diff options
| -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 |
