fix: TikTok 文案只用标题模板原文,取样最短 1 分钟

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric 2026-08-14 20:33:24 -05:00
parent 4c8eafacb3
commit 21f74cb85c
6 changed files with 24 additions and 27 deletions

View File

@ -225,8 +225,8 @@ def init_db() -> None:
enabled INTEGER NOT NULL DEFAULT 1, enabled INTEGER NOT NULL DEFAULT 1,
daily_min INTEGER NOT NULL DEFAULT 9, daily_min INTEGER NOT NULL DEFAULT 9,
daily_max INTEGER NOT NULL DEFAULT 9, daily_max INTEGER NOT NULL DEFAULT 9,
title_template TEXT NOT NULL DEFAULT '{anchor} #fyp', title_template TEXT NOT NULL DEFAULT '',
description_template TEXT NOT NULL DEFAULT '{anchor}\n{url}', description_template TEXT NOT NULL DEFAULT '',
privacy_level TEXT NOT NULL DEFAULT 'SELF_ONLY', privacy_level TEXT NOT NULL DEFAULT 'SELF_ONLY',
last_assigned_at REAL NOT NULL DEFAULT 0, last_assigned_at REAL NOT NULL DEFAULT 0,
oauth_ok INTEGER NOT NULL DEFAULT -1, oauth_ok INTEGER NOT NULL DEFAULT -1,
@ -412,7 +412,7 @@ def _seed_defaults(conn: sqlite3.Connection) -> None:
], ],
# TikTok pipeline (fully isolated from Shorts) # TikTok pipeline (fully isolated from Shorts)
"tiktok_enabled": False, "tiktok_enabled": False,
"tiktok_clip_sec": 15, "tiktok_clip_sec": 60,
"tiktok_trigger": "tagged", "tiktok_trigger": "tagged",
"tiktok_tag": "shorts", "tiktok_tag": "shorts",
"tiktok_dedupe_room_day": True, "tiktok_dedupe_room_day": True,

View File

@ -286,8 +286,8 @@ class TikTokSessionBody(BaseModel):
class TikTokChannelCreate(BaseModel): class TikTokChannelCreate(BaseModel):
name: str = "TikTok 账号" name: str = "TikTok 账号"
enabled: bool = True enabled: bool = True
title_template: str = "{anchor} #fyp" title_template: str = ""
description_template: str = "{anchor}\n{url}" description_template: str = ""
privacy_level: str = "PUBLIC_TO_EVERYONE" privacy_level: str = "PUBLIC_TO_EVERYONE"
note: str = "" note: str = ""

View File

@ -50,8 +50,8 @@ def create_tiktok_channel(
enabled: bool = True, enabled: bool = True,
daily_min: int = TIKTOK_DAILY_FORCE, daily_min: int = TIKTOK_DAILY_FORCE,
daily_max: int = TIKTOK_DAILY_FORCE, daily_max: int = TIKTOK_DAILY_FORCE,
title_template: str = "{anchor} #fyp", title_template: str = "",
description_template: str = "{anchor}\n{url}", description_template: str = "",
privacy_level: str = "SELF_ONLY", privacy_level: str = "SELF_ONLY",
note: str = "", note: str = "",
) -> dict[str, Any]: ) -> dict[str, Any]:

View File

