From e8bc7764b6e832dadc61d9bbb821cec83532de43 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 27 Oct 2026 22:32:35 +0800 Subject: [PATCH] =?UTF-8?q?Randomize=20TikTok=20clip=20length=20to=2061?= =?UTF-8?q?=E2=80=93120s=20instead=20of=20fixed=2060=E2=80=9390.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Live record and yt-long cascade both pick a random duration in the >1–2 minute range each job. Co-authored-by: Cursor --- backend/app/clip_cascade.py | 12 ++++-------- backend/app/db.py | 3 ++- backend/app/tiktok_pipeline.py | 20 +++++--------------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/backend/app/clip_cascade.py b/backend/app/clip_cascade.py index 9012184..02e94b6 100644 --- a/backend/app/clip_cascade.py +++ b/backend/app/clip_cascade.py @@ -24,13 +24,9 @@ def _clamp(v: int, lo: int, hi: int) -> int: def tiktok_cut_sec(cfg: dict[str, Any]) -> int: - """1–1.5 minutes.""" - try: - base = int(cfg.get("tiktok_clip_sec") or 75) - except Exception: - base = 75 - base = _clamp(base, 60, 90) - return random.randint(60, max(60, base)) if base > 60 else random.randint(60, 90) + """Random >1–2 minutes (61–120s). cfg kept for call-site compatibility.""" + _ = cfg + return random.randint(61, 120) def shorts_cut_sec(cfg: dict[str, Any]) -> int: @@ -254,7 +250,7 @@ async def cascade_from_yt_long(job: dict[str, Any], cfg: dict[str, Any] | None = clips_root = settings.clips_dir clips_root.mkdir(parents=True, exist_ok=True) - # ── TikTok (1–1.5 min) ───────────────────────────────────────────── + # ── TikTok (>1–2 min random) ─────────────────────────────────────── if bool(settings_map.get("tiktok_enabled", False)): try: if room_id and tiktok_db.has_tiktok_job_for_room_day(room_id, day): diff --git a/backend/app/db.py b/backend/app/db.py index 72f5710..dce140b 100644 --- a/backend/app/db.py +++ b/backend/app/db.py @@ -656,7 +656,8 @@ def _seed_defaults(conn: sqlite3.Connection) -> None: "ops_neko_public_base": "", # TikTok pipeline (fully isolated from Shorts) "tiktok_enabled": False, - "tiktok_clip_sec": 75, + # Upper bound for random TikTok clip length (actual: randint 61..tiktok_clip_sec, max 120) + "tiktok_clip_sec": 120, "tiktok_trigger": "tagged", "tiktok_tag": "shorts", "tiktok_dedupe_room_day": True, diff --git a/backend/app/tiktok_pipeline.py b/backend/app/tiktok_pipeline.py index 44e1549..2ff2d5c 100644 --- a/backend/app/tiktok_pipeline.py +++ b/backend/app/tiktok_pipeline.py @@ -278,7 +278,9 @@ class TikTokPipeline: "quota_gap": tiktok_db.tiktok_total_quota_gap(), "quota_defaults": db.tiktok_quota_defaults(cfg), "last_error": self.last_error, - "clip_sec": max(60, min(90, int(cfg.get("tiktok_clip_sec") or 75))), + "clip_sec_min": 61, + "clip_sec_max": 120, + "clip_sec": 120, "douyin_live_count": live_count, "board": board, "oauth_issues": oauth_issues, @@ -530,20 +532,8 @@ class TikTokPipeline: ) return - # TikTok 素材 1–1.5 分钟;多 CDN 线路按 DouyinLiveRecorder 方式试探 - try: - sec = int(cfg.get("tiktok_clip_sec") or 75) - except Exception: - sec = 75 - sec = max(60, min(90, sec)) - try: - room_pk = str(job.get("room_pk") or "") - room = db.get_room(room_pk) if room_pk else None - override = db.room_clip_seconds(room, default=0, platform="tiktok") if room else 0 - if override > 0: - sec = max(60, min(90, override)) - except Exception: - pass + # TikTok 素材:>1–2 分钟随机时长(61–120s),不用固定秒数 + sec = random.randint(61, 120) outcome = await record_clip( job_id=f"tiktok_{jid[:8]}", stream_urls=candidates,