from liveMan import DouyinLiveWebFetcher, DouyinLiveWebReply
from argparse import ArgumentParser
from helper import PromptQueue
from multiprocessing import Process, Event, freeze_support


def parse_args():
    parser = ArgumentParser()
    parser.add_argument('--live_id', type=str, required=True, help='直播间id')
    args = parser.parse_args()
    return args


def fetch_user_chat_content(live_id, ws_open_event, queue):
    fetcher = DouyinLiveWebFetcher(live_id, ws_open_event, queue)
    fetcher.start()


def reply_user_chat_content(queue):
    reply = DouyinLiveWebReply(queue)
    reply()


if __name__ == '__main__':
    freeze_support()
    args = parse_args()

    queue = PromptQueue(1000)
    ws_open_event = Event()

    fetch_process = Process(target=fetch_user_chat_content, args=(args.live_id, ws_open_event, queue))
    reply_process = Process(target=reply_user_chat_content, args=(queue,))
    fetch_process.start()
    ws_open_event.wait()
    reply_process.start()
    fetch_process.join()
    reply_process.join()
