From 2266d0a3ee3a3512ed243034d25542550ad66969 Mon Sep 17 00:00:00 2001 From: "hehihoho3@gmail.com" Date: Wed, 5 Aug 2026 15:54:20 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20h-lab=20=EC=88=98=EC=A7=91=20=EB=8B=A8?= =?UTF-8?q?=EA=B3=84=EC=97=90=EC=84=9C=20=EA=B4=91=EA=B3=A0/=ED=99=8D?= =?UTF-8?q?=EB=B3=B4=20=EB=8C=93=EA=B8=80=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 좋아요를 조작한 광고(할인 링크 등)가 ➕좋아요 채우기·후보 상위로 올라와 드래프트 카드에 들어가는 사고가 실제로 났다. 오탐이 더 아프므로 보수적으로 URL·"n% 할인"·"최저가"만 걸러낸다("할인"·"%" 단독 일상 댓글은 통과). Co-Authored-By: Claude Opus 5 (1M context) --- capcut_agent/comments.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 ""),