Files
pytchat-fork/pytchat/cli/echo.py
taizan-hokouto bc3f16e86b Move functions
2020-12-05 14:39:55 +09:00

23 lines
691 B
Python

import pytchat
from ..exceptions import ChatDataFinished, NoContents
from ..util import extract_video_id
class Echo:
def __init__(self, video_id):
self.video_id = extract_video_id(video_id)
def run(self):
livechat = pytchat.create(self.video_id)
while livechat.is_alive():
chatdata = livechat.get()
for c in chatdata.sync_items():
print(f"{c.datetime} [{c.author.name}] {c.message} {c.amountString}")
try:
livechat.raise_for_status()
except (ChatDataFinished, NoContents):
print("Chat finished.")
except Exception as e:
print(type(e), str(e))