player.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import asyncio
  2. import argparse
  3. from mopidy_async_client import MopidyClient
  4. parser = argparse.ArgumentParser(description="Mopdiy FloppyPlayer")
  5. parser.add_argument("URI_string", help="Mopdiy URI to Album/Playlist.")
  6. args = parser.parse_args()
  7. inputURI = args.URI_string
  8. async def selector(action):
  9. last_disk_read = open("/home/pi/pythonDiskPlayer/last_disk.txt", "r+").read()
  10. if action is not "" and last_disk_read != action:
  11. mopidy = await MopidyClient().connect()
  12. if action == "stop":
  13. await mopidy.playback.stop()
  14. await mopidy.tracklist.clear()
  15. elif action == "next":
  16. await mopidy.playback.next()
  17. elif action == "previous":
  18. await mopidy.playback.previous()
  19. elif action == "shuffle":
  20. await mopidy.tracklist.shuffle()
  21. await mopidy.tracklist.move(
  22. start=await mopidy.tracklist.index(),
  23. end=await mopidy.tracklist.index(),
  24. to_position=0,
  25. )
  26. elif action == "playpause":
  27. if await mopidy.playback.get_state() == "playing":
  28. await mopidy.playback.pause()
  29. else:
  30. await mopidy.playback.resume()
  31. elif action == "":
  32. return
  33. else:
  34. last_disk = open("/home/pi/pythonDiskPlayer/last_disk.txt", "w")
  35. last_disk.write(action)
  36. await run_floppy(action)
  37. await mopidy.disconnect()
  38. else:
  39. mopidy = await MopidyClient().connect()
  40. if await mopidy.playback.get_state() == "playing":
  41. return
  42. else:
  43. await run_floppy(action)
  44. async def run_floppy(input):
  45. link = input.split(" - ")[1]
  46. mopidy = await MopidyClient().connect()
  47. await mopidy.playback.stop()
  48. await mopidy.tracklist.clear()
  49. await mopidy.tracklist.add(uris=[link])
  50. await mopidy.playback.play()
  51. await mopidy.disconnect()
  52. asyncio.run(selector(inputURI))