pretty good status

This commit is contained in:
Vitalii Lebedynskyi
2022-08-15 17:07:59 +03:00
parent efa6216e2a
commit 173fcc098f
6 changed files with 42 additions and 30 deletions

View File

@@ -8,7 +8,6 @@ CHAT_DIVIDER = "<~|~>"
class TwitchChatRecorder:
is_running = False
chat_process = None
def __init__(self, api, debug=False):
@@ -16,10 +15,23 @@ class TwitchChatRecorder:
self.api = api
def run(self, streamer_name, output_file):
self.is_running = True
self.chat_process = multiprocessing.Process(target=self._record_chat, args=(streamer_name, output_file))
self.chat_process.start()
def stop(self):
try:
if self.chat_process:
self.chat_process.terminate()
self.chat_process = None
logger.info("Chat stopped")
except BaseException as e:
logger.error("Unable to stop chat")
logger.error(e)
def is_running(self):
return self.chat_process is not None and self.chat_process.is_alive()
def _record_chat(self, streamer_name, output_file):
with open(output_file, "w") as stream:
def on_message(twitch_msg):
@@ -34,19 +46,6 @@ class TwitchChatRecorder:
self.api.start_chat(streamer_name, on_message)
def stop(self):
try:
if self.chat_process:
self.chat_process.terminate()
self.chat_process = None
logger.error("Chat stopped")
except BaseException as e:
logger.error("Unable to stop chat")
logger.error(e)
self.is_running = False
def parse_msg(self, msg):
try:
return msg[1:].split('!')[0], msg.split(":", 2)[2]