Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: artwork tag option #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ These songs are already mp3-tagged with their track name and track number, but n
+ I set the tracklist in `tracks.txt` (same tracks as before)
+ I execute `python -m album_splitter --file DogsEatingDogsAlbum.mp3 --album "Dogs Eating Gods" --artist "blink-182" --folder "2012 - Dogs Eating Dogs"`
+ The software will execute, it will split the album, and mp3-tag each track with the author and the album name I passed as a parameter (as well as track number and name). It will also put the files in the folder passed as an argument (instead of putting them in the default `./splits` folder)
+ To add an image you have saved locally as album artwork to the tracks, add the option `--artwork "./path/to/artwork.jpeg"`.

## Supported formats for the track list (`tracks.txt`)

Expand Down
6 changes: 6 additions & 0 deletions album_splitter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def get_parser():
help="The year that the ouput will be tagged with. (default: %(default)s)",
default=None,
)
tracks_metadata_group.add_argument(
"--artwork",
help="Path to an image that will be used as the album artwork. (default: %(default)s)",
default=None,
)
tracks_metadata_group.add_argument(
"-md",
"--metadata",
Expand Down Expand Up @@ -143,6 +148,7 @@ def main():
"artist": args.artist,
"album": args.album,
"year": args.year,
"artwork": args.artwork,
}
)
for tag_data_line in args.extra_metadata or []:
Expand Down
10 changes: 10 additions & 0 deletions album_splitter/tag_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ def tag_file(file: Path, tag_data: Dict[str, str]):
raise RuntimeError(
f"Something went wrong when loading file for tagging: {file}"
)

for tag, data in tag_data.items():
if tag in ["artwork"] and isinstance(data, str):
if Path(data).exists():
with open(data, "rb") as img_in:
data = img_in.read()
else:
print(f"Warning: no artwork file found at {data}, skipping.")
continue

if data:
audio[tag] = data

audio.save()