Skip to content

fix: 修复抖音相关的 3 个核心 issue (#435 / #315 / #325) - #515

Open
zzuu080603 wants to merge 3 commits into
ihmily:mainfrom
zzuu080603:fix/douyin-core-issues
Open

zzuu080603 wants to merge 3 commits into
ihmily:mainfrom
zzuu080603:fix/douyin-core-issues

Conversation

@zzuu080603

Copy link
Copy Markdown

概述

本 PR 修复 3 个抖音相关的高关注度 issue,均为根因分析 + 修复 + 单元测试验证过的改动(26 项测试全部通过,对全平台通用,不止抖音):

1️⃣ #435 显示「录制中」但文件未保存(emoji 主播名)

根因:EMOJI_PATTERN 缺少变体选择符(U+FE0F)、零宽连接符(U+200D)、肤色修饰符等区间。主播名只含 emoji 时(如 👁️、👨‍👩‍👧‍👦),清洗后残留不可见字符进入保存路径,录制静默失败且状态卡死。
修复:补齐 emoji 区间 + 新增 INVISIBLE_CHAR_PATTERN 清除零宽/控制字符 + 名称清洗为空时回退平台原始名,保存路径永不为空。

2️⃣ #315 手机分享短链无法解析(unique_id 为空)

根因:上游 streamget 的 DouyinUtils.get_unique_id 只提取 unique_id,部分账号该字段为空、仅有 short_id(两者均可拼接直播间地址),上游直接抛 RuntimeError。
修复:在 DouyinHandler 加载时打幂等 monkey-patch,失败/空串时回退提取 short_id;UnsupportedUrlError 保持原样传播。
备注:根因在上游库,建议同步修复 streamget;此补丁作为过渡方案,streamget 结构变化时自动跳过。

3️⃣ #325 主播掉线重连后不停止录制但无数据写入

根因:录制循环只检查 should_stop/进程退出码,ffmpeg 挂在死流上时进程不死、文件零增长,状态挂数小时。
修复:新增输出目录大小停滞检测(每 15s 采样,90s 零增长或全程 0 字节判定死流,stalled_stream_timeout 可配、0 禁用),判定后优雅停止并经 recheck_live_status 用新流地址自动重启;顺带修复 stop_download 超时后不 cancel 任务导致的句柄泄漏(Windows 文件锁定)。

测试

  • ✅ 26 项单元测试通过(emoji 清洗 10 项、short_id 回退 8 项、停滞检测 8 项)
  • ✅ ruff 检查通过

Fixes #435
Fixes #315
Fixes #325

qinzihan added 3 commits November 10, 2026 08:31
…e correctly (ihmily#435)

EMOJI_PATTERN was missing variation selectors (U+FE0F), zero-width joiners
(U+200D) and skin-tone modifiers, so names made only of emoji (e.g. 👁️,
👨‍👩‍👧‍👦) left invisible characters in the save path and recording failed
silently while the card stayed 'recording'.

- extend EMOJI_PATTERN with VS16/ZWJ/keycap/skin-tone/misc-symbol ranges
- add INVISIBLE_CHAR_PATTERN to strip zero-width/control chars from names
- fall back to the platform anchor name (then the localized default) when
  a custom streamer name cleans to empty, so the path is never None
…ile links (ihmily#315)

Some Douyin profiles return an empty unique_id and only expose short_id
(both work in live.douyin.com/<id> URLs), which broke mobile-shared
profile short links. streamget's DouyinUtils.get_unique_id raises
RuntimeError in that case, so apply an idempotent monkey-patch at import
time: on failure/empty result, re-request the share page and extract
short_id. UnsupportedUrlError keeps propagating unchanged since callers
rely on it to tell room links from profile links.
When an anchor disconnects and reconnects, the old stream URL stops
delivering data while ffmpeg (or the direct-download task) keeps waiting
on it: the card stays 'recording' for hours but nothing is written.

- sample the output directory size every 15s; when it stops growing for
  stalled_stream_timeout seconds (default 90, 0 disables) or nothing was
  ever written, stop the recorder gracefully and let check_if_live
  restart it with the fresh stream URL (recheck now also runs for
  stall-triggered stops)
- DirectStreamDownloader.stop_download: cancel the task after the 10s
  grace timeout so a hung HTTP read can no longer leak the task and keep
  the output file locked on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant