fix: YouTube name matching + Facebook domain fallback in channel discovery
YouTube now verifies all candidates and picks best match by channel title. Facebook tries all candidates with domain-name fallback when Firecrawl returns empty. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
d1157da39c
commit
2ca9ec0306
2 files changed
+67
-12
No files matched your search
@@ -251,12 +251,10 @@ Deno.serve(async (req) => {
|
||||
`https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel&q=${q}&maxResults=3&key=${YOUTUBE_API_KEY}`
|
||||
);
|
||||
const data = await res.json();
|
||||
// Add ALL search results — let verifyAllHandles pick the best match by name
|
||||
for (const item of (data.items || [])) {
|
||||
const channelId = item.snippet?.channelId || item.id?.channelId;
|
||||
const title = (item.snippet?.title || "").toLowerCase();
|
||||
const nameL = resolvedName.toLowerCase();
|
||||
// Match if title contains clinic name or vice versa
|
||||
if (channelId && (title.includes(nameL) || nameL.includes(title) || title.includes(nameL.replace(/성형외과|병원|의원|클리닉/g, '').trim()))) {
|
||||
if (channelId) {
|
||||
apiHandles.youtube!.push(channelId);
|
||||
}
|
||||
}
|
||||
@@ -466,6 +464,15 @@ Deno.serve(async (req) => {
|
||||
tiktok: [...new Set(merged.tiktok.map(h => extractHandle(h, 'tiktok')).filter((h): h is string => h !== null))],
|
||||
};
|
||||
|
||||
// Fallback: try domain name as Facebook/Instagram handle if no candidates found
|
||||
try {
|
||||
const domain = new URL(url).hostname.replace('www.', '').split('.')[0]; // e.g. "idhospital"
|
||||
if (domain && domain.length >= 3) {
|
||||
if (cleanHandles.facebook.length === 0) cleanHandles.facebook.push(domain);
|
||||
if (cleanHandles.instagram.length === 0) cleanHandles.instagram.push(domain);
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
|
||||
const verified: VerifiedChannels = await verifyAllHandles(
|
||||
cleanHandles, resolvedName, gangnamUnniHintUrl,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user