fix 유튜브 채널 수집 실패 버그

This commit is contained in:
jaehwang committed 2026-05-20 10:00:39 +09:00
1 parent 18d01357c0
commit 1f45b3e53d
4 files changed
+40 -124

No files matched your search

-44
View File
@@ -1,5 +1,4 @@
import os
import re
import asyncio
from http import HTTPMethod
import httpx
@@ -38,46 +37,3 @@ async def http_request(
print(f" [error] {label} → {e}")
return None
return None
_SKIP_IG = {"p", "reel", "stories", "explore", "accounts", "about", "directory"}
_SKIP_FB = {"sharer", "share", "dialog", "plugins", "groups", "events", "watch", "help"}
def extract_social_handles(urls: list[str]) -> dict[str, list[str]]:
result: dict[str, list[str]] = {"instagram": [], "youtube": [], "facebook": [], "naver_blog": [], "tiktok": []}
for url in urls:
if not url:
continue
m = re.search(r"instagram\.com/([a-zA-Z0-9._]+)", url)
if m and m.group(1).lower() not in _SKIP_IG:
result["instagram"].append(m.group(1))
m = re.search(r"youtube\.com/(?:@([a-zA-Z0-9._-]+)|channel/(UC[a-zA-Z0-9_-]+)|c/([a-zA-Z0-9._-]+))", url)
if m:
result["youtube"].append(f"@{m.group(1)}" if m.group(1) else (m.group(2) or m.group(3) or ""))
m = re.search(r"facebook\.com/([a-zA-Z0-9._-]+)", url)
if m and m.group(1).lower() not in _SKIP_FB:
result["facebook"].append(m.group(1))
m = re.search(r"blog\.naver\.com/([a-zA-Z0-9_-]+)", url)
if m:
result["naver_blog"].append(m.group(1))
m = re.search(r"tiktok\.com/@([a-zA-Z0-9._-]+)", url)
if m:
result["tiktok"].append(m.group(1))
return {k: list(set(v)) for k, v in result.items()}
def normalize_handle(platform: str, value: str) -> str:
"""URL이 들어오면 핸들을 추출하고, 이미 핸들이면 그대로 반환."""
if not value:
return value
if "://" in value or value.startswith("www."):
handles = extract_social_handles([value]).get(platform, [])
value = handles[0] if handles else value
return value.lstrip("@") if platform != "youtube" else value