-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·71 lines (62 loc) · 2.42 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from threading import Thread
from scripts.vrchat import send_vrchat as vrc
from scripts.discord import connect_to_discord as dis
import subprocess, os
import json
import sys
global settings
settings = {
"MPD Address": "localhost",
"MPD Port": 6600,
"VRchat OSC Address": "localhost",
"VRchat OSC Port": 9000,
}
def save_settings():
if os.name == 'nt':
with open('settings.json', 'w') as f:
json.dump(settings, f)
else:
with open(os.path.join(os.path.expanduser('~'), ".config", 'mpd-osc-rpc.json'), 'w') as f:
json.dump(settings, f)
def load_settings():
try:
if os.name == 'nt':
with open('settings.json', 'r') as f:
loaded_settings = json.load(f)
settings.update(loaded_settings)
print("Loaded Settings Successfully!")
with open(os.path.join(os.path.expanduser('~'), ".config", 'mpd-osc-rpc.json'), 'r') as f:
loaded_settings = json.load(f)
settings.update(loaded_settings)
print("Loaded Settings Successfully!")
with open('settings.json', 'r') as f:
loaded_settings = json.load(f)
settings.update(loaded_settings)
print("Loaded Settings Successfully!")
except FileNotFoundError:
print("Error: E001: Could not find 'settings.json': Unable to load settings")
load_settings()
def vrchat_thread():
vrc(settings['VRchat OSC Address'], settings['VRchat OSC Port'], settings['MPD Address'], settings['MPD Port'])
def discord_thread():
dis(settings['MPD Address'], settings['MPD Port'])
def main():
if len(sys.argv) > 1:
if sys.argv[1] == "--discord":
print("Starting Discord RPC...")
discord_thread()
if sys.argv[1] == "--vrchat":
print("Starting VRChat OSC...")
vrchat_thread()
if sys.argv[1] == "--help":
print("no args #lauch both vrchat thread and discord thread\n--discord #runs only the discord thread\n--vrchat #runs only the vrchat thread\n--help shows this\nthe config file is located in the same directory 'settings.json'")
else:
try:
print("Starting VRChat OSC, Starting Discord RPC...")
Thread(target = vrchat_thread).start()
Thread(target = discord_thread).start()
except KeyboardInterrupt:
exit()
if __name__ == "__main__":
main()
save_settings()