diff options
| author | Arslaan Pathan <[email protected]> | 2026-10-06 09:39:45 +1300 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-10-06 09:39:45 +1300 |
| commit | bdb81a53f5f974bd539c0f820f6fc82785e31cb8 (patch) | |
| tree | db51e0d8ecb03a0fb42503b0c9955b8cfc544de8 | |
| parent | 71de959fcfcea4f84a0b85daefab2085dc2dbc69 (diff) | |
| download | remote-automation-bdb81a53f5f974bd539c0f820f6fc82785e31cb8.tar.xz remote-automation-bdb81a53f5f974bd539c0f820f6fc82785e31cb8.zip | |
music
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | backend.py | 42 | ||||
| -rw-r--r-- | requirements.txt | 2 |
3 files changed, 45 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env @@ -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) diff --git a/requirements.txt b/requirements.txt index e3e9a71..8dbf8bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ Flask +python-dotenv +requests |
