Skip to content

Commit

Permalink
Merge pull request #212 from jedomed/master
Browse files Browse the repository at this point in the history
Minor fixes and added "Album artist" tag
  • Loading branch information
Evolution0 authored Aug 10, 2023
2 parents 6b5e23a + 898fa60 commit f7327d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ output file names and directories. Templates can be built using special
tokens with the format of ``%{artist}``. Here is a list of allowed
tokens:

- ``artist``: The artist name.
- ``trackartist``: The artist name.
- ``artist``: The album artist name.
- ``album``: The album name.
- ``track``: The track number.
- ``title``: The track title.
Expand Down
8 changes: 4 additions & 4 deletions bandcamp_dl/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_track_lyrics(self, track_url):
return track_lyrics.text
else:
logging.debug(" Lyrics not found..")
return "lyrics unavailable"
return ""

def all_tracks_available(self) -> bool:
"""Verify that all tracks have a url
Expand All @@ -133,6 +133,7 @@ def get_track_metadata(track: dict or None) -> dict:
"duration": track['duration'],
"track": str(track['track_num']),
"title": track['title'],
"artist": track['artist'],
"url": None
}

Expand All @@ -145,9 +146,8 @@ def get_track_metadata(track: dict or None) -> dict:
track_metadata['url'] = None

if track['has_lyrics'] is not False:
if track['lyrics'] is None:
track['lyrics'] = "lyrics unavailable"
track_metadata['lyrics'] = track['lyrics'].replace('\\r\\n', '\n')
if track['lyrics'] is not None:
track_metadata['lyrics'] = track['lyrics'].replace('\\r\\n', '\n')

logging.debug(" Track metadata generated..")
return track_metadata
Expand Down
34 changes: 25 additions & 9 deletions bandcamp_dl/bandcampdownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ def slugify_preset(content):
return slugged

if self.config['--no-slugify']:
path = path.replace("%{artist}", track['artist'])
path = path.replace("%{trackartist}", track['artist'])
path = path.replace("%{artist}", track['albumartist'])
path = path.replace("%{album}", track['album'])
path = path.replace("%{title}", track['title'])
path = path.replace("%{date}", track['date'])
path = path.replace("%{label}", track['label'])
else:
path = path.replace("%{artist}", slugify_preset(track['artist']))
path = path.replace("%{trackartist}", slugify_preset(track['artist']))
path = path.replace("%{artist}", slugify_preset(track['albumartist']))
path = path.replace("%{album}", slugify_preset(track['album']))
path = path.replace("%{title}", slugify_preset(track['title']))
path = path.replace("%{date}", slugify_preset(track['date']))
Expand All @@ -91,7 +93,10 @@ def slugify_preset(content):
else:
path = path.replace("%{track}", str(track['track']).zfill(2))

path = f"{self.config['--base-dir']}/{path}.mp3"
if self.config['--base-dir'] is not None:
path = f"{self.config['--base-dir']}/{path}.mp3"
else:
path = f"{path}.mp3"

logging.debug(" filepath/trackname generated..")
logging.debug(f"\n\tPath: {path}")
Expand Down Expand Up @@ -120,13 +125,14 @@ def download_album(self, album: dict) -> bool:
"""
for track_index, track in enumerate(album['tracks']):
track_meta = {
"artist": album['artist'],
"artist": track['artist'],
"albumartist": album['artist'],
"label": album['label'],
"album": album['title'],
"title": track['title'],
"title": track['title'].replace(f"{track['artist']} - ", "", 1),
"track": track['track'],
# TODO: Find out why the 'lyrics' key seems to vanish.
"lyrics": track.get('lyrics', "lyrics unavailable"),
"lyrics": track.get('lyrics', ""),
"date": album['date']
}

Expand Down Expand Up @@ -247,10 +253,20 @@ def write_id3_tags(self, filepath: str, meta: dict):
audio["APIC"] = APIC(encoding=3, mime='image/jpeg', type=3, desc='Cover', data=cover_bytes)
audio.save()

audio = EasyMP3(filepath)
audio["tracknumber"] = meta['track']
audio = EasyMP3(filepath)

if meta['track'].isdigit():
audio["tracknumber"] = meta['track']
else:
audio["tracknumber"] = '1'

if meta['artist'] is not None:
audio["artist"] = meta['artist']
else:
audio["artist"] = meta['albumartist']

audio["title"] = meta["title"]
audio["artist"] = meta['artist']
audio["albumartist"] = meta['albumartist']
audio["album"] = meta['album']
audio["date"] = meta["date"]
audio.save()
Expand Down
1 change: 1 addition & 0 deletions bandcamp_dl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ def init_config(arguments) -> json or dict:
f.write("".join(str(arguments).split('\n')))

config = {key: arguments.get(key, config[key]) for key in config}

return config

0 comments on commit f7327d1

Please sign in to comment.