From 6ab6d75b7baced77f7d841a86005c75e0f9c0eb8 Mon Sep 17 00:00:00 2001 From: Karl Date: Wed, 3 Nov 2021 13:37:53 +0000 Subject: [PATCH] initial working commit --- .gitignore | 3 ++ .vscode/launch.json | 29 ++++++++++++++++ SongLocations | 10 ++++++ player.py | 82 +++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 20 +++++++++++ 5 files changed, 144 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 SongLocations create mode 100644 player.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c475372 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv +demo_client.py +test.py diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f59d8fc --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "yt diskLoad", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args":[ + // "Daft Punk RAM - ytmusic:album:MPREb_K8qWMWVqXGi" + " Xtra Reloaded - http://media-ice.musicradio.com/CapitalXTRAReloadedMP3.m3u" + ] + }, + { + "name": "current_track", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args":[ + "current_track" + ] + } + ] +} \ No newline at end of file diff --git a/SongLocations b/SongLocations new file mode 100644 index 0000000..1b5fc3a --- /dev/null +++ b/SongLocations @@ -0,0 +1,10 @@ +Chris Brown Indigo - ytmusic:album:MPREb_jlY9mqAHYjR + +Daft Punk RAM - +ytmusic:album:MPREb_K8qWMWVqXGi + +My Likes - +ytmusic:liked + +Radio +http://media-ice.musicradio.com/CapitalXTRAReloadedMP3.m3u \ No newline at end of file diff --git a/player.py b/player.py new file mode 100644 index 0000000..fac8d21 --- /dev/null +++ b/player.py @@ -0,0 +1,82 @@ +import asyncio +import argparse + +from mopidy_async_client import MopidyClient + +parser = argparse.ArgumentParser(description="Mopdiy FloppyPlayer") +parser.add_argument("URI_string", help="Mopdiy URI to Album/Playlist.") +args = parser.parse_args() +inputURI = args.URI_string + + +async def playback_started_handler(data): + print(data) + + +async def all_events_handler(event, data): + print(event, data) + + +async def main3(): + if inputURI == "stop": + await stop() + elif inputURI == "current_track": + await current_track() + else: + await main1() + + +async def stop(): + mopidy = await MopidyClient().connect() + await mopidy.playback.stop() + await mopidy.disconnect() + + +async def current_track(): + mopidy = await MopidyClient().connect() + res = await mopidy.playback.get_current_track() + current_data = { + "Artist": res["artists"][0]["name"], + "Album": res["album"]["name"], + "Song": res["name"], + } + print(current_data) + await mopidy.disconnect() + + +async def main1(): + link = inputURI.split(" - ")[1] + async with MopidyClient( + url="ws://127.0.0.1:6680/mopidy/ws" + ) as mopidy: # close connection explicit + await mopidy.playback.stop() + await mopidy.tracklist.clear() + await mopidy.tracklist.add(uris=[link]) + await mopidy.playback.play() + + +async def main2(): + mopidy = await MopidyClient().connect() + await mopidy.playback.stop() + await mopidy.tracklist.clear() + await mopidy.tracklist.add(uris=[inputURI]) + await mopidy.playback.play() + mopidy.listener.bind("track_playback_started", playback_started_handler) + mopidy.listener.bind("*", all_events_handler) + + # your app logic + for i in range(10): + # res = await mopidy.tracklist.get_tracks() + res = await mopidy.playback.get_current_track() + print(res) + await asyncio.sleep(5) + + # end your app logic + + await mopidy.disconnect() # close connection implicit + + +# asyncio.run(main1()) +# or +# asyncio.run(main2()) +asyncio.run(main3()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a8a4ac0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,20 @@ +Adafruit-GPIO==1.0.4 +Adafruit-PureIO==1.1.9 +Adafruit-SSD1306==1.6.2 +black==21.10b0 +click==8.0.3 +future==0.18.2 +importlib-metadata==4.8.1 +mopidy-async-client==0.6.4 +mypy-extensions==0.4.3 +pathspec==0.9.0 +pkg-resources==0.0.0 +platformdirs==2.4.0 +regex==2021.10.23 +spidev==3.5 +tomli==1.2.2 +typed-ast==1.4.3 +typing-extensions==3.10.0.2 +websocket-client==1.2.1 +websockets==10.0 +zipp==3.6.0