# YouTube Chat Listener (Version 2) - Project Progress Log This document chronicles the key steps, findings, and decisions made during the development and research phases of the YouTube Chat Listener (Version 2) project. ## Initial State * Existing `youtube_chat_terminal` project used YouTube Data API v3 polling. * Concerns about API quota exhaustion led to the conception of `youtube-chat-webhook-v2`. ## Research Phase - Initial Plan (gRPC Misconception) * **Goal:** Find a quota-friendly, compliant solution. * **Initial Hypothesis:** `liveChatMessages.streamList` (gRPC) was believed to be the ideal solution. * **Action:** A detailed "Deep Research Plan" was outlined in `README.md` and `DEVELOPMENT_PLAN.md`. * **Finding:** Subsequent research (via `google_web_search`) revealed that `liveChatMessages.streamList` (gRPC) is **not publicly available** for the YouTube Data API v3. This was a critical correction to the initial understanding. ## Research Phase - Revised Plan (Focus on Sustainability & `pytchat`) * **Goal:** Identify a sustainable, quota-friendly, compliant, open-source, Linux-compatible method for real-time YouTube Live Chat, explicitly ruling out API quota increases. * **Revised Strategy:** Shifted focus to: * Deep dive into YouTube's web client communication. * Re-exploration of YouTube Data API v3 (creative use). * Community solutions and open-source projects. * Re-evaluation of third-party services. * **Action:** `README.md` and `DEVELOPMENT_PLAN.md` were updated to reflect this revised plan. ## Experimental Implementation - `pytchat` Exploration * **Objective:** Experiment with `pytchat` as a direct (but risky) solution for zero-quota live chat fetching. * **Action:** Installed `pytchat` and created `pytchat_listener.py` for basic chat fetching and display. * **Status:** `pytchat_listener.py` is working as expected. * **Internal Mechanism Analysis of `pytchat`:** * **Endpoint:** `POST https://www.youtube.com/youtubei/v1/live_chat/get_live_chat` (internal, undocumented API). * **Authentication/Session:** Relies on mimicking browser headers (`User-Agent`), `visitorData` (extracted from previous responses), dynamically generated `clientVersion`, and `httpx.Client`'s automatic cookie handling. * **Continuation Token:** Complex, encoded parameter generated using custom Protocol Buffers-like encoding and timestamps. * **Channel ID Discovery:** Performs lightweight scraping of YouTube's `embed` or `m.youtube.com` pages using regex. * **Implications:** Highly fragile (subject to breaking), **critical compliance risk** (violates YouTube's Terms of Service). * **Action:** `DEVELOPMENT_PLAN.md` was updated with these findings. ## Next Steps * Proceed with "Integration with `rich` Display" as outlined in `DEVELOPMENT_PLAN.md`. * Continue with other phases of the revised research plan, keeping the compliance and fragility risks of `pytchat` in mind.