Add pytchat_listener.py for basic chat fetching

This commit is contained in:
2025-10-30 18:12:53 +01:00
parent 956d5d7c6f
commit cecc52f52b

41
pytchat_listener.py Normal file
View File

@@ -0,0 +1,41 @@
import pytchat
import sys
import os
from rich.console import Console
from rich.style import Style
console = Console()
def main():
# Clear the terminal screen
os.system('clear')
video_id = input("Enter the YouTube Live Stream Video ID: ")
try:
livechat = pytchat.create(video_id=video_id)
console.print(f"[green]Listening to live chat for video ID: {video_id}[/green]")
message_count = 0
while livechat.is_alive():
for c in livechat.get().sync_items():
author_display_name = c.author.name
message_text = c.message
# Simple alternating background for readability
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
# Basic username styling
username_style = Style(color="#4CAF50", bold=True)
formatted_message = f"[{username_style}]{author_display_name}[/]: {message_text}"
console.print(formatted_message, style=background_style)
message_count += 1
except Exception as e:
console.print(f"[red]An error occurred: {e}[/red]")
finally:
console.print("[yellow]Live chat listener stopped.[/yellow]")
if __name__ == '__main__':
main()