Skip to content

Commit

Permalink
Merge pull request #246 from tko81/genres
Browse files Browse the repository at this point in the history
add cmd argument --embed-genres to fetch genres
  • Loading branch information
Evolution0 authored Dec 24, 2024
2 parents 7154b52 + c0a2bc2 commit 716cfd0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions bandcamp_dl/__main__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main():
action='store_true', default=conf.embed_lyrics)
parser.add_argument('-g', '--group', help='Use album/track Label as iTunes grouping',
action='store_true', default=conf.group)
parser.add_argument('-r', '--embed-art', help='Use album/track Label as iTunes grouping',
parser.add_argument('-r', '--embed-art', help='Embed album art (If available)',
action='store_true', default=conf.embed_art)
parser.add_argument('-y', '--no-slugify', action='store_true', default=conf.no_slugify,
help='Disable slugification of track, album, and artist names')
Expand All @@ -72,6 +72,8 @@ def main():
action='store_true', default=conf.keep_upper)
parser.add_argument('--no-confirm', help='Override confirmation prompts. Use with caution',
action='store_true', default=conf.no_confirm)
parser.add_argument('--embed-genres', help='Embed album/track genres',
action='store_true', default=conf.embed_genres)

arguments = parser.parse_args()
if arguments.version:
Expand Down Expand Up @@ -114,7 +116,7 @@ def main():
if "/album/" not in url and "/track/" not in url:
continue
logger.debug("\n\tURL: %s", url)
album_list.append(bandcamp.parse(url, not arguments.no_art, arguments.embed_lyrics,
album_list.append(bandcamp.parse(url, not arguments.no_art, arguments.embed_lyrics, arguments.embed_genres,
arguments.debug))

for album in album_list:
Expand Down
9 changes: 7 additions & 2 deletions bandcamp_dl/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ def __init__(self):
self.adapter = SSLAdapter(ssl_context=ctx)
self.session.mount('https://', self.adapter)

def parse(self, url: str, art: bool = True, lyrics: bool = False,
def parse(self, url: str, art: bool = True, lyrics: bool = False, genres: bool = False,
debugging: bool = False) -> dict or None:
"""Requests the page, cherry-picks album info
:param url: album/track url
:param art: if True download album art
:param lyrics: if True fetch track lyrics
:param genres: if True fetch track tags
:param debugging: if True then verbose output
:return: album metadata
"""
Expand Down Expand Up @@ -123,7 +124,8 @@ def parse(self, url: str, art: bool = True, lyrics: bool = False,
"full": False,
"art": "",
"date": str(datetime.datetime.strptime(album_release, "%d %b %Y %H:%M:%S GMT").year),
"url": url
"url": url,
"genres": ""
}

if "track" in page_json['url']:
Expand All @@ -135,13 +137,16 @@ def parse(self, url: str, art: bool = True, lyrics: bool = False,
if lyrics:
track['lyrics'] = self.get_track_lyrics(f"{artist_url}"
f"{track['title_link']}#lyrics")

if track['file'] is not None:
track = self.get_track_metadata(track)
album['tracks'].append(track)

album['full'] = self.all_tracks_available()
if art:
album['art'] = self.get_album_art()
if genres:
album['genres'] = ','.join(page_json['keywords'])

self.logger.debug(" Album generated..")
self.logger.debug(" Album URL: %s", album['url'])
Expand Down
6 changes: 4 additions & 2 deletions bandcamp_dl/bandcampdownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def download_album(self, album: dict) -> bool:
"track": track['track'],
# TODO: Find out why the 'lyrics' key seems to vanish.
"lyrics": track.get('lyrics', ""),
"date": album['date']}
"date": album['date'],
"genres": album['genres'],}

self.num_tracks = len(album['tracks'])
self.track_num = track_index + 1
Expand Down Expand Up @@ -261,6 +262,8 @@ def write_id3_tags(self, filepath: str, meta: dict):
cover_bytes = cover_img.read()
audio["APIC"] = id3._frames.APIC(encoding=3, mime='image/jpeg', type=3,
desc='Cover', data=cover_bytes)
if self.config.embed_genres:
audio["TCON"] = id3._frames.TCON(encoding=3, text=meta['genres'])
audio.save()

audio = mp3.EasyMP3(filepath)
Expand All @@ -274,7 +277,6 @@ def write_id3_tags(self, filepath: str, meta: dict):
audio["artist"] = meta['artist']
else:
audio["artist"] = meta['albumartist']

audio["title"] = meta["title"]
audio["albumartist"] = meta['albumartist']
audio["album"] = meta['album']
Expand Down
3 changes: 2 additions & 1 deletion bandcamp_dl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Config(dict):
"keep_spaces": False,
"keep_upper": False,
"no_confirm": False,
"debug": False}
"debug": False,
"embed_genres": False}

def __init__(self, dict_=None):
if dict_ is None:
Expand Down

0 comments on commit 716cfd0

Please sign in to comment.