From e0d4a95c0c873cfb56dbfb2a7c13750b35325463 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 15 Aug 2026 08:12:58 -0500 Subject: [PATCH] =?UTF-8?q?fix(test1):=20=E6=94=BE=E5=AE=BD=E7=9F=AD?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E6=96=87=E6=A1=88=E6=A0=A1=E9=AA=8C=EF=BC=8C?= =?UTF-8?q?=E7=9F=AD=E4=B8=BB=E6=92=AD=E5=90=8D=E8=87=AA=E5=8A=A8=E8=A1=A5?= =?UTF-8?q?=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 「小夏妹妹」等短名不再被误判正文过短;默认模板改为带「直播精彩瞬间」。 Co-authored-by: Cursor --- backend/app/db.py | 2 +- backend/app/x_clips_pipeline.py | 14 +++++++--- extensions/dylive-helper/manifest.json | 2 +- extensions/dylive-helper/package.json | 2 +- extensions/dylive-helper/src/content.ts | 36 +++++++++++++++++++------ frontend/src/app/x/ClipsPanel.tsx | 4 +-- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/backend/app/db.py b/backend/app/db.py index 5fb94f7..53c8bf7 100644 --- a/backend/app/db.py +++ b/backend/app/db.py @@ -493,7 +493,7 @@ def _seed_defaults(conn: sqlite3.Connection) -> None: "x_clips_upload_min_gap_sec": 600, "x_clips_delete_clip_after_post": True, "x_clips_daily_max": 20, - "x_clips_caption_template": "{anchor}", + "x_clips_caption_template": "{anchor} 直播精彩瞬间", "tiktok_auto_retry_failed": False, "tiktok_auto_retry_max_attempts": 3, "tiktok_auto_retry_interval_sec": 300, diff --git a/backend/app/x_clips_pipeline.py b/backend/app/x_clips_pipeline.py index 9b3d93d..9902af3 100644 --- a/backend/app/x_clips_pipeline.py +++ b/backend/app/x_clips_pipeline.py @@ -58,7 +58,7 @@ def _clip_sec(cfg: dict[str, Any], room: dict[str, Any] | None = None) -> int: def build_caption(job: dict[str, Any], cfg: dict[str, Any] | None = None) -> str: settings = cfg or db.get_settings_map() - tpl = str(settings.get("x_clips_caption_template") or "{anchor}").strip() or "{anchor}" + tpl = str(settings.get("x_clips_caption_template") or "{anchor} 直播精彩瞬间").strip() or "{anchor} 直播精彩瞬间" anchor = str(job.get("anchor_name") or "").strip() or "Live" room = str(job.get("room_id") or "").strip() text = ( @@ -66,7 +66,12 @@ def build_caption(job: dict[str, Any], cfg: dict[str, Any] | None = None) -> str .replace("{room}", room) .replace("{title}", anchor) ).strip() - # X hard limit ~280; leave headroom for media + bare = "".join(ch for ch in text if not ch.isspace()) + # Pad very short captions (短主播名会触发旧插件 length>=12 校验) + if len(bare) < 8: + suffix = "直播精彩瞬间" + if suffix not in text: + text = f"{text} {suffix}".strip() return text[:270] @@ -246,7 +251,7 @@ class XClipsPipeline: "x_clips_trigger": cfg.get("x_clips_trigger") or "tagged", "x_clips_tag": cfg.get("x_clips_tag") or "x", "x_clips_daily_max": x_clips_db.x_clips_daily_max(cfg), - "x_clips_caption_template": cfg.get("x_clips_caption_template") or "{anchor}", + "x_clips_caption_template": cfg.get("x_clips_caption_template") or "{anchor} 直播精彩瞬间", "x_clips_live_sample": bool(cfg.get("x_clips_live_sample", True)), "x_clips_live_sample_interval_sec": int(cfg.get("x_clips_live_sample_interval_sec") or 180), "x_clips_live_sample_batch": int(cfg.get("x_clips_live_sample_batch") or 1), @@ -484,6 +489,9 @@ class XClipsPipeline: jid = str(job.get("id") or "") cfg = db.get_settings_map() caption = str(job.get("caption") or "").strip() or build_caption(job, cfg) + bare = "".join(ch for ch in caption if not ch.isspace()) + if len(bare) < 8: + caption = build_caption(job, cfg) media_url = str(job.get("media_url") or "").strip() media_key = str(job.get("media_key") or "").strip() clip = str(job.get("clip_path") or "").strip() diff --git a/extensions/dylive-helper/manifest.json b/extensions/dylive-helper/manifest.json index 1e5310d..06b7dff 100644 --- a/extensions/dylive-helper/manifest.json +++ b/extensions/dylive-helper/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "dylive Helper", - "version": "2.2.1", + "version": "2.2.2", "description": "TikTok Cookie + X2 Ops(推送到 dylive /x)", "permissions": ["cookies", "storage", "tabs", "alarms", "scripting", "clipboardWrite"], "host_permissions": [ diff --git a/extensions/dylive-helper/package.json b/extensions/dylive-helper/package.json index cbaf0dd..68d3373 100644 --- a/extensions/dylive-helper/package.json +++ b/extensions/dylive-helper/package.json @@ -1,6 +1,6 @@ { "name": "dylive-helper", - "version": "2.2.1", + "version": "2.2.2", "private": true, "type": "module", "scripts": { diff --git a/extensions/dylive-helper/src/content.ts b/extensions/dylive-helper/src/content.ts index 0a59f0c..7f43a27 100644 --- a/extensions/dylive-helper/src/content.ts +++ b/extensions/dylive-helper/src/content.ts @@ -1116,6 +1116,26 @@ function captionOnly(s: string): string { .trim(); } +/** Reject empty / URL-only; allow short CJK names (旧规则 length>=12 会误杀「小夏妹妹」). */ +function isCaptionAcceptable(body: string): boolean { + const raw = String(body || "").trim(); + if (!raw) return false; + if (/^https?:\/\/\S+$/i.test(raw)) return false; + const token = captionOnly(raw); + if (!token) return false; + const cjk = (token.match(/[\u4e00-\u9fff\u3400-\u4dbf]/g) || []).join("").length; + if (cjk >= 2) return true; + return token.replace(/\s+/g, "").length >= 6; +} + +function captionMatchToken(got: string, token: string): boolean { + const t = captionOnly(token); + const g = captionOnly(got); + if (!t || !g) return false; + const needle = t.slice(0, Math.min(10, t.length)); + return g.includes(needle); +} + function looksLikePlaceholder(s: string): boolean { return /^(what('|’)s happening|what is happening|有什么新鲜事|发生什么了|有什麼新鮮事)/i.test( s.trim(), @@ -1202,7 +1222,7 @@ async function setComposerText(box: HTMLElement, text: string): Promise if (looksLikePlaceholder(got)) got = ""; let cap = captionOnly(got); const expect = captionOnly(flat).slice(0, 16); - if (expect.length >= 8 && cap.includes(expect.slice(0, 10))) return true; + if (expect.length >= 2 && cap.includes(expect.slice(0, Math.min(10, expect.length)))) return true; // Fallback once: insertText whole string (still no chunking) await clearComposer(box); @@ -1221,8 +1241,8 @@ async function setComposerText(box: HTMLElement, text: string): Promise got = composerPlain(box); if (looksLikePlaceholder(got)) got = ""; cap = captionOnly(got); - if (expect.length >= 8 && cap.includes(expect.slice(0, 10))) return true; - return cap.length >= 12; + if (expect.length >= 2 && cap.includes(expect.slice(0, Math.min(10, expect.length)))) return true; + return isCaptionAcceptable(cap); } async function ensureComposerCaption(text: string, token: string): Promise { @@ -1243,7 +1263,7 @@ async function ensureComposerCaption(text: string, token: string): Promise= 8 && got.includes(token.slice(0, 10))) { + if (ok && captionMatchToken(got, token) && isCaptionAcceptable(got)) { return live; } await sleep(300); @@ -1272,8 +1292,8 @@ async function postTweet( } const token = captionOnly(body); - if (token.length < 12) { - throw new Error("正文过短(X 规范:不能发纯链接)。已中止"); + if (!isCaptionAcceptable(body)) { + throw new Error("正文过短或仅含链接/话题(需可读正文)。已中止"); } let box = findTweetComposeBox(); @@ -1303,8 +1323,8 @@ async function postTweet( let finalCaption = captionOnly(finalRaw); if ( /^https?:\/\/\S+$/i.test(finalRaw.trim()) || - finalCaption.length < 12 || - !finalCaption.includes(token.slice(0, 10)) + !isCaptionAcceptable(finalRaw) || + !captionMatchToken(finalCaption, token) ) { throw new Error( `发送前校验失败:正文丢失(「${finalRaw.slice(0, 40)}」)。不会发出纯链接`, diff --git a/frontend/src/app/x/ClipsPanel.tsx b/frontend/src/app/x/ClipsPanel.tsx index 8e45346..2ca4a3a 100644 --- a/frontend/src/app/x/ClipsPanel.tsx +++ b/frontend/src/app/x/ClipsPanel.tsx @@ -81,7 +81,7 @@ export function ClipsPanel({ toast }: { toast: (msg: string, kind?: "ok" | "err" const s = status?.settings || {}; setClipSec(Number(s.x_clips_clip_sec || status?.clip_sec || 12)); setDailyMax(Number(s.x_clips_daily_max || status?.daily_max || 20)); - setCaptionTpl(String(s.x_clips_caption_template || "{anchor}")); + setCaptionTpl(String(s.x_clips_caption_template || "{anchor} 直播精彩瞬间")); setTrigger(String(s.x_clips_trigger || "tagged")); setSampleAny(Boolean(s.x_clips_sample_any_live ?? true)); setAutoPost(Boolean(s.x_clips_auto_post ?? true)); @@ -191,7 +191,7 @@ export function ClipsPanel({ toast }: { toast: (msg: string, kind?: "ok" | "err"