fix: Instagram data collection pipeline — handle normalization + DB persistence
- enrich-channels: Instagram fallback — auto-try _ps, .ps, _clinic suffixes when <100 followers - enrich-channels: YouTube URL normalization via normalizeYouTubeChannel (handles /c/, /user/, @handle) - enrich-channels: Google Maps multi-query search for better hit rate - generate-report: AI-found social handles prioritized over Firecrawl scrape - generate-report: Added socialMedia field to AI prompt for accurate handle discovery - normalizeHandles: Added normalizeYouTubeChannel for /c/, /user/, /channel/, @handle URLs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9bf47f7d93
commit
e5399486f7
3 files changed
+157
-56
No files matched your search
@@ -46,3 +46,62 @@ export function normalizeInstagramHandle(
|
||||
|
||||
return handle || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a YouTube channel identifier from various URL formats.
|
||||
*
|
||||
* Returns an object with the best identifier type for API lookup:
|
||||
* - "https://www.youtube.com/@banobagips" → { type: 'handle', value: 'banobagips' }
|
||||
* - "https://youtube.com/c/banobagips" → { type: 'username', value: 'banobagips' }
|
||||
* - "https://youtube.com/user/banobagi" → { type: 'username', value: 'banobagi' }
|
||||
* - "https://youtube.com/channel/UCxxxx" → { type: 'channelId', value: 'UCxxxx' }
|
||||
* - "@banobagips" → { type: 'handle', value: 'banobagips' }
|
||||
* - "UCxxxx" → { type: 'channelId', value: 'UCxxxx' }
|
||||
* - "banobagips" → { type: 'username', value: 'banobagips' }
|
||||
*/
|
||||
export function normalizeYouTubeChannel(
|
||||
raw: string | null | undefined,
|
||||
): { type: 'handle' | 'username' | 'channelId'; value: string } | null {
|
||||
if (!raw || typeof raw !== "string") return null;
|
||||
|
||||
let input = raw.trim();
|
||||
if (!input) return null;
|
||||
|
||||
// Parse YouTube URLs
|
||||
if (input.includes("youtube.com") || input.includes("youtu.be")) {
|
||||
try {
|
||||
const urlStr = input.startsWith("http") ? input : `https://${input}`;
|
||||
const url = new URL(urlStr);
|
||||
const segments = url.pathname.split("/").filter(Boolean);
|
||||
|
||||
if (segments[0] === "channel" && segments[1]?.startsWith("UC")) {
|
||||
return { type: "channelId", value: segments[1] };
|
||||
}
|
||||
if (segments[0] === "c" && segments[1]) {
|
||||
return { type: "username", value: segments[1] };
|
||||
}
|
||||
if (segments[0] === "user" && segments[1]) {
|
||||
return { type: "username", value: segments[1] };
|
||||
}
|
||||
if (segments[0]?.startsWith("@")) {
|
||||
return { type: "handle", value: segments[0].slice(1) };
|
||||
}
|
||||
// Fallback: first path segment
|
||||
if (segments[0]) {
|
||||
return { type: "username", value: segments[0] };
|
||||
}
|
||||
} catch {
|
||||
// URL parsing failed
|
||||
}
|
||||
}
|
||||
|
||||
// Non-URL formats
|
||||
if (input.startsWith("@")) {
|
||||
return { type: "handle", value: input.slice(1) };
|
||||
}
|
||||
if (input.startsWith("UC") && input.length > 20) {
|
||||
return { type: "channelId", value: input };
|
||||
}
|
||||
|
||||
return { type: "username", value: input };
|
||||
}
|
||||
Reference in new issue
Block a user