fix: YouTube channel ID (UC...) handling + handle-to-channelId resolution

discover-channels: extractHandle('youtube') now detects UC* channel IDs
and returns them without @ prefix (previously @UC... caused verify fail)

verifyHandles: verifyYouTube uses cleanHandle for UC* check, requests
part=id,snippet for richer data

collect-channel-data: if channelId missing but handle present, resolves
via forHandle/forUsername lookup or direct UC* detection before skipping

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-04 01:00:21 +09:00
1 parent 163751410f
commit df8f84c3b9
3 files changed
+21 -4

No files matched your search

@@ -109,7 +109,22 @@ Deno.serve(async (req) => {
if (YOUTUBE_API_KEY && ytVerified?.verified) {
tasks.push((async () => {
const YT = "https://www.googleapis.com/youtube/v3";
const channelId = (ytVerified?.channelId as string) || "";
let channelId = (ytVerified?.channelId as string) || "";
// If no channelId, try to resolve from handle
if (!channelId && ytVerified?.handle) {
const h = (ytVerified.handle as string).replace(/^@/, '');
if (h.startsWith('UC')) {
channelId = h;
} else {
for (const param of ['forHandle', 'forUsername']) {
const lookupRes = await fetch(`${YT}/channels?part=id&${param}=${h}&key=${YOUTUBE_API_KEY}`);
const lookupData = await lookupRes.json();
channelId = lookupData.items?.[0]?.id || '';
if (channelId) break;
}
}
}
if (!channelId) return;
const chRes = await fetch(`${YT}/channels?part=snippet,statistics,brandingSettings&id=${channelId}&key=${YOUTUBE_API_KEY}`);