Prepare V0.2

This commit is contained in:
unknown
2025-12-18 01:58:17 +01:00
parent 2b66994f41
commit 0be2435290

View File

@@ -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]:
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:
genres = []
genres: List[str] = []
for data in rawartists:
with Loader(PrintChannel.PROGRESS_INFO, "Fetching artist information..."):
(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])
(raw, artistInfo) = Zotify.invoke_url(f"{data[HREF]}")
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)
genres.append('')
return ['']
return genres
except Exception as e:
raise ValueError(f'Failed to parse GENRES response: {str(e)}\n{raw}')
else:
return ['']
raise ValueError(f'Failed to parse GENRES response: {str(e)}')
def get_song_lyrics(song_id: str, file_save: Optional[PurePath], title: Optional[str] = None, artists: Optional[List[str]] = None,