feat: Log song title, artist, and album after setting rating
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
33
main.py
33
main.py
@@ -46,6 +46,29 @@ def parse_log_line(line):
|
||||
return timestamp, song_id, is_starred
|
||||
|
||||
|
||||
async def navidrome_get_song_details(song_id):
|
||||
"""
|
||||
Gets song details from Navidrome's inspect API.
|
||||
"""
|
||||
navidrome_url = settings.NAVIDROME_URL
|
||||
if not navidrome_url:
|
||||
logging.error("NAVIDROME_URL must be set in settings.py.")
|
||||
return None
|
||||
|
||||
api_url = f"{navidrome_url.rstrip('/')}/api/inspect"
|
||||
params = {'id': song_id}
|
||||
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(api_url, params=params) as response:
|
||||
response.raise_for_status()
|
||||
data = await response.json()
|
||||
return data
|
||||
except aiohttp.ClientError as e:
|
||||
logging.error(f"Error calling Navidrome inspect API for song {song_id}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
async def navidrome_set_rating(song_id):
|
||||
navidrome_url = settings.NAVIDROME_URL
|
||||
username = settings.NAVIDROME_USER
|
||||
@@ -86,7 +109,15 @@ async def navidrome_set_rating(song_id):
|
||||
response.raise_for_status()
|
||||
data = await response.json()
|
||||
if data.get('subsonic-response', {}).get('status') == 'ok':
|
||||
logging.info(f"Successfully set rating for song {song_id} to 1.")
|
||||
details = await navidrome_get_song_details(song_id)
|
||||
if details:
|
||||
raw_tags = details.get('rawTags', {})
|
||||
title = raw_tags.get('title', ['Unknown Title'])[0]
|
||||
artist = raw_tags.get('artist', ['Unknown Artist'])[0]
|
||||
album = raw_tags.get('album', ['Unknown Album'])[0]
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user