-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
executable file
·47 lines (39 loc) · 1.21 KB
/
scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/python3
import utils
import json
import session
from time import sleep
busy_session: session.Session = None
config: dict
def player_is_valid(player_name: str) -> bool:
for player in config["players"]:
if player_name == player:
return True
return False
def check_players():
# check if already busy with a session
global busy_session
if busy_session != None:
return False
# Check if any players are playing
act_players = utils.execute("playerctl -l").split('\n')
for player in act_players:
if player_is_valid(player):
try:
busy_session = session.Session(player,
config["players"][player])
except:
print("An error occured, restarting...")
print("done")
busy_session = None
return True
# no valid player, keep searching
if __name__ == '__main__':
print("music-rpc started... " + utils.execute('date'))
with open("players.json", "r") as json_file:
config = json.load(json_file)
print(json_file.readlines)
print("Loaded config...")
while True:
check_players()
sleep(3)