Prepare V0.2
This commit is contained in:
@@ -138,27 +138,39 @@ def get_song_info(song_id) -> Tuple[List[str], List[Any], str, str, Any, Any, An
|
|||||||
|
|
||||||
|
|
||||||
def get_song_genres(rawartists: List[str], track_name: str) -> List[str]:
|
def get_song_genres(rawartists: List[str], track_name: str) -> List[str]:
|
||||||
if Zotify.CONFIG.get_save_genres():
|
"""Fetch genres for the track from Spotify's artist metadata.
|
||||||
|
|
||||||
|
For each contributing artist, query the artist's Spotify API endpoint
|
||||||
|
(via its ``href``) and collect the ``genres`` field. These genres are
|
||||||
|
then passed to ``set_audio_tags`` so they end up in the audio file's
|
||||||
|
metadata.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
genres = []
|
genres: List[str] = []
|
||||||
for data in rawartists:
|
for data in rawartists:
|
||||||
with Loader(PrintChannel.PROGRESS_INFO, "Fetching artist information..."):
|
with Loader(PrintChannel.PROGRESS_INFO, "Fetching artist information..."):
|
||||||
(raw, artistInfo) = Zotify.invoke_url(f'{data[HREF]}')
|
(raw, artistInfo) = Zotify.invoke_url(f"{data[HREF]}")
|
||||||
if Zotify.CONFIG.get_all_genres() and len(artistInfo[GENRES]) > 0:
|
|
||||||
for genre in artistInfo[GENRES]:
|
|
||||||
genres.append(genre)
|
|
||||||
elif len(artistInfo[GENRES]) > 0:
|
|
||||||
genres.append(artistInfo[GENRES][0])
|
|
||||||
|
|
||||||
if len(genres) == 0:
|
artist_genres = artistInfo.get(GENRES, [])
|
||||||
|
if not isinstance(artist_genres, list):
|
||||||
|
artist_genres = []
|
||||||
|
|
||||||
|
if Zotify.CONFIG.get_all_genres():
|
||||||
|
genres.extend(artist_genres)
|
||||||
|
elif artist_genres:
|
||||||
|
genres.append(artist_genres[0])
|
||||||
|
|
||||||
|
# De-duplicate while preserving order
|
||||||
|
seen = set()
|
||||||
|
genres = [g for g in genres if not (g in seen or seen.add(g))]
|
||||||
|
|
||||||
|
if not genres:
|
||||||
Printer.print(PrintChannel.WARNINGS, 'No Genres found for song ' + track_name)
|
Printer.print(PrintChannel.WARNINGS, 'No Genres found for song ' + track_name)
|
||||||
genres.append('')
|
return ['']
|
||||||
|
|
||||||
return genres
|
return genres
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f'Failed to parse GENRES response: {str(e)}\n{raw}')
|
raise ValueError(f'Failed to parse GENRES response: {str(e)}')
|
||||||
else:
|
|
||||||
return ['']
|
|
||||||
|
|
||||||
|
|
||||||
def get_song_lyrics(song_id: str, file_save: Optional[PurePath], title: Optional[str] = None, artists: Optional[List[str]] = None,
|
def get_song_lyrics(song_id: str, file_save: Optional[PurePath], title: Optional[str] = None, artists: Optional[List[str]] = None,
|
||||||
|
|||||||
Reference in New Issue
Block a user