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 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: mopidy = await MopidyClient().connect() if await mopidy.playback.get_state() == "playing": return else: await run_floppy(action) async def run_floppy(input): link = input.split(" - ")[1] mopidy = await MopidyClient().connect() await mopidy.playback.stop() await mopidy.tracklist.clear() await mopidy.tracklist.add(uris=[link]) await mopidy.playback.play() await mopidy.disconnect() asyncio.run(selector(inputURI))