refactor: Flatten navidrome_set_rating function
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
20
main.py
20
main.py
@@ -108,20 +108,24 @@ async def navidrome_set_rating(song_id):
|
|||||||
async with session.get(api_url, params=params) as response:
|
async with session.get(api_url, params=params) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
if data.get('subsonic-response', {}).get('status') == 'ok':
|
except aiohttp.ClientError as e:
|
||||||
|
logging.error(f"Error calling Navidrome API for song {song_id}: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
if data.get('subsonic-response', {}).get('status') != 'ok':
|
||||||
|
logging.error(f"Failed to set rating for song {song_id}. Response: {data}")
|
||||||
|
return
|
||||||
|
|
||||||
details = await navidrome_get_song_details(song_id)
|
details = await navidrome_get_song_details(song_id)
|
||||||
if details:
|
if not details:
|
||||||
|
logging.info(f"Successfully set rating for song {song_id} to 1, but couldn't get song details.")
|
||||||
|
return
|
||||||
|
|
||||||
raw_tags = details.get('rawTags', {})
|
raw_tags = details.get('rawTags', {})
|
||||||
title = raw_tags.get('title', ['Unknown Title'])[0]
|
title = raw_tags.get('title', ['Unknown Title'])[0]
|
||||||
artist = raw_tags.get('artist', ['Unknown Artist'])[0]
|
artist = raw_tags.get('artist', ['Unknown Artist'])[0]
|
||||||
album = raw_tags.get('album', ['Unknown Album'])[0]
|
album = raw_tags.get('album', ['Unknown Album'])[0]
|
||||||
logging.info(f'Set song "{title}" - {artist} ({album}) rating to 1.')
|
logging.info(f'Set song "{title}" - {artist} ({album}) rating to 1.')
|
||||||
else:
|
|
||||||
logging.info(f"Successfully set rating for song {song_id} to 1, but couldn't get song details.")
|
|
||||||
else:
|
|
||||||
logging.error(f"Failed to set rating for song {song_id}. Response: {data}")
|
|
||||||
except aiohttp.ClientError as e:
|
|
||||||
logging.error(f"Error calling Navidrome API for song {song_id}: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user