From bdb81a53f5f974bd539c0f820f6fc82785e31cb8 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Tue, 6 Oct 2026 09:39:45 +1300 Subject: music --- backend.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'backend.py') diff --git a/backend.py b/backend.py index e868252..c8d4025 100644 --- a/backend.py +++ b/backend.py @@ -38,5 +38,47 @@ def print_queue(): finally: print_lock.release() +@app.get("/automate/music") +def music(): + NAVIDROME_URL = os.environ.get("NAVIDROME_URL", "127.0.0.1") + USERNAME = os.environ.get("NAVIDROME_USER", "user") + PASSWORD = os.environ.get("NAVIDROME_PASSWORD", "password123") + PLAYLIST_ID = os.environ.get("NAVIDROME_PLAYLIST_ID", "6767baldniko67") + + params = { + "u": USERNAME, + "p": PASSWORD, + "s": "remote-automation", + "v": "1.16.1", + "c": "remote-automation", + "f": "json", + "id": PLAYLIST_ID, + } + + response = requests.get(f"{NAVIDROME_URL}/rest/getPlaylist.view") + response.raise_for_status() + + songs = response.json()["subsonic-response"]["playlist"]["entry"] + song = random.choice(songs) + + stream_params = { + "u": USERNAME, + "p": PASSWORD, + "s": "remote-automation", + "v": "1.16.1", + "c": "remote-automation", + "id": song["id"], + } + + subprocess.Popen([ + "mpv", + "--no-video", + "--audio-device=pipewire", + "--", + requests.Request("GET", stream_url, params=stream_params).prepare().url, + ]) + + print(f"Playing: {song['title']} - {song.get('artist', 'Unknown Artist')}") + if __name__ == "__main__": app.run(host="0.0.0.0", port=6732) -- cgit v1.2.3