2021-11-03 13:37:53 +00:00
|
|
|
import argparse
|
2021-11-14 19:29:35 +00:00
|
|
|
import pathlib
|
2021-11-03 13:37:53 +00:00
|
|
|
|
2021-11-14 19:29:35 +00:00
|
|
|
from mopidy_json_client import MopidyClient
|
2021-11-03 13:37:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-11-14 19:29:35 +00:00
|
|
|
disk_file = f"{pathlib.Path().resolve()}/last_disk.txt"
|
2021-11-03 13:37:53 +00:00
|
|
|
|
2021-11-14 19:29:35 +00:00
|
|
|
mopidy = MopidyClient()
|
|
|
|
|
|
|
|
|
|
|
|
def selector(action):
|
|
|
|
last_disk_read = open(disk_file, "r+").read()
|
2021-11-08 12:12:31 +00:00
|
|
|
if action is not "" and last_disk_read != action:
|
|
|
|
if action == "stop":
|
2021-11-14 19:29:35 +00:00
|
|
|
mopidy.playback.stop()
|
|
|
|
mopidy.tracklist.clear()
|
2021-11-08 12:12:31 +00:00
|
|
|
elif action == "next":
|
2021-11-14 19:29:35 +00:00
|
|
|
mopidy.playback.next()
|
2021-11-08 12:12:31 +00:00
|
|
|
elif action == "previous":
|
2021-11-14 19:29:35 +00:00
|
|
|
mopidy.playback.previous()
|
2021-11-08 12:12:31 +00:00
|
|
|
elif action == "shuffle":
|
2021-11-14 19:29:35 +00:00
|
|
|
mopidy.tracklist.shuffle()
|
|
|
|
mopidy.tracklist.move(
|
|
|
|
start=mopidy.tracklist.index(),
|
|
|
|
end=mopidy.tracklist.index(),
|
2021-11-08 12:12:31 +00:00
|
|
|
to_position=0,
|
|
|
|
)
|
|
|
|
elif action == "playpause":
|
2021-11-14 19:29:35 +00:00
|
|
|
if mopidy.playback.get_state() == "playing":
|
|
|
|
mopidy.playback.pause()
|
2021-11-08 12:12:31 +00:00
|
|
|
else:
|
2021-11-14 19:29:35 +00:00
|
|
|
mopidy.playback.resume()
|
2021-11-08 12:12:31 +00:00
|
|
|
elif action == "":
|
|
|
|
return
|
|
|
|
else:
|
2021-11-14 19:29:35 +00:00
|
|
|
last_disk = open(disk_file, "w")
|
2021-11-08 12:12:31 +00:00
|
|
|
last_disk.write(action)
|
2021-11-14 19:29:35 +00:00
|
|
|
run_floppy(action)
|
|
|
|
mopidy.disconnect()
|
|
|
|
elif action == "":
|
|
|
|
pass
|
2021-11-03 13:37:53 +00:00
|
|
|
else:
|
2021-11-14 19:29:35 +00:00
|
|
|
if mopidy.playback.get_state() == "playing":
|
2021-11-08 12:12:31 +00:00
|
|
|
return
|
|
|
|
else:
|
2021-11-14 19:29:35 +00:00
|
|
|
run_floppy(action)
|
|
|
|
mopidy.disconnect()
|
2021-11-03 13:37:53 +00:00
|
|
|
|
|
|
|
|
2021-11-14 19:29:35 +00:00
|
|
|
def run_floppy(input):
|
2021-11-04 15:15:59 +00:00
|
|
|
link = input.split(" - ")[1]
|
2021-11-14 19:29:35 +00:00
|
|
|
mopidy.playback.stop()
|
|
|
|
mopidy.tracklist.clear()
|
|
|
|
mopidy.tracklist.add(uris=[link])
|
|
|
|
mopidy.playback.play()
|
|
|
|
mopidy.disconnect()
|
2021-11-03 13:37:53 +00:00
|
|
|
|
|
|
|
|
2021-11-14 19:29:35 +00:00
|
|
|
selector(inputURI)
|