player.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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():
  9. if "ytmusic" in inputURI or "http://" in inputURI:
  10. await run_floppy(inputURI)
  11. else:
  12. await action(inputURI)
  13. async def action(action):
  14. mopidy = await MopidyClient().connect()
  15. if action == "stop":
  16. await mopidy.playback.stop()
  17. elif action == "next":
  18. await mopidy.playback.next()
  19. elif action == "previous":
  20. await mopidy.playback.previous()
  21. elif action == "play":
  22. await mopidy.playback.play()
  23. elif action == "pause":
  24. await mopidy.playback.pause()
  25. elif action == "resume":
  26. await mopidy.playback.resume()
  27. elif action == "shuffle":
  28. await mopidy.tracklist.shuffle()
  29. await mopidy.disconnect()
  30. async def run_floppy(input):
  31. link = input.split(" - ")[1]
  32. mopidy = await MopidyClient().connect()
  33. await mopidy.playback.stop()
  34. await mopidy.tracklist.clear()
  35. await mopidy.tracklist.add(uris=[link])
  36. await mopidy.playback.play()
  37. await mopidy.disconnect()
  38. asyncio.run(selector())