mirror of
https://github.com/Wojtek242/qobuz-dl.git
synced 2024-11-22 11:05:25 +01:00
fixed genre formatting issue
This commit is contained in:
parent
98db34bc8e
commit
69728e21ee
@ -30,6 +30,25 @@ def _format_copyright(s: str) -> str:
|
|||||||
return s
|
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
|
# Use KeyError catching instead of dict.get to avoid empty tags
|
||||||
def tag_flac(filename, root_dir, final_name, d, album,
|
def tag_flac(filename, root_dir, final_name, d, album,
|
||||||
istrack=True, em_image=False):
|
istrack=True, em_image=False):
|
||||||
@ -72,17 +91,17 @@ def tag_flac(filename, root_dir, final_name, d, album,
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if istrack:
|
if istrack:
|
||||||
audio["GENRE"] = ", ".join(d["album"]["genres_list"]) # GENRE
|
audio["GENRE"] = _format_genres(d["album"]["genres_list"]) # GENRE
|
||||||
audio["ALBUMARTIST"] = d["album"]["artist"]["name"] # ALBUM ARTIST
|
audio["ALBUMARTIST"] = d["album"]["artist"]["name"] # ALBUMARTIST
|
||||||
audio["TRACKTOTAL"] = str(d["album"]["tracks_count"]) # TRACK TOTAL
|
audio["TRACKTOTAL"] = str(d["album"]["tracks_count"]) # TRACK TOTAL
|
||||||
audio["ALBUM"] = d["album"]["title"] # ALBUM TITLE
|
audio["ALBUM"] = d["album"]["title"] # ALBUM TITLE
|
||||||
audio["DATE"] = d["album"]["release_date_original"]
|
audio["DATE"] = d["album"]["release_date_original"]
|
||||||
audio["COPYRIGHT"] = _format_copyright(d["copyright"])
|
audio["COPYRIGHT"] = _format_copyright(d["copyright"])
|
||||||
else:
|
else:
|
||||||
audio["GENRE"] = ", ".join(album["genres_list"]) # GENRE
|
audio["GENRE"] = _format_genres(album["genres_list"]) # GENRE
|
||||||
audio["ALBUMARTIST"] = album["artist"]["name"] # ALBUM ARTIST
|
audio["ALBUMARTIST"] = album["artist"]["name"] # ALBUM ARTIST
|
||||||
audio["TRACKTOTAL"] = str(album["tracks_count"]) # TRACK TOTAL
|
audio["TRACKTOTAL"] = str(album["tracks_count"]) # TRACK TOTAL
|
||||||
audio["ALBUM"] = album["title"] # ALBUM TITLE
|
audio["ALBUM"] = album["title"] # ALBUM TITLE
|
||||||
audio["DATE"] = album["release_date_original"]
|
audio["DATE"] = album["release_date_original"]
|
||||||
audio["COPYRIGHT"] = _format_copyright(album["copyright"])
|
audio["COPYRIGHT"] = _format_copyright(album["copyright"])
|
||||||
|
|
||||||
@ -161,14 +180,14 @@ def tag_mp3(filename, root_dir, final_name, d, album,
|
|||||||
tags['artist'] = album["artist"]["name"]
|
tags['artist'] = album["artist"]["name"]
|
||||||
|
|
||||||
if istrack:
|
if istrack:
|
||||||
tags["genre"] = ", ".join(d["album"]["genres_list"])
|
tags["genre"] = _format_genres(d["album"]["genres_list"])
|
||||||
tags["albumartist"] = d["album"]["artist"]["name"]
|
tags["albumartist"] = d["album"]["artist"]["name"]
|
||||||
tags["album"] = d["album"]["title"]
|
tags["album"] = d["album"]["title"]
|
||||||
tags["date"] = d["album"]["release_date_original"]
|
tags["date"] = d["album"]["release_date_original"]
|
||||||
tags["copyright"] = _format_copyright(d["copyright"])
|
tags["copyright"] = _format_copyright(d["copyright"])
|
||||||
tracktotal = str(d["album"]["tracks_count"])
|
tracktotal = str(d["album"]["tracks_count"])
|
||||||
else:
|
else:
|
||||||
tags["genre"] = ", ".join(album["genres_list"])
|
tags["genre"] = _format_genres(album["genres_list"])
|
||||||
tags["albumartist"] = album["artist"]["name"]
|
tags["albumartist"] = album["artist"]["name"]
|
||||||
tags["album"] = album["title"]
|
tags["album"] = album["title"]
|
||||||
tags["date"] = album["release_date_original"]
|
tags["date"] = album["release_date_original"]
|
||||||
|
Loading…
Reference in New Issue
Block a user