|
@@ -9,30 +9,42 @@ args = parser.parse_args()
|
|
|
inputURI = args.URI_string
|
|
|
|
|
|
|
|
|
-async def selector():
|
|
|
- if "ytmusic" in inputURI or "http://" in inputURI:
|
|
|
- await run_floppy(inputURI)
|
|
|
+async def selector(action):
|
|
|
+ last_disk_read = open("/home/pi/pythonDiskPlayer/last_disk.txt", "r+").read()
|
|
|
+ if action is not "" and last_disk_read != action:
|
|
|
+ mopidy = await MopidyClient().connect()
|
|
|
+ if action == "stop":
|
|
|
+ await mopidy.playback.stop()
|
|
|
+ await mopidy.tracklist.clear()
|
|
|
+ elif action == "next":
|
|
|
+ await mopidy.playback.next()
|
|
|
+ elif action == "previous":
|
|
|
+ await mopidy.playback.previous()
|
|
|
+ elif action == "shuffle":
|
|
|
+ await mopidy.tracklist.shuffle()
|
|
|
+ await mopidy.tracklist.move(
|
|
|
+ start=await mopidy.tracklist.index(),
|
|
|
+ end=await mopidy.tracklist.index(),
|
|
|
+ to_position=0,
|
|
|
+ )
|
|
|
+ elif action == "playpause":
|
|
|
+ if await mopidy.playback.get_state() == "playing":
|
|
|
+ await mopidy.playback.pause()
|
|
|
+ else:
|
|
|
+ await mopidy.playback.resume()
|
|
|
+ elif action == "":
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ last_disk = open("/home/pi/pythonDiskPlayer/last_disk.txt", "w")
|
|
|
+ last_disk.write(action)
|
|
|
+ await run_floppy(action)
|
|
|
+ await mopidy.disconnect()
|
|
|
else:
|
|
|
- await action(inputURI)
|
|
|
-
|
|
|
-
|
|
|
-async def action(action):
|
|
|
- mopidy = await MopidyClient().connect()
|
|
|
- if action == "stop":
|
|
|
- await mopidy.playback.stop()
|
|
|
- elif action == "next":
|
|
|
- await mopidy.playback.next()
|
|
|
- elif action == "previous":
|
|
|
- await mopidy.playback.previous()
|
|
|
- elif action == "play":
|
|
|
- await mopidy.playback.play()
|
|
|
- elif action == "pause":
|
|
|
- await mopidy.playback.pause()
|
|
|
- elif action == "resume":
|
|
|
- await mopidy.playback.resume()
|
|
|
- elif action == "shuffle":
|
|
|
- await mopidy.tracklist.shuffle()
|
|
|
- await mopidy.disconnect()
|
|
|
+ mopidy = await MopidyClient().connect()
|
|
|
+ if await mopidy.playback.get_state() == "playing":
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ await run_floppy(action)
|
|
|
|
|
|
|
|
|
async def run_floppy(input):
|
|
@@ -45,4 +57,4 @@ async def run_floppy(input):
|
|
|
await mopidy.disconnect()
|
|
|
|
|
|
|
|
|
-asyncio.run(selector())
|
|
|
+asyncio.run(selector(inputURI))
|