diff --git a/capcut_agent/pipeline.py b/capcut_agent/pipeline.py index 3d87a9e..79936e2 100644 --- a/capcut_agent/pipeline.py +++ b/capcut_agent/pipeline.py @@ -167,6 +167,21 @@ def _remap_placements(placements, keep_sorted): for p0, p1 in placements] +def captions_for_places(captions, places, *, cap: int = 500): + """컷 구간마다 그 구간에 걸친 자막을 이어붙인다 — 댓글 추천의 근거. + + `captions`·`places` 둘 다 **같은(압축) 타임라인** 좌표여야 한다. 겹치는 부분이 + 조금이라도 있으면 그 컷의 말로 본다(경계에 닿기만 하는 건 제외). + cap 자에서 자른다 — 그 이상은 Gemini 토큰만 먹고 매칭 정확도가 안 오른다. + Returns: places 와 같은 길이의 문자열 리스트 + """ + out = [] + for p0, p1 in places: + parts = [txt for cs, ce, txt in captions if cs < p1 and ce > p0 and txt] + out.append(" ".join(" ".join(parts).split())[:cap]) + return out + + def _safe_name(name: str) -> str: s = "".join(c for c in name if c.isalnum() or c in (" ", "_", "-", ".")).strip() return s[:60] or "video"