debug: canlı-tespit için detaylı teşhis bilgisi ekle

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 <noreply@anthropic.com>
This commit is contained in:
2026-08-30 20:01:58 +03:00
co-authored by Claude Sonnet 5
parent 32c09de896
commit 5447a8d269
2 changed files with 17 additions and 1 deletions
+2 -1
View File
@@ -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,
})),
});
});
+15
View File
@@ -13,6 +13,14 @@ const BROWSER_USER_AGENT =
*/
export const lastPollErrors = new Map<string, string>();
/**
* 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<string, string>();
/**
* 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<string | null> {
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);