feat: Implement Navidrome setRating API for starred/unstarred songs
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
18
main.py
18
main.py
@@ -9,6 +9,9 @@ import re
|
|||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
import aiodocker
|
import aiodocker
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
import hashlib
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
@@ -71,14 +74,24 @@ async def navidrome_set_rating(song_id):
|
|||||||
's': salt,
|
's': salt,
|
||||||
'v': '1.16.1',
|
'v': '1.16.1',
|
||||||
'c': 'heart-monitor',
|
'c': 'heart-monitor',
|
||||||
'f': 'json'
|
'f': 'json',
|
||||||
'id': song_id,
|
'id': song_id,
|
||||||
'rating': 1,
|
'rating': 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
api_url = f"{navidrome_url.rstrip('/')}/rest/setRating"
|
api_url = f"{navidrome_url.rstrip('/')}/rest/setRating"
|
||||||
|
|
||||||
# TODO: call the subsonic API here
|
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()
|
||||||
|
if data.get('subsonic-response', {}).get('status') == 'ok':
|
||||||
|
logging.info(f"Successfully set rating for song {song_id} to 1.")
|
||||||
|
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():
|
||||||
@@ -113,6 +126,7 @@ async def main():
|
|||||||
logging.info(
|
logging.info(
|
||||||
f"Song {song_id} was starred and then unstarred within {STAR_UNSTAR_WINDOW.seconds} seconds."
|
f"Song {song_id} was starred and then unstarred within {STAR_UNSTAR_WINDOW.seconds} seconds."
|
||||||
)
|
)
|
||||||
|
await navidrome_set_rating(song_id)
|
||||||
# Remove song from tracking after it has been unstarred
|
# Remove song from tracking after it has been unstarred
|
||||||
del starred_songs[song_id]
|
del starred_songs[song_id]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user