@ -208,7 +208,7 @@ class TikTokPipeline:
"sampled": self.sampled, "sampled": self.sampled,
"quota_gap": tiktok_db.tiktok_total_quota_gap(), "quota_gap": tiktok_db.tiktok_total_quota_gap(),
"last_error": self.last_error, "last_error": self.last_error,
"clip_sec": int(cfg.get("tiktok_clip_sec") or 15), "clip_sec": max(60, int(cfg.get("tiktok_clip_sec") or 60)),
"douyin_live_count": len(db.list_live_douyin_rooms_for_shorts(limit=400)), "douyin_live_count": len(db.list_live_douyin_rooms_for_shorts(limit=400)),
"board": board, "board": board,
"oauth_issues": oauth_issues, "oauth_issues": oauth_issues,
@ -375,7 +375,8 @@ class TikTokPipeline:
finished_at=time.time(), finished_at=time.time(),
) )
return return
sec = max(5, int(cfg.get("tiktok_clip_sec") or 15)) # TikTok 素材最少录 1 分钟
sec = max(60, int(cfg.get("tiktok_clip_sec") or 60))
outcome = await record_clip(job_id=f"tiktok_{jid[:8]}", stream_url=stream, seconds=sec) outcome = await record_clip(job_id=f"tiktok_{jid[:8]}", stream_url=stream, seconds=sec)
if not outcome.get("ok"): if not outcome.get("ok"):
tiktok_db.update_tiktok_job( tiktok_db.update_tiktok_job(
@ -430,18 +431,14 @@ class TikTokPipeline:
if not tiktok_session.channel_has_session(channel): if not tiktok_session.channel_has_session(channel):
tiktok_db.update_tiktok_job(jid, status="scheduled", error="账号未配置 Cookie") tiktok_db.update_tiktok_job(jid, status="scheduled", error="账号未配置 Cookie")
return return
title_tpl = str(channel.get("title_template") or "{anchor} #fyp") # 文案只用账号「标题模板」原文,绝不自动拼直播间名/链接
desc_tpl = str(channel.get("description_template") or "") title = str(channel.get("title_template") or "").strip()
anchor = str(fresh.get("anchor_name") or fresh.get("room_id") or "live")
url = str(fresh.get("source_url") or "")
title = title_tpl.replace("{anchor}", anchor).replace("{url}", url)
desc = desc_tpl.replace("{anchor}", anchor).replace("{url}", url)
if not tiktok_db.touch_tiktok_upload_lease(jid): if not tiktok_db.touch_tiktok_upload_lease(jid):
return return
result = await upload_tiktok_mp4( result = await upload_tiktok_mp4(
file_path=clip, file_path=clip,
title=title, title=title,
description=desc, description="",
privacy_level=str(channel.get("privacy_level") or "PUBLIC_TO_EVERYONE"), privacy_level=str(channel.get("privacy_level") or "PUBLIC_TO_EVERYONE"),
channel_pk=str(channel["id"]), channel_pk=str(channel["id"]),
) )

View File

@ -129,9 +129,8 @@ async def upload_tiktok_mp4(
_ = (description, client_key, client_secret, refresh_token, access_token, token_expires_at) _ = (description, client_key, client_secret, refresh_token, access_token, token_expires_at)
if not channel_pk: if not channel_pk:
raise ValueError("缺少 channel_pk") raise ValueError("缺少 channel_pk")
caption = (title or "").strip() # 只用 title;不再把 description 拼进文案(避免带上直播间名)
if description.strip() and description.strip() not in caption: caption = (title or "").strip()[:2200]
caption = f"{caption}\n{description.strip()}"[:2200]
try: try:
return await asyncio.wait_for( return await asyncio.wait_for(
asyncio.to_thread( asyncio.to_thread(

View File

@ -93,8 +93,7 @@ export default function TikTokPage() {
const [editId, setEditId] = useState(""); const [editId, setEditId] = useState("");
const [formName, setFormName] = useState("TikTok 账号"); const [formName, setFormName] = useState("TikTok 账号");
const [formPrivacy, setFormPrivacy] = useState("PUBLIC_TO_EVERYONE"); const [formPrivacy, setFormPrivacy] = useState("PUBLIC_TO_EVERYONE");
const [formTitle, setFormTitle] = useState("{anchor} #fyp"); const [formTitle, setFormTitle] = useState("");
const [formDesc, setFormDesc] = useState("{anchor}\n{url}");
const [sessionChannelId, setSessionChannelId] = useState(""); const [sessionChannelId, setSessionChannelId] = useState("");
const [sessionChannelName, setSessionChannelName] = useState(""); const [sessionChannelName, setSessionChannelName] = useState("");
@ -152,8 +151,7 @@ export default function TikTokPage() {
setEditId(""); setEditId("");
setFormName("TikTok 账号"); setFormName("TikTok 账号");
setFormPrivacy("PUBLIC_TO_EVERYONE"); setFormPrivacy("PUBLIC_TO_EVERYONE");
setFormTitle("{anchor} #fyp"); setFormTitle("");
setFormDesc("{anchor}\n{url}");
setShowForm(true); setShowForm(true);
setShowSessionForm(false); setShowSessionForm(false);
}; };
@ -241,7 +239,7 @@ export default function TikTokPage() {
name: formName, name: formName,
privacy_level: formPrivacy, privacy_level: formPrivacy,
title_template: formTitle, title_template: formTitle,
description_template: formDesc, description_template: "",
}), }),
}); });
toast.push("账号已添加,请粘贴 Cookie", "ok"); toast.push("账号已添加,请粘贴 Cookie", "ok");
@ -261,7 +259,7 @@ export default function TikTokPage() {
name: formName, name: formName,
privacy_level: formPrivacy, privacy_level: formPrivacy,
title_template: formTitle, title_template: formTitle,
description_template: formDesc, description_template: "",
}), }),
}); });
toast.push("已保存", "ok"); toast.push("已保存", "ok");
@ -337,8 +335,7 @@ export default function TikTokPage() {
setEditId(ch.id); setEditId(ch.id);
setFormName(ch.name || "TikTok 账号"); setFormName(ch.name || "TikTok 账号");
setFormPrivacy(ch.privacy_level || "PUBLIC_TO_EVERYONE"); setFormPrivacy(ch.privacy_level || "PUBLIC_TO_EVERYONE");
setFormTitle(ch.title_template || "{anchor} #fyp"); setFormTitle(ch.title_template || "");
setFormDesc(ch.description_template || "{anchor}\n{url}");
setShowForm(true); setShowForm(true);
}; };
@ -581,9 +578,13 @@ export default function TikTokPage() {
<input <input
value={formTitle} value={formTitle}
onChange={(e) => setFormTitle(e.target.value)} onChange={(e) => setFormTitle(e.target.value)}
placeholder="例如 street food(原文案上传,不会带直播间名)"
className="mt-1 w-full rounded-lg border border-white/10 bg-black/40 px-3 py-2 text-sm" className="mt-1 w-full rounded-lg border border-white/10 bg-black/40 px-3 py-2 text-sm"
/> />
</label> </label>
<p className="text-[11px] text-slate-500 sm:col-span-2">
发到 TikTok 的文案就是这里写的原文,不会自动加直播间名字或链接。
</p>
</div> </div>
<div className="mt-3 flex gap-2"> <div className="mt-3 flex gap-2">
<button <button