From cecc52f52b0444716e23340d1e52d3a04ea0cec3 Mon Sep 17 00:00:00 2001 From: Ramforth Date: Thu, 30 Oct 2025 18:12:53 +0100 Subject: [PATCH] Add pytchat_listener.py for basic chat fetching --- pytchat_listener.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 pytchat_listener.py diff --git a/pytchat_listener.py b/pytchat_listener.py new file mode 100644 index 0000000..5ff8557 --- /dev/null +++ b/pytchat_listener.py @@ -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()