streamprobe 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of streamprobe might be problematic. Click here for more details.
- streamprobe-0.3.0/.gitignore +36 -0
- streamprobe-0.3.0/LICENSE +21 -0
- streamprobe-0.3.0/PKG-INFO +364 -0
- streamprobe-0.3.0/README.md +334 -0
- streamprobe-0.3.0/docs/findings.md +91 -0
- streamprobe-0.3.0/docs/report-schema.md +240 -0
- streamprobe-0.3.0/pyproject.toml +92 -0
- streamprobe-0.3.0/src/streamprobe/__init__.py +5 -0
- streamprobe-0.3.0/src/streamprobe/__main__.py +4 -0
- streamprobe-0.3.0/src/streamprobe/analyze.py +459 -0
- streamprobe-0.3.0/src/streamprobe/bilibili.py +392 -0
- streamprobe-0.3.0/src/streamprobe/capture.py +198 -0
- streamprobe-0.3.0/src/streamprobe/cli.py +772 -0
- streamprobe-0.3.0/src/streamprobe/config.py +204 -0
- streamprobe-0.3.0/src/streamprobe/configfile.py +281 -0
- streamprobe-0.3.0/src/streamprobe/cookies.py +71 -0
- streamprobe-0.3.0/src/streamprobe/data/health.toml +54 -0
- streamprobe-0.3.0/src/streamprobe/data/platforms.json +109 -0
- streamprobe-0.3.0/src/streamprobe/engine.py +271 -0
- streamprobe-0.3.0/src/streamprobe/errors.py +62 -0
- streamprobe-0.3.0/src/streamprobe/manifest.py +127 -0
- streamprobe-0.3.0/src/streamprobe/masking.py +46 -0
- streamprobe-0.3.0/src/streamprobe/media.py +149 -0
- streamprobe-0.3.0/src/streamprobe/metrics.py +208 -0
- streamprobe-0.3.0/src/streamprobe/normalize.py +153 -0
- streamprobe-0.3.0/src/streamprobe/parsers.py +359 -0
- streamprobe-0.3.0/src/streamprobe/paths.py +34 -0
- streamprobe-0.3.0/src/streamprobe/platforms.py +57 -0
- streamprobe-0.3.0/src/streamprobe/py.typed +0 -0
- streamprobe-0.3.0/src/streamprobe/report.py +274 -0
- streamprobe-0.3.0/src/streamprobe/resolver.py +323 -0
- streamprobe-0.3.0/src/streamprobe/resources.py +14 -0
- streamprobe-0.3.0/src/streamprobe/sample.py +313 -0
- streamprobe-0.3.0/src/streamprobe/scoring.py +487 -0
- streamprobe-0.3.0/src/streamprobe/server/__init__.py +1 -0
- streamprobe-0.3.0/src/streamprobe/server/api.py +346 -0
- streamprobe-0.3.0/src/streamprobe/server/config.py +251 -0
- streamprobe-0.3.0/src/streamprobe/server/main.py +71 -0
- streamprobe-0.3.0/src/streamprobe/server/manifest.py +365 -0
- streamprobe-0.3.0/src/streamprobe/server/middleware.py +106 -0
- streamprobe-0.3.0/src/streamprobe/server/models.py +15 -0
- streamprobe-0.3.0/src/streamprobe/server/pipeline.py +347 -0
- streamprobe-0.3.0/src/streamprobe/server/queue.py +488 -0
- streamprobe-0.3.0/src/streamprobe/server/static.py +107 -0
- streamprobe-0.3.0/src/streamprobe/server/store.py +353 -0
- streamprobe-0.3.0/src/streamprobe/server/supervisor.py +291 -0
- streamprobe-0.3.0/src/streamprobe/server/uploads.py +89 -0
- streamprobe-0.3.0/src/streamprobe/server/worker.py +148 -0
- streamprobe-0.3.0/src/streamprobe/storage.py +47 -0
- streamprobe-0.3.0/src/streamprobe/tools.py +152 -0
- streamprobe-0.3.0/src/streamprobe/upload.py +272 -0
- streamprobe-0.3.0/src/streamprobe/version.py +1 -0
- streamprobe-0.3.0/tests/test_allowlist.py +88 -0
- streamprobe-0.3.0/tests/test_bilibili.py +357 -0
- streamprobe-0.3.0/tests/test_cli.py +429 -0
- streamprobe-0.3.0/tests/test_config.py +129 -0
- streamprobe-0.3.0/tests/test_configfile.py +254 -0
- streamprobe-0.3.0/tests/test_cookies.py +48 -0
- streamprobe-0.3.0/tests/test_engine.py +216 -0
- streamprobe-0.3.0/tests/test_metrics.py +55 -0
- streamprobe-0.3.0/tests/test_normalize.py +101 -0
- streamprobe-0.3.0/tests/test_parsers.py +122 -0
- streamprobe-0.3.0/tests/test_report.py +152 -0
- streamprobe-0.3.0/tests/test_resolver.py +148 -0
- streamprobe-0.3.0/tests/test_sample.py +185 -0
- streamprobe-0.3.0/tests/test_scoring.py +208 -0
- streamprobe-0.3.0/tests/test_server_api.py +356 -0
- streamprobe-0.3.0/tests/test_server_e2e.py +132 -0
- streamprobe-0.3.0/tests/test_server_manifest.py +179 -0
- streamprobe-0.3.0/tests/test_server_store.py +216 -0
- streamprobe-0.3.0/tests/test_storage.py +22 -0
- streamprobe-0.3.0/tests/test_tools.py +155 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Environment and local data
|
|
2
|
+
.env
|
|
3
|
+
.env.*
|
|
4
|
+
!.env.example
|
|
5
|
+
/data/
|
|
6
|
+
/streamprobe-reports/
|
|
7
|
+
/.streamprobe/
|
|
8
|
+
# Leftover runtime data from the retired hosted server
|
|
9
|
+
/api/data/
|
|
10
|
+
|
|
11
|
+
# Python
|
|
12
|
+
.venv/
|
|
13
|
+
__pycache__/
|
|
14
|
+
*.py[cod]
|
|
15
|
+
*.egg-info/
|
|
16
|
+
dist/
|
|
17
|
+
build/
|
|
18
|
+
.mypy_cache/
|
|
19
|
+
.pytest_cache/
|
|
20
|
+
.ruff_cache/
|
|
21
|
+
|
|
22
|
+
# Node / Nuxt
|
|
23
|
+
web/node_modules/
|
|
24
|
+
web/.nuxt/
|
|
25
|
+
web/.output/
|
|
26
|
+
web/.data/
|
|
27
|
+
web/dist
|
|
28
|
+
web/.eslintcache
|
|
29
|
+
web/app/types/api.d.ts
|
|
30
|
+
|
|
31
|
+
# Editors and OS
|
|
32
|
+
.DS_Store
|
|
33
|
+
.idea/
|
|
34
|
+
.vscode/
|
|
35
|
+
*.swp
|
|
36
|
+
*.log
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dup4
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: streamprobe
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Capture live streams locally, analyse them on a StreamProbe server
|
|
5
|
+
Author: Dup4
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: diagnostics,ffmpeg,hls,live-stream,streamlink
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Multimedia :: Video
|
|
17
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: click<9,>=8.1
|
|
20
|
+
Requires-Dist: httpx<1,>=0.28
|
|
21
|
+
Requires-Dist: portable-ffmpeg==0.5.0
|
|
22
|
+
Requires-Dist: streamlink==8.6.3
|
|
23
|
+
Provides-Extra: offline
|
|
24
|
+
Requires-Dist: portable-ffmpeg-full==0.5.0; extra == 'offline'
|
|
25
|
+
Provides-Extra: server
|
|
26
|
+
Requires-Dist: fastapi<1,>=0.115; extra == 'server'
|
|
27
|
+
Requires-Dist: python-multipart<1,>=0.0.20; extra == 'server'
|
|
28
|
+
Requires-Dist: uvicorn<1,>=0.34; extra == 'server'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# StreamProbe
|
|
32
|
+
|
|
33
|
+
**在观众察觉之前,先看清流的健康状态。**
|
|
34
|
+
|
|
35
|
+
StreamProbe 由两部分组成:
|
|
36
|
+
|
|
37
|
+
- **CLI**:在本地解析直播地址、抓取 10–60 秒原始流与传输遥测,然后上传到 StreamProbe 服务端。
|
|
38
|
+
- **服务端**:负责标准化、ffprobe/ffmpeg 分析、波形/频谱/截帧、可播放样本、评分,并托管可分享的报告。
|
|
39
|
+
|
|
40
|
+
也可以在网页首页直接上传已有的抓取文件;浏览器上传只做媒体分析,没有网络传输遥测。
|
|
41
|
+
|
|
42
|
+
检测维度包括:视频码率曲线、分辨率与帧率、GOP、冻结/黑屏/亮度、音频响度(LUFS)、true peak、静音/削波、声道平衡、CLI 抓取的卡顿/TTFB/吞吐、音画起始偏移与时间戳跳变。
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
需要 Python 3.11+。
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 推荐:uv
|
|
50
|
+
uv tool install streamprobe
|
|
51
|
+
|
|
52
|
+
# 或者 pipx / pip
|
|
53
|
+
pipx install streamprobe
|
|
54
|
+
pip install streamprobe
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
ffmpeg 与 ffprobe 默认由 [portable-ffmpeg](https://pypi.org/project/portable-ffmpeg/) 在首次抓取时下载并做 SHA-256 校验,缓存在 `~/.streamprobe/cache/ffmpeg`。也可以使用系统安装的 ffmpeg:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# macOS
|
|
61
|
+
brew install ffmpeg
|
|
62
|
+
# Debian / Ubuntu
|
|
63
|
+
sudo apt install ffmpeg
|
|
64
|
+
# 然后跳过自动下载
|
|
65
|
+
streamprobe doctor --no-download
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 配置
|
|
69
|
+
|
|
70
|
+
默认服务端是 `https://streamprobe.dup4.com`。上传需要共享 API token,token 只用于 `Authorization: Bearer`,不会出现在 URL 或日志中。
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# 可选:换成自建服务端
|
|
74
|
+
streamprobe config set server.url https://streamprobe.example.com
|
|
75
|
+
|
|
76
|
+
# 不传 VALUE 时会隐藏输入
|
|
77
|
+
streamprobe config set server.token
|
|
78
|
+
|
|
79
|
+
# 检查配置、token、服务端连通性与本地工具
|
|
80
|
+
streamprobe doctor
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
配置保存在 `~/.streamprobe/config.json`(`0600`,父目录 `0700`):
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"version": 2,
|
|
88
|
+
"server": {
|
|
89
|
+
"url": "https://streamprobe.dup4.com",
|
|
90
|
+
"token": "..."
|
|
91
|
+
},
|
|
92
|
+
"probe": {
|
|
93
|
+
"defaultDuration": 30,
|
|
94
|
+
"defaultQuality": null
|
|
95
|
+
},
|
|
96
|
+
"bilibili": {
|
|
97
|
+
"cookie": "SESSDATA=...; bili_jct=..."
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- `streamprobe config show` 只显示 token 是否已配置,不打印值。
|
|
103
|
+
- `server.token` / `bilibili.cookie` 也支持 `STREAMPROBE_API_TOKEN` / `STREAMPROBE_BILIBILI_COOKIE` 环境变量,环境变量优先。
|
|
104
|
+
- Bilibili Cookie 只注入 `.bilibili.com` 的 Streamlink 请求,**绝不上传、不写报告、不进日志**。
|
|
105
|
+
- 生产环境也可以通过 `--token-file` 从权限受限的文件读取 token,避免出现在 shell 历史里。
|
|
106
|
+
|
|
107
|
+
## 快速开始
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 抓取、上传、等待分析并打开报告
|
|
111
|
+
streamprobe "https://www.twitch.tv/example"
|
|
112
|
+
|
|
113
|
+
# 等价写法,指定抓取时长与画质
|
|
114
|
+
streamprobe probe "https://live.bilibili.com/12345" --duration 60 --quality 1080p-avc
|
|
115
|
+
|
|
116
|
+
# 只上传,不等待;打印报告 URL
|
|
117
|
+
streamprobe probe "<url>" --no-wait
|
|
118
|
+
|
|
119
|
+
# 上传已有抓取文件(没有网络遥测)
|
|
120
|
+
streamprobe upload capture.ts --title "Opening night" --platform youtube
|
|
121
|
+
|
|
122
|
+
# JSON 输出(不包含 manageToken)
|
|
123
|
+
streamprobe probe "<url>" --json
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`streamprobe <url>` 是 `streamprobe probe <url>` 的简写。
|
|
127
|
+
|
|
128
|
+
### 退出码
|
|
129
|
+
|
|
130
|
+
| 退出码 | 含义 |
|
|
131
|
+
|---|---|
|
|
132
|
+
| `0` | 上传成功;等待模式下分析也完成(结论可以是 degraded / unhealthy) |
|
|
133
|
+
| `1` | 服务端已生成失败报告(离线、鉴权失败、无法解码等) |
|
|
134
|
+
| `2` | 用法、配置、网络或上传鉴权错误 |
|
|
135
|
+
| `130` | 用户按 Ctrl-C 中断;等待阶段会尝试取消服务端任务 |
|
|
136
|
+
|
|
137
|
+
### `streamprobe probe`
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
streamprobe probe URL [OPTIONS]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
| 选项 | 说明 |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `-d, --duration N` | 抓取秒数,默认来自配置(30);上限 `STREAMPROBE_MAX_DURATION`(默认 60) |
|
|
146
|
+
| `-q, --quality NAME` | Streamlink 画质名,如 `best`、`720p`;Bilibili 形如 `1080p-avc` |
|
|
147
|
+
| `--server URL` | 覆盖服务端地址 |
|
|
148
|
+
| `--token-file FILE` | 从文件读取 API token |
|
|
149
|
+
| `--wait / --no-wait` | 是否等待分析完成;默认等待 |
|
|
150
|
+
| `--timeout N` | 等待超时秒数,默认 `900` |
|
|
151
|
+
| `--json` | 将结果 JSON 写到 stdout,进度仍走 stderr |
|
|
152
|
+
| `--keep-raw` | 将原始抓取保留到 `~/.streamprobe/raw/<id>/` |
|
|
153
|
+
| `--open / --no-open` | 是否打开浏览器;默认打开 |
|
|
154
|
+
| `--ffmpeg PATH` / `--ffprobe PATH` | 显式指定本地工具路径 |
|
|
155
|
+
| `--no-download` | 不使用 managed ffmpeg 下载,仅用显式路径或 `PATH` |
|
|
156
|
+
| `--allow-http` | 允许 localhost 明文 HTTP(仅开发) |
|
|
157
|
+
| `--allow-private-hosts` | 允许探测环回/内网地址(仅测试) |
|
|
158
|
+
| `--allow-fake-ip` | 允许 Clash/Surge fake-IP 的 `198.18.0.0/15` |
|
|
159
|
+
|
|
160
|
+
### `streamprobe upload`
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
streamprobe upload FILE [OPTIONS]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
上传已有抓取文件,使用 analysis-only manifest:`probe.origin="cli"`、`probe.telemetry="none"`,传输指标不参与评分。支持 `--server`、`--token-file`、`--wait/--no-wait`、`--timeout`、`--json`、`--open/--no-open`、`--allow-http`,以及可选的 `--title`、`--author`、`--platform`、`--source-url`。
|
|
167
|
+
|
|
168
|
+
### `streamprobe config`
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
streamprobe config show
|
|
172
|
+
streamprobe config set {server.url|server.token|probe.defaultDuration|probe.defaultQuality|bilibili.cookie} [VALUE]
|
|
173
|
+
streamprobe config unset {server.url|server.token|probe.defaultDuration|probe.defaultQuality|bilibili.cookie}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`server.token` 与 `bilibili.cookie` 在 `set` 时不传值会隐藏输入;`show` 不会打印 secret 原文。
|
|
177
|
+
|
|
178
|
+
### `streamprobe doctor`
|
|
179
|
+
|
|
180
|
+
```text
|
|
181
|
+
streamprobe doctor [--json] [--no-download] [--clear-cache] [--allow-http]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
打印配置状态、服务端版本/鉴权、ffmpeg / ffprobe 来源与版本、Bilibili session 是否配置;不打印 token 或 cookie。缺配置、token、工具或服务端不可达时退出 `1`。
|
|
185
|
+
|
|
186
|
+
## 报告
|
|
187
|
+
|
|
188
|
+
报告链接形如 `https://streamprobe.dup4.com/p/<id>`,ID 为 128-bit 随机串,查看公开但不可猜。报告默认保留 `STREAMPROBE_TTL_DAYS=7` 天,到期自动删除。
|
|
189
|
+
|
|
190
|
+
- CLI 创建报告时会得到该报告专用的 `manageToken`,用于取消运行中的任务或删除报告。`--open` 会把 token 放在 URL fragment(`#token=...`)里,前端读取后立即从地址栏清除,只保存在本机浏览器。
|
|
191
|
+
- 网页上传会在同一个标签页保存 token,因此删除按钮可用。
|
|
192
|
+
- 报告页、图表与媒体样本通过同一域名提供;`/api/probes/{id}/report.json` 可下载完整 JSON。
|
|
193
|
+
- 浏览器上传没有实时网络采集,报告会标记 `probe.origin="browser"`、`probe.telemetry="none"`、`delivery.measured=false`,传输相关指标显示“未测量”,也不参与评分。
|
|
194
|
+
|
|
195
|
+
报告 schema 见 [docs/report-schema.md](docs/report-schema.md),finding code 与建议见 [docs/findings.md](docs/findings.md)。
|
|
196
|
+
|
|
197
|
+
## 支持的平台
|
|
198
|
+
|
|
199
|
+
平台列表在 `src/streamprobe/data/platforms.json`,CLI 的 URL 校验使用这份数据:
|
|
200
|
+
|
|
201
|
+
Twitch、YouTube Live、Bilibili Live、斗鱼、虎牙、抖音直播、TikTok Live、Kick、CHZZK、SOOP、Facebook Live、Vimeo、niconico、DLive、TwitCasting。
|
|
202
|
+
|
|
203
|
+
URL 必须使用 `https://`,且 host 必须属于上述平台(或通过 `STREAMPROBE_ALLOWED_HOSTS` 额外放行)。私有、环回、链路本地地址默认被 SSRF 校验拒绝;Clash/Surge fake-IP 可加 `--allow-fake-ip`。
|
|
204
|
+
|
|
205
|
+
匿名 Bilibili 请求通常最高只能拿到 720P H.264;登录态下可能拿到 1080P H.264。Bilibili 的画质 ID 形如 `1080p-av1`、`720p-avc`。AV1 无法装入 MPEG-TS,服务端会自动改用 NUT 容器(`probe.analyzedAs=nut`)。
|
|
206
|
+
|
|
207
|
+
## 本地状态
|
|
208
|
+
|
|
209
|
+
```text
|
|
210
|
+
~/.streamprobe/
|
|
211
|
+
config.json # server/probe/bilibili 配置,权限 0600
|
|
212
|
+
cache/ffmpeg/ # managed ffmpeg/ffprobe
|
|
213
|
+
tmp/capture-*/ # 抓取中的临时目录;上传成功后删除
|
|
214
|
+
raw/<id>/capture.bin # 仅 --keep-raw
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
上传失败时会保留临时抓取并打印路径,方便用 `streamprobe upload <file>` 重试。成功且未指定 `--keep-raw` 时会删除临时目录。
|
|
218
|
+
|
|
219
|
+
## 环境变量
|
|
220
|
+
|
|
221
|
+
CLI 相关变量均以 `STREAMPROBE_` 为前缀,优先级高于 `config.json`:
|
|
222
|
+
|
|
223
|
+
| 变量 | 默认值 | 说明 |
|
|
224
|
+
|---|---|---|
|
|
225
|
+
| `STREAMPROBE_HOME` | `~/.streamprobe` | 配置、缓存与临时文件根目录 |
|
|
226
|
+
| `STREAMPROBE_SERVER_URL` | `https://streamprobe.dup4.com` | 服务端地址 |
|
|
227
|
+
| `STREAMPROBE_API_TOKEN` | 空 | 共享上传 token |
|
|
228
|
+
| `STREAMPROBE_DEFAULT_DURATION` | `30` | 默认抓取秒数 |
|
|
229
|
+
| `STREAMPROBE_DEFAULT_QUALITY` | 空 | 默认画质,空表示 `best` |
|
|
230
|
+
| `STREAMPROBE_MAX_DURATION` | `60` | `--duration` 上限 |
|
|
231
|
+
| `STREAMPROBE_MAX_BYTES` | `250MB` | 单次抓取字节上限 |
|
|
232
|
+
| `STREAMPROBE_ALLOWED_HOSTS` | 空 | 额外允许的域名,逗号分隔 |
|
|
233
|
+
| `STREAMPROBE_ALLOW_PRIVATE_HOSTS` | `false` | 允许环回/内网地址 |
|
|
234
|
+
| `STREAMPROBE_ALLOW_FAKE_IP` | `false` | 允许 fake-IP 地址 |
|
|
235
|
+
| `STREAMPROBE_FFMPEG` / `STREAMPROBE_FFPROBE` | 空 | 工具路径 |
|
|
236
|
+
| `STREAMPROBE_BILIBILI_COOKIE` | 空 | Bilibili `Cookie` 请求头 |
|
|
237
|
+
| `STREAMPROBE_PLATFORMS` | 包内数据 | 自定义平台列表路径 |
|
|
238
|
+
|
|
239
|
+
## 自建服务端
|
|
240
|
+
|
|
241
|
+
服务端需要 `fastapi`、`uvicorn` 与 `python-multipart`:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
pip install "streamprobe[server]"
|
|
245
|
+
export STREAMPROBE_ENV=production
|
|
246
|
+
export STREAMPROBE_API_TOKEN_FILE=/path/to/api-token # 至少 32 字符
|
|
247
|
+
export STREAMPROBE_PUBLIC_BASE_URL=https://streamprobe.example.com
|
|
248
|
+
export STREAMPROBE_WEB_DIR=/path/to/web # Nuxt generate 的产物
|
|
249
|
+
export STREAMPROBE_DATA_DIR=/var/lib/streamprobe
|
|
250
|
+
uvicorn streamprobe.server.main:create_app --factory --host 0.0.0.0 --port 8000 --workers 1 --proxy-headers
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
服务端主要环境变量:
|
|
254
|
+
|
|
255
|
+
| 变量 | 默认值 | 说明 |
|
|
256
|
+
|---|---|---|
|
|
257
|
+
| `STREAMPROBE_ENV` | `development` | `production` 时强制 HTTPS、token 长度与 web dir |
|
|
258
|
+
| `STREAMPROBE_DATA_DIR` | `/data` | 报告、暂存与临时文件 |
|
|
259
|
+
| `STREAMPROBE_PUBLIC_BASE_URL` | `http://127.0.0.1:8000` | 报告中使用的公开地址 |
|
|
260
|
+
| `STREAMPROBE_API_TOKEN` / `STREAMPROBE_API_TOKEN_FILE` | 空 | 共享上传 token;生产建议用文件 |
|
|
261
|
+
| `STREAMPROBE_WEB_DIR` | 空 | 构建好的 Nuxt UI(`web/.output/public`) |
|
|
262
|
+
| `STREAMPROBE_TTL_DAYS` | `7` | 报告保留天数 |
|
|
263
|
+
| `STREAMPROBE_CONCURRENCY` | `2` | 并发分析数 |
|
|
264
|
+
| `STREAMPROBE_QUEUE_SIZE` | `8` | 等待队列长度 |
|
|
265
|
+
| `STREAMPROBE_RATE_LIMIT` | `12/600` | 每个 IP 的窗口内上传次数 |
|
|
266
|
+
| `STREAMPROBE_MAX_UPLOAD_BYTES` | `300MB` | 单次 multipart 上限 |
|
|
267
|
+
| `STREAMPROBE_MAX_MANIFEST_BYTES` | `64KiB` | manifest 文本上限 |
|
|
268
|
+
| `STREAMPROBE_MIN_FREE_BYTES` | `2GB` | 低于此值拒绝上传 |
|
|
269
|
+
| `STREAMPROBE_MAX_DURATION` | `60` | 最长分析窗口 |
|
|
270
|
+
| `STREAMPROBE_ANALYSIS_TIMEOUT_SEC` | `480` | 单任务超时 |
|
|
271
|
+
| `STREAMPROBE_QUEUE_WAIT_TIMEOUT_SEC` | `60` | 排队超时 |
|
|
272
|
+
| `STREAMPROBE_TARGET_LUFS` | `-14` | 响度评分目标 |
|
|
273
|
+
| `STREAMPROBE_MEDIA_MAX_BYTES` | `50MB` | 可播放样本大小上限 |
|
|
274
|
+
| `STREAMPROBE_MEDIA_MAX_HEIGHT` | `720` | 转码样本最高分辨率 |
|
|
275
|
+
| `STREAMPROBE_MEDIA_TIMEOUT_SEC` | `180` | 样本生成超时 |
|
|
276
|
+
| `STREAMPROBE_CAPTURE_DATA_GRACE_SEC` | `5` | 允许抓取时长超出窗口的宽限 |
|
|
277
|
+
| `STREAMPROBE_FFMPEG` / `STREAMPROBE_FFPROBE` | `ffmpeg` / `ffprobe` | 服务端工具路径 |
|
|
278
|
+
| `STREAMPROBE_PLATFORMS` / `STREAMPROBE_HEALTH_CONFIG` | 包内数据 | 平台列表 / 评分配置路径 |
|
|
279
|
+
| `STREAMPROBE_TRUST_PROXY` | `false` | 信任 `X-Forwarded-For` |
|
|
280
|
+
| `STREAMPROBE_TRUSTED_HOSTS` | 空 | `Host` 白名单,逗号分隔 |
|
|
281
|
+
| `STREAMPROBE_KEEP_SAMPLE` | `false` | 保留上传的原始抓取 |
|
|
282
|
+
|
|
283
|
+
Docker:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
docker build -t streamprobe:dev .
|
|
287
|
+
docker run --rm -p 8000:8000 \
|
|
288
|
+
-e STREAMPROBE_ENV=development \
|
|
289
|
+
-e STREAMPROBE_API_TOKEN=dev-token \
|
|
290
|
+
-e STREAMPROBE_PUBLIC_BASE_URL=http://127.0.0.1:8000 \
|
|
291
|
+
-v streamprobe-data:/data \
|
|
292
|
+
streamprobe:dev
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
或使用 `docker-compose.yml`(需要设置 `STREAMPROBE_API_TOKEN`)。镜像内同时包含 FastAPI、构建好的 UI 与系统 ffmpeg,以非 root uid `10001` 运行。
|
|
296
|
+
|
|
297
|
+
服务端不会访问客户端提供的任何 URL;所有上传都被视为不可信媒体。ffmpeg/ffprobe 输入固定带 `-protocol_whitelist file,pipe`,容器非 root、`cap_drop: ALL`、有超时与资源限制。
|
|
298
|
+
|
|
299
|
+
## 安全与隐私
|
|
300
|
+
|
|
301
|
+
- 共享 token 只用于上传与鉴权;常量时间比较,不写日志,不放进 URL。网页只把 token 存在当前标签页的 `sessionStorage`。
|
|
302
|
+
- Bilibili session 只存在于 CLI 的 `~/.streamprobe/config.json`(`0600`);manifest、报告、服务端、worker 环境与日志都不包含它。
|
|
303
|
+
- 上传的原始抓取在分析后删除;报告与可播放样本按 TTL 保留。`report.json` 中的 URL 只保留 scheme/host/path,失败消息经过脱敏。
|
|
304
|
+
- 报告 ID 不可猜,但查看是公开的;拿到链接的人可以看到报告与媒体样本。不要上传无权公开的内容。
|
|
305
|
+
- 报告页带 `noindex` / `no-referrer`,报告链接默认 7 天后失效。
|
|
306
|
+
- 请只探测你有权访问的流;本项目不绕过登录、订阅或 DRM。配置自己的登录态不等于获得绕过权限。
|
|
307
|
+
|
|
308
|
+
## 开发
|
|
309
|
+
|
|
310
|
+
前置:Python 3.11+、[uv](https://docs.astral.sh/uv/)、Node.js(见 `.nvmrc`)、pnpm。
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
make install # uv sync --extra server + pnpm install
|
|
314
|
+
make web-assets # 构建 UI 到 web/.output/public
|
|
315
|
+
make lint # ruff + eslint
|
|
316
|
+
make typecheck # mypy + nuxt typecheck
|
|
317
|
+
make test # pytest(不含 e2e)+ vitest
|
|
318
|
+
make test-e2e # 需要本机 ffmpeg
|
|
319
|
+
make check # lint + typecheck + test
|
|
320
|
+
make package # 构建 wheel/sdist 并校验布局
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
仓库结构:
|
|
324
|
+
|
|
325
|
+
```text
|
|
326
|
+
src/streamprobe/ Python 包:CLI、抓取、上传、manifest、分析与报告
|
|
327
|
+
server/ 托管服务:FastAPI、队列、worker、存储、上传
|
|
328
|
+
data/ 平台列表与 health.toml
|
|
329
|
+
tests/ pytest(含 e2e)
|
|
330
|
+
web/ Nuxt 4 报告 UI(SSG,由 Docker 镜像提供)
|
|
331
|
+
docs/ finding code 与报告 schema
|
|
332
|
+
Dockerfile 单镜像:FastAPI + UI + ffmpeg
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
本地跑服务端:
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
uv run uvicorn streamprobe.server.main:create_app --factory --port 8000
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
默认 `development` 模式不要求 token、不要求 HTTPS;需要 UI 时先 `make web-assets`,并设置 `STREAMPROBE_WEB_DIR=web/.output/public`。
|
|
342
|
+
|
|
343
|
+
## 发布
|
|
344
|
+
|
|
345
|
+
版本号唯一来源是 `src/streamprobe/version.py`,同步更新 `web/package.json` 后打 `vX.Y.Z` tag。Release workflow 会:
|
|
346
|
+
|
|
347
|
+
1. 校验 tag 与版本一致,构建并校验 wheel/sdist;
|
|
348
|
+
2. 通过 PyPI trusted publishing 发布 CLI;
|
|
349
|
+
3. 构建 `linux/amd64` Docker 镜像并推送到 `registry.cn-shanghai.aliyuncs.com/dup4/streamprobe:<tag>`。
|
|
350
|
+
|
|
351
|
+
PyPI 需要 trusted publisher:仓库 `Dup4/streamprobe`、workflow `release.yml`、environment `pypi`。ACR 推送需要 secrets `ALIYUN_REGISTRY_USERNAME` / `ALIYUN_REGISTRY_TOKEN`。部署由 homelab Ansible 的 `streamprobe` role 完成。
|
|
352
|
+
|
|
353
|
+
## 限制
|
|
354
|
+
|
|
355
|
+
- 样本窗口不代表整场直播;广告、转场、静帧、黑场与节目静音都可能触发提示。
|
|
356
|
+
- 浏览器上传没有网络遥测,传输指标明确显示“未测量”,不能被解读为“通过”。
|
|
357
|
+
- 容器 PTS 偏移不等于真实唇音同步误差。
|
|
358
|
+
- 服务端为单实例内存队列(`workers=1`),不支持水平扩容。
|
|
359
|
+
- 主要在 macOS / Linux 验证;Windows 可运行 CLI,但未纳入 CI。
|
|
360
|
+
- 需要登录、地区限制或 DRM 的流会在解析阶段给出明确错误。
|
|
361
|
+
|
|
362
|
+
## 许可证
|
|
363
|
+
|
|
364
|
+
[MIT](LICENSE)
|