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);