Metadata-Version: 2.5
Name: mp3-cover-adder
Version: 0.1.0
Summary: Python library to embed MP3 album art and edit ID3 tags
Project-URL: Homepage, https://github.com/sherotree/mp3-cover-adder-py
Project-URL: Repository, https://github.com/sherotree/mp3-cover-adder-py
Project-URL: Web Tool, https://www.uwarp.design/mp3-cover-adder
Author-email: Sherotree <sherotree@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Keywords: album-art,audio,cover-art,id3,metadata,mp3
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Sound/Audio
Requires-Python: >=3.8
Requires-Dist: mutagen>=1.45.0
Provides-Extra: dev
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Description-Content-Type: text/markdown

# mp3-cover-adder

[**Add Cover to MP3**](https://www.uwarp.design/mp3-cover-adder) — free browser tool for embedding album art and editing ID3 tags (the reference UI for this library).

Offline Python library for embedding album art and editing ID3 metadata in MP3 files.

Package: **`mp3-cover-adder`** on PyPI (`0.1.0`).

## Install

```bash
pip install mp3-cover-adder
```

## Quick start

```python
from mp3_cover_adder import MP3CoverAdder

# Read and modify an MP3 file
mp3 = MP3CoverAdder("song.mp3")
mp3.set_cover("cover.jpg")
mp3.set_metadata(title="My Song", artist="Artist Name", album="Album Title")
mp3.write("output.mp3")

# Or work with bytes in memory
result_bytes = mp3.to_bytes()
```

## API

### Class API

| Method | Description |
| --- | --- |
| `MP3CoverAdder(file_path)` | Load MP3 from path, bytes, or BytesIO |
| `.get_metadata()` | Returns `dict` with title, artist, album |
| `.get_cover()` | Returns cover image as `bytes` or `None` |
| `.set_cover(image, mime_type=None)` | Set/replace cover from path or bytes (JPEG/PNG) |
| `.remove_cover()` | Remove all album art |
| `.set_metadata(title=None, artist=None, album=None)` | Update ID3 text fields |
| `.write(output_path=None)` | Save to file (or modify in-place if path is `None`) |
| `.to_bytes()` | Get modified MP3 as bytes without writing |

### Convenience functions

| Function | Role |
| --- | --- |
| `read_mp3_metadata(file)` | Read metadata + check for cover art |
| `set_mp3_cover(input, image, output=None)` | Add cover (returns bytes if `output` is `None`) |
| `remove_mp3_cover(input, output=None)` | Remove cover (returns bytes if `output` is `None`) |
| `set_mp3_metadata(input, output=None, ...)` | Update metadata (returns bytes if `output` is `None`) |
| `write_mp3(input, output, image=None, ...)` | One-shot: write MP3 with optional cover + metadata |

## Examples

### Read metadata and cover

```python
from mp3_cover_adder import read_mp3_metadata, MP3CoverAdder

# Quick check
info = read_mp3_metadata("song.mp3")
print(info)  # {'title': '...', 'artist': '...', 'album': '...', 'has_cover': True}

# Extract cover
mp3 = MP3CoverAdder("song.mp3")
cover_bytes = mp3.get_cover()
if cover_bytes:
    with open("extracted_cover.jpg", "wb") as f:
        f.write(cover_bytes)
```

### Add or replace cover art

```python
from mp3_cover_adder import set_mp3_cover

# From file path (MIME type auto-detected from extension)
set_mp3_cover("input.mp3", "cover.jpg", output_path="output.mp3")

# From bytes in memory (MIME type auto-detected from magic bytes)
with open("cover.png", "rb") as f:
    cover_data = f.read()

result = set_mp3_cover("input.mp3", cover_data)  # returns bytes
with open("output.mp3", "wb") as f:
    f.write(result)
```

### Update metadata only

```python
from mp3_cover_adder import MP3CoverAdder

mp3 = MP3CoverAdder("song.mp3")
mp3.set_metadata(
    title="Updated Title",
    artist="New Artist",
    album="New Album"
)
mp3.write()  # modify in-place
```

### Remove album art

```python
from mp3_cover_adder import remove_mp3_cover

remove_mp3_cover("input.mp3", output_path="output_no_cover.mp3")
```

### All-in-one convenience

```python
from mp3_cover_adder import write_mp3

write_mp3(
    input_path="input.mp3",
    output_path="output.mp3",
    image_source="cover.jpg",
    title="Song Title",
    artist="Artist Name",
    album="Album Name"
)
```

## Tests

```bash
pytest
# or with coverage
pytest --cov=mp3_cover_adder
```

## Development

```bash
# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/ tests/

# Lint
ruff check src/ tests/
```

## License

MIT. See [LICENSE](./LICENSE).
