streamget
streamget copied to clipboard
斗鱼签名 tt 使用本机时间,系统时钟有偏差的机器上取流必失败(error=-9 时间戳错误)
问题
streamget/platforms/douyu/live_stream.py L149 用 ts = int(time.time())(本机时钟)生成 getH5PlayV1 签名里的 tt。斗鱼服务端用自身时间校验 tt 且容差很小,系统时钟有偏差的机器(无 RTC 的录制盒、Docker 容器等场景常见)上每次请求都会被拒:
{"error": -9, "msg": "时间戳错误"}
复现(A/B 验证)
本机时钟快约 14 分钟(与 Cloudflare/百度/斗鱼 Date 响应头三方对比确认)的 Linux 机器上,同一秒、同一份 enc_data:
tt= 本机时间 →error=-9 时间戳错误tt= getEncryption 响应头Date解析出的服务器时间 →error=0,正常拿到流地址
签名算法本身(rand_str / enc_time / key / is_special 的处理)是正确的,纯粹是时间源问题。
建议
tt 改用 getEncryption 响应头 Date 解析出的服务器时间(email.utils.parsedate_to_datetime 一行可解),本机时间仅作回退。无需额外请求,对时钟偏差免疫。
环境
- streamget main(2026-08-01)
- Linux 5.15 x64(Docker 容器,无 RTC,时钟 +815s)
容器的时间和宿主机是完全一致的,不应该考虑下宿主机的ntp服务运作是否正常吗?