From 6eb668510b32b6405769ccb15cf62bded94677c8 Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Fri, 20 Sep 2024 12:52:23 +0100 Subject: [PATCH] rework input to string --- main.py | 62 ++++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/main.py b/main.py index 0679f9c..38019cc 100644 --- a/main.py +++ b/main.py @@ -25,37 +25,31 @@ if len(sys.argv) > 1: # Get the JSON argument from the command line input_str = sys.argv[1] - try: - # Convert the JSON string into a dictionary - disc_data = input_str.split(":") - if disc_data[0] == "ytmusic": - disc_object = { - "Name":disc_data[1], - "type":disc_data[2], - "id":disc_data[3] - } - # Check if disc is the same as last inserted - if (disc_object == json.loads(check_current_disc(client))): - # If disc is the same, PLAY - control_player(client, "PLAY") - else: - # Pass the parsed data to the update_disc function - control_player(client, "PLAY") - update_disc(client, disc_data) - except json.JSONDecodeError as e: - try: - if input_str == "EJECT": - # PAUSE the current playing item - control_player(client, "PAUSE") - elif input_str == "PLAY": - # PLAY the current playing item - control_player(client, "PLAY") - elif input_str == "PAUSE": - # PAUSE the current playing item - control_player(client, "PAUSE") - else: - print(f"Can't process {input_str}") - except Exception: - print(f"Invalid JSON format: {e}") -else: - print("No Command or Track Info Passed") \ No newline at end of file + # Convert the JSON string into a dictionary + disc_data = input_str.split(":") + if disc_data[0] == "ytmusic": + disc_object = { + "Name":disc_data[1], + "type":disc_data[2], + "id":disc_data[3] + } + # Check if disc is the same as last inserted + if (disc_object == json.loads(check_current_disc(client))): + # If disc is the same, PLAY + control_player(client, "PLAY") + else: + # Pass the parsed data to the update_disc function + control_player(client, "PLAY") + update_disc(client, disc_data) + else: + if input_str == "EJECT": + # PAUSE the current playing item + control_player(client, "PAUSE") + elif input_str == "PLAY": + # PLAY the current playing item + control_player(client, "PLAY") + elif input_str == "PAUSE": + # PAUSE the current playing item + control_player(client, "PAUSE") + else: + print(f"Can't process {input_str}") \ No newline at end of file