aboutsummaryrefslogtreecommitdiff
path: root/backend.py
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-10-06 09:39:45 +1300
committerArslaan Pathan <[email protected]>2026-10-06 09:39:45 +1300
commitbdb81a53f5f974bd539c0f820f6fc82785e31cb8 (patch)
treedb51e0d8ecb03a0fb42503b0c9955b8cfc544de8 /backend.py
parent71de959fcfcea4f84a0b85daefab2085dc2dbc69 (diff)
downloadremote-automation-bdb81a53f5f974bd539c0f820f6fc82785e31cb8.tar.xz
remote-automation-bdb81a53f5f974bd539c0f820f6fc82785e31cb8.zip
music
Diffstat (limited to 'backend.py')
-rw-r--r--backend.py42
1 files changed, 42 insertions, 0 deletions
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()
[email protected]("/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)