feat: Implement navidrome_set_rating function for Subsonic API
This commit is contained in:
41
main.py
41
main.py
@@ -7,8 +7,10 @@ logging.basicConfig(
|
||||
import asyncio
|
||||
import re
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import aiodocker
|
||||
import aiohttp
|
||||
|
||||
import settings
|
||||
|
||||
NAVIDROME_CONTAINER = os.environ.get('NAVIDROME_CONTAINER', 'navidrome-navidrome-1')
|
||||
STAR_UNSTAR_WINDOW = timedelta(seconds=4)
|
||||
@@ -42,6 +44,43 @@ def parse_log_line(line):
|
||||
return timestamp, song_id, is_starred
|
||||
|
||||
|
||||
async def navidrome_set_rating(song_id):
|
||||
navidrome_url = settings.NAVIDROME_URL
|
||||
username = settings.NAVIDROME_USER
|
||||
|
||||
if not all([navidrome_url, username]):
|
||||
logging.error("NAVIDROME_URL and NAVIDROME_USER must be set in settings.py.")
|
||||
return
|
||||
|
||||
salt = settings.SUBSONIC_SALT
|
||||
token = settings.SUBSONIC_TOKEN
|
||||
|
||||
if not all([salt, token]):
|
||||
password = settings.NAVIDROME_PASSWORD
|
||||
if not password:
|
||||
logging.error("Either (SUBSONIC_SALT and SUBSONIC_TOKEN) or NAVIDROME_PASSWORD must be set in settings.py.")
|
||||
return
|
||||
|
||||
# Subsonic API requires a salt and a token (md5(password + salt))
|
||||
salt = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10))
|
||||
token = hashlib.md5((password + salt).encode('utf-8')).hexdigest()
|
||||
|
||||
params = {
|
||||
'u': username,
|
||||
't': token,
|
||||
's': salt,
|
||||
'v': '1.16.1',
|
||||
'c': 'heart-monitor',
|
||||
'f': 'json'
|
||||
'id': song_id,
|
||||
'rating': 1,
|
||||
}
|
||||
|
||||
api_url = f"{navidrome_url.rstrip('/')}/rest/setRating"
|
||||
|
||||
# TODO: call the subsonic API here
|
||||
|
||||
|
||||
async def main():
|
||||
"""
|
||||
Monitors Navidrome container logs for rapid star/unstar events.
|
||||
|
||||
Reference in New Issue
Block a user