This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (43 loc) · 1.54 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
import toml
import watcher
import signal
import watcher
import requests
import os
from argparse import ArgumentParser
parser = ArgumentParser(description="QueueWatchClient")
parser.add_argument("path_to_google_home", type=str, help="URL to Google Home")
parser.add_argument("--local", action='store_true', help="Run with using local redis server")
parser.add_argument("--debug", action='store_true', help="Run with debug mode")
parser.add_argument("--wait", type=int, help="Wait time between songs [sec]")
# TODO: Implements multi target selection available
# TODO: Implements dynamic address modification (based on HTTP request)
# TARGETS = []
TARGET = None
TRYTIMES = 3
def callback(data):
"""
callback function
:param data: parsed json data (dict)
:return:
"""
for i in range(TRYTIMES):
params = {"text":data["song"]["music_url"]}
res = requests.get(TARGET, params=params)
if res.status_code == requests.codes.ok:
return
raise TimeoutError
if __name__ == '__main__':
args = parser.parse_args()
TARGET = args.path_to_google_home
conf = toml.load(os.path.join(os.path.dirname(__file__), "config.toml"))
if args.local:
host = conf["redis-local"]["ip"]
port = conf["redis-local"]["port"]
password = None
else:
host = conf["redis"]["ip"]
port = conf["redis"]["port"]
password = conf["redis"]["password"]
w = watcher.PlayQueueWatcher(host, port, password=password, debug=args.debug, wait=args.wait)
w.start(callback, with_thread=False)