50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import json
|
|
import os
|
|
import time
|
|
|
|
from chats import YoutubeLive
|
|
from chats.ChatProcess import LIFECYCLE_MESSAGES
|
|
from chats.FakeChat import FakeChat
|
|
from ui.App import App
|
|
from plugins.PogCount import PogCounter
|
|
|
|
EVENT_POLL_FREQ = 0.1
|
|
GOOGLE_API_SECRETS_PATH = 'googleapi.secret.json'
|
|
|
|
if __name__ == '__main__':
|
|
chat_processes = [FakeChat(EVENT_POLL_FREQ)]
|
|
if os.path.exists(GOOGLE_API_SECRETS_PATH):
|
|
with open(GOOGLE_API_SECRETS_PATH, 'r') as f:
|
|
client_secrets = json.load(f)['installed']
|
|
chat_processes.append(YoutubeLive.YoutubeLiveProcess(client_secrets, EVENT_POLL_FREQ))
|
|
else:
|
|
print('No client secrets - disabling youtube chat client. Hit "f" to enable a testing client')
|
|
|
|
plugins = [PogCounter('../live-status.txt', prefix='Pog count: ')]
|
|
|
|
app = App(chat_processes, plugins)
|
|
|
|
for process in chat_processes:
|
|
process.start()
|
|
app.start()
|
|
|
|
while True:
|
|
if not app.is_alive():
|
|
break
|
|
|
|
for process in chat_processes:
|
|
if process.control_pipe.poll():
|
|
chat_control_msg = process.control_pipe.recv()
|
|
if chat_control_msg == YoutubeLive.CONTROL_MESSAGES.NEEDS_OAUTH_CONSENT_TOKEN:
|
|
code = input('Allow access in your browser and paste response code here: ')
|
|
process.control_pipe.send({
|
|
'type': YoutubeLive.CONTROL_MESSAGES.OAUTH_CONSENT_TOKEN,
|
|
'token': code
|
|
})
|
|
time.sleep(EVENT_POLL_FREQ)
|
|
|
|
for process in chat_processes:
|
|
process.control_pipe.send({'type': LIFECYCLE_MESSAGES.SHUTDOWN})
|
|
process.join(10)
|
|
if process.exitcode is None:
|
|
process.terminate()
|