3.5 KiB
YouTube Chat Webhook Listener (Version 2) - gRPC Implementation
This project aims to create a robust, quota-friendly, open-source, and Linux-compatible solution for monitoring YouTube Live Chat by implementing the recommended liveChatMessages.streamList gRPC endpoint. This approach will provide an event-driven, server-push model for receiving live chat messages, effectively eliminating the limitations and quota consumption associated with continuous API polling.
Project Goal
To build a Python application that leverages the liveChatMessages.streamList gRPC endpoint to receive real-time YouTube Live Chat messages, process them, and display them in the terminal with rich formatting. This will ensure a highly efficient and compliant method for sustained live stream monitoring.
Implementation Plan: gRPC Client
Phase 1: gRPC Client Setup
-
Install Dependencies:
- Action: Install
grpcioandgrpcio-toolsPython packages.
- Action: Install
-
Obtain
.protoFile:- Action: Locate and download the official Protocol Buffers (
.proto) file that defines theliveChatMessages.streamListservice.
- Action: Locate and download the official Protocol Buffers (
-
Generate Python Client Code:
- Action: Use
grpc_tools.protocto generate the Python client-side libraries from the.protofile.
- Action: Use
-
Develop gRPC Client:
- Action: Write a Python script to:
- Establish a secure gRPC channel to the YouTube API endpoint.
- Create a client stub for the
liveChatMessages.streamListservice. - Initiate the
StreamListrequest to begin receiving messages. - Implement a loop to continuously process messages as they are pushed from the server.
- Action: Write a Python script to:
Phase 2: Integration and Enhancements
-
Integrate with Display Logic:
- Action: Adapt the existing
richdisplay logic frommain.pyto consume messages received from the gRPC client instead of the polling mechanism.
- Action: Adapt the existing
-
Error Handling & Resilience:
- Action: Implement robust error handling for gRPC connections, including automatic reconnection logic.
- Action: Utilize
nextPageToken(if provided by the gRPC stream) to resume receiving messages from where the connection was interrupted, preventing data loss.
-
Configuration:
- Action: Externalize API keys, default video ID, and display preferences into a configuration file (e.g.,
config.iniorconfig.json).
- Action: Externalize API keys, default video ID, and display preferences into a configuration file (e.g.,
-
Enhance Display Features:
- Action: Implement a more sophisticated system to assign consistent, unique colors to each user.
- Action: Improve emote rendering and potentially integrate with external emote services (e.g., BTTV, FrankerFaceZ) if feasible and compliant.
- Action: Add options for message filtering (e.g., by user, keywords, message type).
Phase 3: Testing and Documentation
-
Unit and Integration Tests:
- Action: Write comprehensive unit tests for the gRPC client, message processing, and display logic.
- Action: Develop integration tests to ensure the end-to-end flow works correctly.
-
Update Documentation:
- Action: Update the project's
README.mdwith detailed usage instructions, setup guides, and explanations of the gRPC implementation.
- Action: Update the project's
Dependencies
grpciogrpcio-toolsgoogle-auth-oauthlibgoogle-api-python-clientrich
Future Enhancements
- Interactive message sending via gRPC (if supported by the API).
- More advanced terminal UI (e.g.,
prompt_toolkitfor input). - Web overlay integration.