xenova / chat-downloader

A simple tool used to retrieve chat messages from livestreams, videos, clips and past broadcasts. No authentication needed!
https://chat-downloader.readthedocs.io/
MIT License
902 stars 127 forks source link

[QUESTION] How can I stop chat downloader if the livestreaming is offline #231

Open SqixOW opened 9 months ago

SqixOW commented 9 months ago

What is your question?

in this code:

from chat_downloader import ChatDownloader

chat = ChatDownloader().get_chat("twitch.tv/sqix")

for message in chat:
     print(message)

How can I break the loop if the livestreaming is offline? I tried to add the event listener function, but it needs one more chat after the livestreaming is offline.

chat = ChatDownloader().get_chat(url=url_base + username)

filtered_chat = takewhile(lambda m: check_online(), chat)

while True:
    try:
        message = next(filtered_chat)
        save_chat(chat_set, message)
    except StopIteration:
        break

How to resolve it?