Some working architecture for messages
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
from clipper.api import TwitchApi, TwitchStreamStatus
|
||||
from clipper.chat import TwitchChatRecorder
|
||||
from clipper.video import TwitchVideoRecorder
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RecorderConfig:
|
||||
def __init__(self, tw_client, tw_secret, tw_streamer, tw_quality, output_path):
|
||||
self.output_path = output_path
|
||||
def __init__(self, tw_client, tw_secret, tw_streamer, tw_quality, output_folder):
|
||||
self.output_folder = output_folder
|
||||
self.tw_quality = tw_quality
|
||||
self.tw_streamer = tw_streamer
|
||||
self.tw_secret = tw_secret
|
||||
@@ -18,64 +21,43 @@ class RecorderConfig:
|
||||
|
||||
|
||||
class Recorder:
|
||||
audio_thread = None
|
||||
video_thread = None
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.api = TwitchApi(config.tw_client, config.tw_secret)
|
||||
# self.video_recorder = TwitchVideoRecorder(self.api,)
|
||||
self.chat_recorder = TwitchChatRecorder(self.api, config.tw_streamer)
|
||||
self.recording_folder = os.path.join(self.config.output_folder, self.config.tw_streamer)
|
||||
self.video_recorder = TwitchVideoRecorder(self.api, config.tw_streamer, self.recording_folder)
|
||||
self.chat_recorder = TwitchChatRecorder(self.api, config.tw_streamer, self.recording_folder)
|
||||
|
||||
def run(self):
|
||||
if os.path.isdir(self.recording_folder) is False:
|
||||
logger.info("Recording folder `%s` does not exists. Create it", self.recording_folder)
|
||||
os.makedirs(self.recording_folder)
|
||||
|
||||
while True:
|
||||
logger.info("Start watching streamer %s", self.config.tw_streamer)
|
||||
status = self.api.get_user_status(self.config.tw_streamer)
|
||||
if status == TwitchStreamStatus.ONLINE:
|
||||
logger.info("Streamer %s is online. Start recording", self.config.tw_streamer)
|
||||
self.chat_recorder.run()
|
||||
# TODO run video record and join to it.. Run 2 threads?
|
||||
logger.info("Streamer %s finished his stream", self.config.tw_streamer)
|
||||
|
||||
now = datetime.now()
|
||||
file_template = "{0}-{1}".format(self.config.tw_streamer, now.strftime("%H-%M-%S"))
|
||||
self.chat_recorder.run(file_template)
|
||||
# self.video_recorder.run(file_template)
|
||||
|
||||
logger.info("Streamer %s has finished stream", self.config.tw_streamer)
|
||||
time.sleep(15)
|
||||
|
||||
if status == TwitchStreamStatus.OFFLINE:
|
||||
logger.info("Streamer %s is offline. Waiting for it 60 sec", self.config.tw_streamer)
|
||||
time.sleep(60)
|
||||
logger.info("Streamer %s is offline. Waiting for 300 sec", self.config.tw_streamer)
|
||||
time.sleep(300)
|
||||
|
||||
if status == TwitchStreamStatus.ERROR:
|
||||
logger.critical("Error occurred. Exit", self.config.tw_streamer)
|
||||
sys.exit(1)
|
||||
|
||||
# def run(self):
|
||||
# logger.info("Start watching streamer %s", self.config.tw_streamer)
|
||||
#
|
||||
# while True:
|
||||
# status, info = self.api.check_user_status(self.config.tw_streamer)
|
||||
# if status == TwitchStreamStatus.NOT_FOUND:
|
||||
# logger.error("streamer_name not found, invalid streamer_name or typo")
|
||||
# sys.exit(1)
|
||||
# elif status == TwitchStreamStatus.ERROR:
|
||||
# logger.error("%s unexpected error. will try again in 5 minutes",
|
||||
# datetime.datetime.now().strftime("%Hh%Mm%Ss"))
|
||||
# time.sleep(300)
|
||||
# elif status == TwitchStreamStatus.OFFLINE:
|
||||
# logger.info("%s currently offline, checking again in %s seconds", self.streamer_name,
|
||||
# self.refresh_timeout)
|
||||
# time.sleep(self.refresh_timeout)
|
||||
# elif status == TwitchStreamStatus.UNAUTHORIZED:
|
||||
# logger.info("unauthorized, will attempt to log back in immediately")
|
||||
# self.access_token = self.authenticator.refresh_token()
|
||||
# elif status == TwitchStreamStatus.ONLINE:
|
||||
# logger.info("%s online, stream recording in session", self.streamer_name)
|
||||
#
|
||||
# channels = info["data"]
|
||||
# channel = next(iter(channels), None)
|
||||
#
|
||||
# recorded_filename = self.record_stream(channel, recording_path)
|
||||
#
|
||||
# logger.info("recording stream is done")
|
||||
#
|
||||
# if self.on_finish is not None:
|
||||
# self.on_finish(channel, recorded_filename)
|
||||
#
|
||||
# time.sleep(self.refresh_timeout)
|
||||
|
||||
# def start_record(self):
|
||||
# pass
|
||||
if status == TwitchStreamStatus.NOT_FOUND:
|
||||
logger.critical(f"Streamer %s not found, invalid streamer_name or typo", self.config.tw_streamer)
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user