Skip to content

Commit

Permalink
fixed genre formatting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nathom committed Feb 25, 2021
1 parent 98db34b commit 69728e2
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions qobuz_dl/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ def _format_copyright(s: str) -> str:
return s


def _format_genres(genres: list) -> str:
'''Fixes the weirdly formatted genre lists returned by the API.
>>> g = ['Pop/Rock', 'Pop/Rock→Rock', 'Pop/Rock→Rock→Alternatif et Indé']
>>> _format_genres(g)
'Pop/Rock, Rock, Alternatif et Indé'
'''

if len(genres) <= 1:
return ''.join(genres)

prev = genres[0]
new_genres = [prev]
for genre in genres[1:]:
new_genres.append(genre.replace(f'{prev}→', ''))
prev = genre

return ', '.join(new_genres)


# Use KeyError catching instead of dict.get to avoid empty tags
def tag_flac(filename, root_dir, final_name, d, album,
istrack=True, em_image=False):
Expand Down Expand Up @@ -72,17 +91,17 @@ def tag_flac(filename, root_dir, final_name, d, album,
pass

if istrack:
audio["GENRE"] = ", ".join(d["album"]["genres_list"]) # GENRE
audio["ALBUMARTIST"] = d["album"]["artist"]["name"] # ALBUM ARTIST
audio["TRACKTOTAL"] = str(d["album"]["tracks_count"]) # TRACK TOTAL
audio["ALBUM"] = d["album"]["title"] # ALBUM TITLE
audio["GENRE"] = _format_genres(d["album"]["genres_list"]) # GENRE
audio["ALBUMARTIST"] = d["album"]["artist"]["name"] # ALBUMARTIST
audio["TRACKTOTAL"] = str(d["album"]["tracks_count"]) # TRACK TOTAL
audio["ALBUM"] = d["album"]["title"] # ALBUM TITLE
audio["DATE"] = d["album"]["release_date_original"]
audio["COPYRIGHT"] = _format_copyright(d["copyright"])
else:
audio["GENRE"] = ", ".join(album["genres_list"]) # GENRE
audio["ALBUMARTIST"] = album["artist"]["name"] # ALBUM ARTIST
audio["TRACKTOTAL"] = str(album["tracks_count"]) # TRACK TOTAL
audio["ALBUM"] = album["title"] # ALBUM TITLE
audio["GENRE"] = _format_genres(album["genres_list"]) # GENRE
audio["ALBUMARTIST"] = album["artist"]["name"] # ALBUM ARTIST
audio["TRACKTOTAL"] = str(album["tracks_count"]) # TRACK TOTAL
audio["ALBUM"] = album["title"] # ALBUM TITLE
audio["DATE"] = album["release_date_original"]
audio["COPYRIGHT"] = _format_copyright(album["copyright"])

Expand Down Expand Up @@ -161,14 +180,14 @@ def tag_mp3(filename, root_dir, final_name, d, album,
tags['artist'] = album["artist"]["name"]

if istrack:
tags["genre"] = ", ".join(d["album"]["genres_list"])
tags["genre"] = _format_genres(d["album"]["genres_list"])
tags["albumartist"] = d["album"]["artist"]["name"]
tags["album"] = d["album"]["title"]
tags["date"] = d["album"]["release_date_original"]
tags["copyright"] = _format_copyright(d["copyright"])
tracktotal = str(d["album"]["tracks_count"])
else:
tags["genre"] = ", ".join(album["genres_list"])
tags["genre"] = _format_genres(album["genres_list"])
tags["albumartist"] = album["artist"]["name"]
tags["album"] = album["title"]
tags["date"] = album["release_date_original"]
Expand Down

0 comments on commit 69728e2

Please sign in to comment.