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:
@@ -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,
|
||||
})),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user