From 5447a8d26988c20efa2124bb4a46faf44ebb2660 Mon Sep 17 00:00:00 2001 From: ayrisdev Date: Sun, 30 Aug 2026 20:01:58 +0300 Subject: [PATCH] =?UTF-8?q?debug:=20canl=C4=B1-tespit=20i=C3=A7in=20detayl?= =?UTF-8?q?=C4=B1=20te=C5=9Fhis=20bilgisi=20ekle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cookie header'ı eklemek beklenen sonucu vermedi — @ertemsener kanalı gerçekten canlıydı ama sistem hâlâ "değil" diyordu. Kör tahminle devam etmek yerine, her kontrolde (sonuç ne olursa olsun) final URL, HTML uzunluğu, cookie gönderilip gönderilmediği, videoDetails bulunup bulunmadığı ve consent formu varlığı GET /status'ta lastPollDebug alanında görünür kılındı. Co-Authored-By: Claude Sonnet 5 --- apps/api-daemon/src/server.ts | 3 ++- apps/api-daemon/src/youtubePolling.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/api-daemon/src/server.ts b/apps/api-daemon/src/server.ts index 451a6b8..dd08646 100644 --- a/apps/api-daemon/src/server.ts +++ b/apps/api-daemon/src/server.ts @@ -1,7 +1,7 @@ import express from "express"; import { prisma } from "@streamclipper/db"; import { env } from "./env"; -import { lastPollErrors } from "./youtubePolling"; +import { lastPollErrors, lastPollDebug } from "./youtubePolling"; import { lastCaptureDebug } from "./capture/streamIngest"; export function startServer() { @@ -29,6 +29,7 @@ export function startServer() { recording: c.sessions.length > 0, activeSessionId: c.sessions[0]?.id ?? null, lastPollError: lastPollErrors.get(c.channelId) ?? null, + lastPollDebug: lastPollDebug.get(c.channelId) ?? null, })), }); }); diff --git a/apps/api-daemon/src/youtubePolling.ts b/apps/api-daemon/src/youtubePolling.ts index 477961b..91a9b01 100644 --- a/apps/api-daemon/src/youtubePolling.ts +++ b/apps/api-daemon/src/youtubePolling.ts @@ -13,6 +13,14 @@ const BROWSER_USER_AGENT = */ export const lastPollErrors = new Map(); +/** + * Diagnostic snapshot of the last check per channel, kept regardless of + * outcome — unlike lastPollErrors (cleared on a clean "not live" result), + * this stays populated so a genuinely-live channel that's misreported as + * offline can still be debugged via GET /status. + */ +export const lastPollDebug = new Map(); + /** * Two earlier approaches both had real problems: * - A naive regex over the channel /live page HTML grabbed the FIRST @@ -56,6 +64,13 @@ async function findLiveVideoId(channelId: string): Promise { lastPollErrors.delete(channelId); const match = html.match(/"videoDetails":\{"videoId":"([^"]+)"/); + const hasConsentForm = /action="https:\/\/consent\.youtube\.com/.test(html); + lastPollDebug.set( + channelId, + `finalUrl=${res.url} htmlLength=${html.length} cookieSent=${Boolean(cookieHeader)} ` + + `hasVideoDetails=${Boolean(match)} hasConsentForm=${hasConsentForm}`, + ); + if (!match) return null; const window = html.slice(match.index!, match.index! + 600);