diff --git a/capcut_agent/comments.py b/capcut_agent/comments.py index 5a382f9..3aa3025 100644 --- a/capcut_agent/comments.py +++ b/capcut_agent/comments.py @@ -23,6 +23,19 @@ _TAG_RE = re.compile(r"<[^>]+>") # 후보(candidates)는 분:초가 아예 없는 댓글만 쓰므로, 여기만 막으면 화면에서 완전히 빠진다. MAX_TIMES = 3 +# 광고/홍보 댓글 판별 — 좋아요를 조작한 광고가 ➕좋아요 채우기·후보 상위에 올라와 +# 드래프트 카드로 뽑히는 사고 방지. 오탐이 더 아프므로 보수적으로: +# URL, "n% 할인", "최저가"만 본다("할인"·"%" 단독인 일상 댓글은 통과). +_AD_RE = re.compile( + r"https?://|www\.|tinyurl\.|bit\.ly|" + r"\d+\s*%\s*할인|최저가" +) + + +def _is_ad(text: str) -> bool: + """광고/홍보 댓글이면 True — fetch_comments 가 수집 단계에서 걸러낸다.""" + return bool(_AD_RE.search(plain_text(text))) + def plain_text(html: str) -> str: """YouTube textDisplay(HTML) → 평문.
→줄바꿈, 나머지 태그 제거.""" @@ -61,11 +74,14 @@ def fetch_comments(url: str, *, timeout: float = 180.0) -> List[Dict]: if not data.get("success"): raise RuntimeError(f"h-lab 응답 실패: {data.get('message')}") out: List[Dict] = [] - for i, c in enumerate(data.get("data") or []): + for c in data.get("data") or []: + text = str(c.get("text") or "") + if _is_ad(text): # 광고는 수집 단계에서 제외 — 어떤 추천 경로로도 카드가 못 된다 + continue out.append({ - "idx": i, + "idx": len(out), "authorName": str(c.get("authorName") or ""), - "text": str(c.get("text") or ""), + "text": text, "likeCount": int(c.get("likeCount") or 0), "replyCount": int(c.get("replyCount") or 0), "publishedAt": str(c.get("publishedAt") or ""),