This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
56 lines (44 loc) · 1.84 KB
/
run.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
import asyncio
import threading
import logging
import aiohttp
from bot import Music
from config import Config
from websocket_client import ws_ctrl, ws_music
logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s][%(module)s] %(message)s'
)
async def main(loop):
player_queue = asyncio.Queue()
res_queue = asyncio.Queue()
ctrl_queue = asyncio.Queue()
key: dict = {}
config = Config('config/config.json', 'config/alias.json', 'config/blacklist.json', 'config/ops.json')
session = aiohttp.ClientSession()
token = config.aria_token
discord = threading.Thread(target=discord_loader, args=(config, player_queue, res_queue, ctrl_queue, loop),name='discord', daemon=True)
ctrl = threading.Thread(target=ctrl_loader, args=(ctrl_queue, res_queue, session, config.cmd_endpoint, key, token, loop), name='ctrl', daemon=True)
music = threading.Thread(target=music_loader, args=(player_queue, session, config.stream_endpoint, key, token, loop), name='music', daemon=True)
discord.start()
ctrl.start()
music.start()
def discord_loader(config, player_queue, res_queue, ctrl_queue, loop):
asyncio.set_event_loop(loop)
music = Music(config, player_queue, res_queue, ctrl_queue, loop)
loop.create_task(music.start(config.token))
def ctrl_loader(q1, q2, session, uri, key, token, loop):
asyncio.set_event_loop(loop)
ws = ws_ctrl(q1, q2, session, uri, key, token, loop)
loop.create_task(ws.receive_res())
def music_loader(q, session, uri, key, token, loop):
asyncio.set_event_loop(loop)
ws = ws_music(q, session, uri, key, token)
loop.create_task(ws.receive_music_bin())
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.create_task(main(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
loop.close()