rework to simple string input
This commit is contained in:
parent
861575f9ec
commit
b633706e56
34
main.py
34
main.py
@ -23,32 +23,38 @@ create_config(client)
|
|||||||
# Check if any arguments are passed
|
# Check if any arguments are passed
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
# Get the JSON argument from the command line
|
# Get the JSON argument from the command line
|
||||||
json_str = sys.argv[1]
|
input_str = sys.argv[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Convert the JSON string into a dictionary
|
# Convert the JSON string into a dictionary
|
||||||
disc_data = json.loads(json_str.replace("'",'"'))
|
disc_data = input_str.split(":")
|
||||||
# Check if disc is the same as last inserted
|
if disc_data[0] == "ytmusic":
|
||||||
if (disc_data == json.loads(check_current_disc(client))):
|
disc_object = {
|
||||||
# If disc is the same, PLAY
|
"Name":disc_data[1],
|
||||||
control_player(client, "PLAY")
|
"type":disc_data[2],
|
||||||
else:
|
"id":disc_data[3]
|
||||||
# Pass the parsed data to the update_disc function
|
}
|
||||||
control_player(client, "PLAY")
|
# Check if disc is the same as last inserted
|
||||||
update_disc(client, disc_data)
|
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:
|
except json.JSONDecodeError as e:
|
||||||
try:
|
try:
|
||||||
if json_str == "EJECT":
|
if input_str == "EJECT":
|
||||||
# PAUSE the current playing item
|
# PAUSE the current playing item
|
||||||
control_player(client, "PAUSE")
|
control_player(client, "PAUSE")
|
||||||
elif json_str == "PLAY":
|
elif input_str == "PLAY":
|
||||||
# PLAY the current playing item
|
# PLAY the current playing item
|
||||||
control_player(client, "PLAY")
|
control_player(client, "PLAY")
|
||||||
elif json_str == "PAUSE":
|
elif input_str == "PAUSE":
|
||||||
# PAUSE the current playing item
|
# PAUSE the current playing item
|
||||||
control_player(client, "PAUSE")
|
control_player(client, "PAUSE")
|
||||||
else:
|
else:
|
||||||
print(f"Can't process {json_str}")
|
print(f"Can't process {input_str}")
|
||||||
except Exception:
|
except Exception:
|
||||||
print(f"Invalid JSON format: {e}")
|
print(f"Invalid JSON format: {e}")
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user