streamprobe 0.3.1__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.
Files changed (59) hide show
  1. streamprobe-0.3.1/.gitignore +36 -0
  2. streamprobe-0.3.1/LICENSE +21 -0
  3. streamprobe-0.3.1/PKG-INFO +215 -0
  4. streamprobe-0.3.1/README.md +337 -0
  5. streamprobe-0.3.1/docs/findings.md +91 -0
  6. streamprobe-0.3.1/docs/pypi-readme.md +189 -0
  7. streamprobe-0.3.1/docs/report-schema.md +240 -0
  8. streamprobe-0.3.1/pyproject.toml +96 -0
  9. streamprobe-0.3.1/src/streamprobe/__init__.py +5 -0
  10. streamprobe-0.3.1/src/streamprobe/__main__.py +4 -0
  11. streamprobe-0.3.1/src/streamprobe/analyze.py +459 -0
  12. streamprobe-0.3.1/src/streamprobe/bilibili.py +392 -0
  13. streamprobe-0.3.1/src/streamprobe/capture.py +198 -0
  14. streamprobe-0.3.1/src/streamprobe/cli.py +760 -0
  15. streamprobe-0.3.1/src/streamprobe/config.py +202 -0
  16. streamprobe-0.3.1/src/streamprobe/configfile.py +281 -0
  17. streamprobe-0.3.1/src/streamprobe/cookies.py +71 -0
  18. streamprobe-0.3.1/src/streamprobe/data/health.toml +54 -0
  19. streamprobe-0.3.1/src/streamprobe/data/platforms.json +109 -0
  20. streamprobe-0.3.1/src/streamprobe/engine.py +271 -0
  21. streamprobe-0.3.1/src/streamprobe/errors.py +62 -0
  22. streamprobe-0.3.1/src/streamprobe/manifest.py +127 -0
  23. streamprobe-0.3.1/src/streamprobe/masking.py +46 -0
  24. streamprobe-0.3.1/src/streamprobe/media.py +149 -0
  25. streamprobe-0.3.1/src/streamprobe/metrics.py +208 -0
  26. streamprobe-0.3.1/src/streamprobe/normalize.py +153 -0
  27. streamprobe-0.3.1/src/streamprobe/parsers.py +359 -0
  28. streamprobe-0.3.1/src/streamprobe/paths.py +34 -0
  29. streamprobe-0.3.1/src/streamprobe/platforms.py +57 -0
  30. streamprobe-0.3.1/src/streamprobe/py.typed +0 -0
  31. streamprobe-0.3.1/src/streamprobe/report.py +274 -0
  32. streamprobe-0.3.1/src/streamprobe/resolver.py +323 -0
  33. streamprobe-0.3.1/src/streamprobe/resources.py +14 -0
  34. streamprobe-0.3.1/src/streamprobe/sample.py +313 -0
  35. streamprobe-0.3.1/src/streamprobe/scoring.py +487 -0
  36. streamprobe-0.3.1/src/streamprobe/storage.py +47 -0
  37. streamprobe-0.3.1/src/streamprobe/tools.py +142 -0
  38. streamprobe-0.3.1/src/streamprobe/upload.py +272 -0
  39. streamprobe-0.3.1/src/streamprobe/version.py +1 -0
  40. streamprobe-0.3.1/tests/test_allowlist.py +88 -0
  41. streamprobe-0.3.1/tests/test_bilibili.py +357 -0
  42. streamprobe-0.3.1/tests/test_cli.py +426 -0
  43. streamprobe-0.3.1/tests/test_config.py +129 -0
  44. streamprobe-0.3.1/tests/test_configfile.py +254 -0
  45. streamprobe-0.3.1/tests/test_cookies.py +48 -0
  46. streamprobe-0.3.1/tests/test_engine.py +216 -0
  47. streamprobe-0.3.1/tests/test_metrics.py +55 -0
  48. streamprobe-0.3.1/tests/test_normalize.py +101 -0
  49. streamprobe-0.3.1/tests/test_parsers.py +122 -0
  50. streamprobe-0.3.1/tests/test_report.py +152 -0
  51. streamprobe-0.3.1/tests/test_resolver.py +148 -0
  52. streamprobe-0.3.1/tests/test_sample.py +185 -0
  53. streamprobe-0.3.1/tests/test_scoring.py +208 -0
  54. streamprobe-0.3.1/tests/test_server_api.py +356 -0
  55. streamprobe-0.3.1/tests/test_server_e2e.py +132 -0
  56. streamprobe-0.3.1/tests/test_server_manifest.py +179 -0
  57. streamprobe-0.3.1/tests/test_server_store.py +216 -0
  58. streamprobe-0.3.1/tests/test_storage.py +22 -0
  59. streamprobe-0.3.1/tests/test_tools.py +140 -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,215 @@
1
+ Metadata-Version: 2.5
2
+ Name: streamprobe
3
+ Version: 0.3.1
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
+ Description-Content-Type: text/markdown
26
+
27
+ # StreamProbe
28
+
29
+ **See how healthy a live stream is before your viewers do.**
30
+
31
+ StreamProbe is a command-line tool that resolves a live stream URL, captures a short sample (10–60 seconds) together with delivery telemetry, uploads it to the hosted StreamProbe analysis service, and opens a shareable report.
32
+
33
+ The report covers:
34
+
35
+ - payload bitrate, resolution and frame rate, GOP structure
36
+ - frozen frames, black frames and brightness
37
+ - audio loudness (LUFS), true peak, silence and clipping
38
+ - channel balance, A/V start offset and timestamp discontinuities
39
+ - capture stalls, TTFB and payload throughput measured by the CLI
40
+
41
+ ## Installation
42
+
43
+ Requires Python 3.11+.
44
+
45
+ ```bash
46
+ # Recommended: uv
47
+ uv tool install streamprobe
48
+
49
+ # Or pipx / pip
50
+ pipx install streamprobe
51
+ pip install streamprobe
52
+ ```
53
+
54
+ ffmpeg is downloaded on first use by [portable-ffmpeg](https://pypi.org/project/portable-ffmpeg/), verified with SHA-256 and cached under `~/.streamprobe/cache/ffmpeg`. The CLI never runs ffprobe and performs no media analysis; Streamlink only uses ffmpeg while capturing streams that need separate audio/video tracks muxed (for example DASH or HLS with external audio). To use a system ffmpeg instead:
55
+
56
+ ```bash
57
+ # macOS
58
+ brew install ffmpeg
59
+ # Debian / Ubuntu
60
+ sudo apt install ffmpeg
61
+ # Then skip the managed download
62
+ streamprobe doctor --no-download
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ The default service is `https://streamprobe.app`. Uploads use a shared API token, sent only as `Authorization: Bearer`; it never appears in URLs or logs.
68
+
69
+ ```bash
70
+ # Optionally point the CLI at another StreamProbe service
71
+ streamprobe config set server.url https://streamprobe.example.com
72
+
73
+ # Omit VALUE to enter the token through a hidden prompt
74
+ streamprobe config set server.token
75
+
76
+ # Check configuration, token, connectivity and local tools
77
+ streamprobe doctor
78
+ ```
79
+
80
+ Configuration is stored in `~/.streamprobe/config.json` (mode `0600`, parent directory `0700`). `streamprobe config show` reports whether secrets are configured without printing their values. `STREAMPROBE_SERVER_URL` and `STREAMPROBE_API_TOKEN` override the file.
81
+
82
+ Bilibili cookies stay local, are only sent to `.bilibili.com` through Streamlink, and are never uploaded, written to reports, or logged.
83
+
84
+ ## Quick start
85
+
86
+ ```bash
87
+ # Capture, upload, wait for analysis and open the report
88
+ streamprobe "https://www.twitch.tv/example"
89
+
90
+ # Equivalent, with an explicit duration and quality
91
+ streamprobe probe "https://live.bilibili.com/12345" --duration 60 --quality 1080p-avc
92
+
93
+ # Upload without waiting, then print the report URL
94
+ streamprobe probe "<url>" --no-wait
95
+
96
+ # Upload an existing capture (analysis only, no delivery telemetry)
97
+ streamprobe upload capture.ts --title "Opening night" --platform youtube
98
+
99
+ # Machine-readable output (never includes the manage token)
100
+ streamprobe probe "<url>" --json
101
+ ```
102
+
103
+ `streamprobe <url>` is shorthand for `streamprobe probe <url>`.
104
+
105
+ ### Exit codes
106
+
107
+ | Code | Meaning |
108
+ |---|---|
109
+ | `0` | Upload accepted; in wait mode analysis also finished |
110
+ | `1` | The service produced a failure report |
111
+ | `2` | Usage, configuration, network or upload authentication error |
112
+ | `130` | Interrupted with Ctrl-C; in wait mode the CLI tries to cancel the remote job |
113
+
114
+ ### `streamprobe probe`
115
+
116
+ | Option | Description |
117
+ |---|---|
118
+ | `-d, --duration N` | Capture seconds; defaults to the configured value (30) |
119
+ | `-q, --quality NAME` | Streamlink quality name, e.g. `best`, `720p`, `1080p-avc` |
120
+ | `--server URL` | Override the service URL |
121
+ | `--token-file FILE` | Read the API token from a file |
122
+ | `--wait / --no-wait` | Wait for analysis (default: wait) |
123
+ | `--timeout N` | Wait timeout in seconds (default `900`) |
124
+ | `--json` | Print result JSON to stdout; progress stays on stderr |
125
+ | `--keep-raw` | Keep the raw capture under `~/.streamprobe/raw/<id>/` |
126
+ | `--open / --no-open` | Open the report in a browser (default: open) |
127
+ | `--ffmpeg PATH` | Explicit local ffmpeg path (capture muxing only) |
128
+ | `--no-download` | Do not download managed ffmpeg; use explicit paths or `PATH` |
129
+ | `--allow-http` | Allow plain HTTP for localhost (development only) |
130
+ | `--allow-private-hosts` | Allow loopback/private addresses (testing only) |
131
+ | `--allow-fake-ip` | Allow Clash/Surge fake-IP range `198.18.0.0/15` |
132
+
133
+ ### `streamprobe upload`
134
+
135
+ ```text
136
+ streamprobe upload FILE [OPTIONS]
137
+ ```
138
+
139
+ Uploads an existing capture with an analysis-only manifest: `probe.origin="cli"`, `probe.telemetry="none"`, and transport metrics are excluded from scoring. Supports `--server`, `--token-file`, `--wait/--no-wait`, `--timeout`, `--json`, `--open/--no-open`, `--allow-http`, plus optional `--title`, `--author`, `--platform` and `--source-url`.
140
+
141
+ ### `streamprobe config`
142
+
143
+ ```text
144
+ streamprobe config show
145
+ streamprobe config set {server.url|server.token|probe.defaultDuration|probe.defaultQuality|bilibili.cookie} [VALUE]
146
+ streamprobe config unset {server.url|server.token|probe.defaultDuration|probe.defaultQuality|bilibili.cookie}
147
+ ```
148
+
149
+ `server.token` and `bilibili.cookie` are entered through a hidden prompt when `VALUE` is omitted. `show` never prints secret values.
150
+
151
+ ### `streamprobe doctor`
152
+
153
+ ```text
154
+ streamprobe doctor [--json] [--no-download] [--clear-cache] [--allow-http]
155
+ ```
156
+
157
+ Prints configuration status, the service version and authentication result, ffmpeg source and version, and whether a Bilibili session is configured. It never prints the token or cookie. Exits `1` when configuration, token, tools or connectivity are missing.
158
+
159
+ ## Reports
160
+
161
+ Report links look like `https://streamprobe.app/p/<id>` and use unguessable 128-bit IDs. Viewing is public, so anyone with the link can see the report and its media sample. Reports expire after 7 days by default.
162
+
163
+ Each CLI-created report comes with a per-report `manageToken` used to cancel a running job or delete the report. `--open` passes it through the URL fragment (`#token=...`), which the report page reads and immediately removes from the address bar.
164
+
165
+ Uploads made with `streamprobe upload` are analysis-only: they have no network telemetry, so transport metrics are marked unmeasured and do not contribute to scoring.
166
+
167
+ ## Supported platforms
168
+
169
+ Twitch, YouTube Live, Bilibili Live, Douyu, Huya, Douyin Live, TikTok Live, Kick, CHZZK, SOOP, Facebook Live, Vimeo, niconico, DLive and TwitCasting.
170
+
171
+ URLs must use `https://` and belong to one of these platforms (or be added with `STREAMPROBE_ALLOWED_HOSTS`). Private, loopback and link-local addresses are rejected by default. Anonymous Bilibili requests usually top out at 720P H.264; a logged-in session may reach 1080P H.264. Bilibili quality IDs look like `1080p-av1` or `720p-avc`.
172
+
173
+ ## Local state
174
+
175
+ ```text
176
+ ~/.streamprobe/
177
+ config.json # service, probe defaults and Bilibili cookie; mode 0600
178
+ cache/ffmpeg/ # managed ffmpeg
179
+ tmp/capture-*/ # temporary captures; removed after a successful upload
180
+ raw/<id>/capture.bin # only with --keep-raw
181
+ ```
182
+
183
+ A failed upload keeps the temporary capture and prints its path so it can be retried with `streamprobe upload <file>`.
184
+
185
+ ## Environment variables
186
+
187
+ CLI variables use the `STREAMPROBE_` prefix and take precedence over `config.json`.
188
+
189
+ | Variable | Default | Description |
190
+ |---|---|---|
191
+ | `STREAMPROBE_HOME` | `~/.streamprobe` | Config, cache and temporary file root |
192
+ | `STREAMPROBE_SERVER_URL` | `https://streamprobe.app` | Service URL |
193
+ | `STREAMPROBE_API_TOKEN` | empty | Shared upload token |
194
+ | `STREAMPROBE_DEFAULT_DURATION` | `30` | Default capture seconds |
195
+ | `STREAMPROBE_DEFAULT_QUALITY` | empty | Default quality (`best` when empty) |
196
+ | `STREAMPROBE_MAX_DURATION` | `60` | Upper bound for `--duration` |
197
+ | `STREAMPROBE_MAX_BYTES` | `250MB` | Per-capture byte limit |
198
+ | `STREAMPROBE_ALLOWED_HOSTS` | empty | Extra allowed hosts, comma-separated |
199
+ | `STREAMPROBE_ALLOW_PRIVATE_HOSTS` | `false` | Allow loopback/private addresses |
200
+ | `STREAMPROBE_ALLOW_FAKE_IP` | `false` | Allow fake-IP addresses |
201
+ | `STREAMPROBE_FFMPEG` | empty | ffmpeg path (capture muxing only) |
202
+ | `STREAMPROBE_BILIBILI_COOKIE` | empty | Bilibili `Cookie` request header |
203
+ | `STREAMPROBE_PLATFORMS` | bundled data | Custom platform list path |
204
+
205
+ ## Limitations
206
+
207
+ - A short sample does not represent an entire broadcast; ads, transitions, stills, black frames and programme silence can trigger findings.
208
+ - Analysis-only uploads have no delivery telemetry, so transport metrics are explicitly shown as unmeasured rather than passed.
209
+ - Container PTS offsets are not a direct measurement of lip-sync error.
210
+ - Requires login, geo-restricted or DRM-protected streams produce explicit errors during resolution.
211
+ - Probe only streams you are authorised to access. StreamProbe does not bypass login, subscriptions, geo-restrictions or DRM.
212
+
213
+ ## License
214
+
215
+ MIT
@@ -0,0 +1,337 @@
1
+ # StreamProbe
2
+
3
+ **在观众察觉之前,先看清流的健康状态。**
4
+
5
+ StreamProbe 由两部分组成:
6
+
7
+ - **CLI**:在本地解析直播地址、抓取 10–60 秒原始流与传输遥测,然后上传到 StreamProbe 服务端。
8
+ - **服务端**:负责标准化、ffprobe/ffmpeg 分析、波形/频谱/截帧、可播放样本、评分,并托管可分享的报告。
9
+
10
+ 也可以在网页首页直接上传已有的抓取文件;浏览器上传只做媒体分析,没有网络传输遥测。
11
+
12
+ 检测维度包括:视频码率曲线、分辨率与帧率、GOP、冻结/黑屏/亮度、音频响度(LUFS)、true peak、静音/削波、声道平衡、CLI 抓取的卡顿/TTFB/吞吐、音画起始偏移与时间戳跳变。
13
+
14
+ ## 安装
15
+
16
+ 需要 Python 3.11+。
17
+
18
+ ```bash
19
+ # 推荐:uv
20
+ uv tool install streamprobe
21
+
22
+ # 或者 pipx / pip
23
+ pipx install streamprobe
24
+ pip install streamprobe
25
+ ```
26
+
27
+ ffmpeg 默认由 [portable-ffmpeg](https://pypi.org/project/portable-ffmpeg/) 在首次抓取时下载并做 SHA-256 校验,缓存在 `~/.streamprobe/cache/ffmpeg`。CLI 不做媒体分析,也不调用 ffprobe;ffmpeg 只在 Streamlink 抓取需要合并分离音视频轨的流时使用(例如 DASH 或带 external audio 的 HLS)。也可以使用系统安装的 ffmpeg:
28
+
29
+ ```bash
30
+ # macOS
31
+ brew install ffmpeg
32
+ # Debian / Ubuntu
33
+ sudo apt install ffmpeg
34
+ # 然后跳过自动下载
35
+ streamprobe doctor --no-download
36
+ ```
37
+
38
+ ## 配置
39
+
40
+ 默认服务端是 `https://streamprobe.app`。上传需要共享 API token,token 只用于 `Authorization: Bearer`,不会出现在 URL 或日志中。
41
+
42
+ ```bash
43
+ # 可选:换成自建服务端
44
+ streamprobe config set server.url https://streamprobe.example.com
45
+
46
+ # 不传 VALUE 时会隐藏输入
47
+ streamprobe config set server.token
48
+
49
+ # 检查配置、token、服务端连通性与本地工具
50
+ streamprobe doctor
51
+ ```
52
+
53
+ 配置保存在 `~/.streamprobe/config.json`(`0600`,父目录 `0700`):
54
+
55
+ ```json
56
+ {
57
+ "version": 2,
58
+ "server": {
59
+ "url": "https://streamprobe.app",
60
+ "token": "..."
61
+ },
62
+ "probe": {
63
+ "defaultDuration": 30,
64
+ "defaultQuality": null
65
+ },
66
+ "bilibili": {
67
+ "cookie": "SESSDATA=...; bili_jct=..."
68
+ }
69
+ }
70
+ ```
71
+
72
+ - `streamprobe config show` 只显示 token 是否已配置,不打印值。
73
+ - `server.token` / `bilibili.cookie` 也支持 `STREAMPROBE_API_TOKEN` / `STREAMPROBE_BILIBILI_COOKIE` 环境变量,环境变量优先。
74
+ - Bilibili Cookie 只注入 `.bilibili.com` 的 Streamlink 请求,**绝不上传、不写报告、不进日志**。
75
+ - 生产环境也可以通过 `--token-file` 从权限受限的文件读取 token,避免出现在 shell 历史里。
76
+
77
+ ## 快速开始
78
+
79
+ ```bash
80
+ # 抓取、上传、等待分析并打开报告
81
+ streamprobe "https://www.twitch.tv/example"
82
+
83
+ # 等价写法,指定抓取时长与画质
84
+ streamprobe probe "https://live.bilibili.com/12345" --duration 60 --quality 1080p-avc
85
+
86
+ # 只上传,不等待;打印报告 URL
87
+ streamprobe probe "<url>" --no-wait
88
+
89
+ # 上传已有抓取文件(没有网络遥测)
90
+ streamprobe upload capture.ts --title "Opening night" --platform youtube
91
+
92
+ # JSON 输出(不包含 manageToken)
93
+ streamprobe probe "<url>" --json
94
+ ```
95
+
96
+ `streamprobe <url>` 是 `streamprobe probe <url>` 的简写。
97
+
98
+ ### 退出码
99
+
100
+ | 退出码 | 含义 |
101
+ |---|---|
102
+ | `0` | 上传成功;等待模式下分析也完成(结论可以是 degraded / unhealthy) |
103
+ | `1` | 服务端已生成失败报告(离线、鉴权失败、无法解码等) |
104
+ | `2` | 用法、配置、网络或上传鉴权错误 |
105
+ | `130` | 用户按 Ctrl-C 中断;等待阶段会尝试取消服务端任务 |
106
+
107
+ ### `streamprobe probe`
108
+
109
+ ```text
110
+ streamprobe probe URL [OPTIONS]
111
+ ```
112
+
113
+ | 选项 | 说明 |
114
+ |---|---|
115
+ | `-d, --duration N` | 抓取秒数,默认来自配置(30);上限 `STREAMPROBE_MAX_DURATION`(默认 60) |
116
+ | `-q, --quality NAME` | Streamlink 画质名,如 `best`、`720p`;Bilibili 形如 `1080p-avc` |
117
+ | `--server URL` | 覆盖服务端地址 |
118
+ | `--token-file FILE` | 从文件读取 API token |
119
+ | `--wait / --no-wait` | 是否等待分析完成;默认等待 |
120
+ | `--timeout N` | 等待超时秒数,默认 `900` |
121
+ | `--json` | 将结果 JSON 写到 stdout,进度仍走 stderr |
122
+ | `--keep-raw` | 将原始抓取保留到 `~/.streamprobe/raw/<id>/` |
123
+ | `--open / --no-open` | 是否打开浏览器;默认打开 |
124
+ | `--ffmpeg PATH` | 显式指定本地 ffmpeg(仅抓取时 mux 使用) |
125
+ | `--no-download` | 不使用 managed ffmpeg 下载,仅用显式路径或 `PATH` |
126
+ | `--allow-http` | 允许 localhost 明文 HTTP(仅开发) |
127
+ | `--allow-private-hosts` | 允许探测环回/内网地址(仅测试) |
128
+ | `--allow-fake-ip` | 允许 Clash/Surge fake-IP 的 `198.18.0.0/15` |
129
+
130
+ ### `streamprobe upload`
131
+
132
+ ```text
133
+ streamprobe upload FILE [OPTIONS]
134
+ ```
135
+
136
+ 上传已有抓取文件,使用 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`。
137
+
138
+ ### `streamprobe config`
139
+
140
+ ```text
141
+ streamprobe config show
142
+ streamprobe config set {server.url|server.token|probe.defaultDuration|probe.defaultQuality|bilibili.cookie} [VALUE]
143
+ streamprobe config unset {server.url|server.token|probe.defaultDuration|probe.defaultQuality|bilibili.cookie}
144
+ ```
145
+
146
+ `server.token` 与 `bilibili.cookie` 在 `set` 时不传值会隐藏输入;`show` 不会打印 secret 原文。
147
+
148
+ ### `streamprobe doctor`
149
+
150
+ ```text
151
+ streamprobe doctor [--json] [--no-download] [--clear-cache] [--allow-http]
152
+ ```
153
+
154
+ 打印配置状态、服务端版本/鉴权、ffmpeg 来源与版本、Bilibili session 是否配置;不打印 token 或 cookie。缺配置、token、工具或服务端不可达时退出 `1`。
155
+
156
+ ## 报告
157
+
158
+ 报告链接形如 `https://streamprobe.app/p/<id>`,ID 为 128-bit 随机串,查看公开但不可猜。报告默认保留 `STREAMPROBE_TTL_DAYS=7` 天,到期自动删除。
159
+
160
+ - CLI 创建报告时会得到该报告专用的 `manageToken`,用于取消运行中的任务或删除报告。`--open` 会把 token 放在 URL fragment(`#token=...`)里,前端读取后立即从地址栏清除,只保存在本机浏览器。
161
+ - 网页上传会在同一个标签页保存 token,因此删除按钮可用。
162
+ - 报告页、图表与媒体样本通过同一域名提供;`/api/probes/{id}/report.json` 可下载完整 JSON。
163
+ - 浏览器上传没有实时网络采集,报告会标记 `probe.origin="browser"`、`probe.telemetry="none"`、`delivery.measured=false`,传输相关指标显示“未测量”,也不参与评分。
164
+
165
+ 报告 schema 见 [docs/report-schema.md](docs/report-schema.md),finding code 与建议见 [docs/findings.md](docs/findings.md)。
166
+
167
+ ## 支持的平台
168
+
169
+ 平台列表在 `src/streamprobe/data/platforms.json`,CLI 的 URL 校验使用这份数据:
170
+
171
+ Twitch、YouTube Live、Bilibili Live、斗鱼、虎牙、抖音直播、TikTok Live、Kick、CHZZK、SOOP、Facebook Live、Vimeo、niconico、DLive、TwitCasting。
172
+
173
+ URL 必须使用 `https://`,且 host 必须属于上述平台(或通过 `STREAMPROBE_ALLOWED_HOSTS` 额外放行)。私有、环回、链路本地地址默认被 SSRF 校验拒绝;Clash/Surge fake-IP 可加 `--allow-fake-ip`。
174
+
175
+ 匿名 Bilibili 请求通常最高只能拿到 720P H.264;登录态下可能拿到 1080P H.264。Bilibili 的画质 ID 形如 `1080p-av1`、`720p-avc`。AV1 无法装入 MPEG-TS,服务端会自动改用 NUT 容器(`probe.analyzedAs=nut`)。
176
+
177
+ ## 本地状态
178
+
179
+ ```text
180
+ ~/.streamprobe/
181
+ config.json # server/probe/bilibili 配置,权限 0600
182
+ cache/ffmpeg/ # managed ffmpeg
183
+ tmp/capture-*/ # 抓取中的临时目录;上传成功后删除
184
+ raw/<id>/capture.bin # 仅 --keep-raw
185
+ ```
186
+
187
+ 上传失败时会保留临时抓取并打印路径,方便用 `streamprobe upload <file>` 重试。成功且未指定 `--keep-raw` 时会删除临时目录。
188
+
189
+ ## 环境变量
190
+
191
+ CLI 相关变量均以 `STREAMPROBE_` 为前缀,优先级高于 `config.json`:
192
+
193
+ | 变量 | 默认值 | 说明 |
194
+ |---|---|---|
195
+ | `STREAMPROBE_HOME` | `~/.streamprobe` | 配置、缓存与临时文件根目录 |
196
+ | `STREAMPROBE_SERVER_URL` | `https://streamprobe.app` | 服务端地址 |
197
+ | `STREAMPROBE_API_TOKEN` | 空 | 共享上传 token |
198
+ | `STREAMPROBE_DEFAULT_DURATION` | `30` | 默认抓取秒数 |
199
+ | `STREAMPROBE_DEFAULT_QUALITY` | 空 | 默认画质,空表示 `best` |
200
+ | `STREAMPROBE_MAX_DURATION` | `60` | `--duration` 上限 |
201
+ | `STREAMPROBE_MAX_BYTES` | `250MB` | 单次抓取字节上限 |
202
+ | `STREAMPROBE_ALLOWED_HOSTS` | 空 | 额外允许的域名,逗号分隔 |
203
+ | `STREAMPROBE_ALLOW_PRIVATE_HOSTS` | `false` | 允许环回/内网地址 |
204
+ | `STREAMPROBE_ALLOW_FAKE_IP` | `false` | 允许 fake-IP 地址 |
205
+ | `STREAMPROBE_FFMPEG` | 空 | ffmpeg 路径(仅抓取 mux 使用) |
206
+ | `STREAMPROBE_BILIBILI_COOKIE` | 空 | Bilibili `Cookie` 请求头 |
207
+ | `STREAMPROBE_PLATFORMS` | 包内数据 | 自定义平台列表路径 |
208
+
209
+ ## 自建服务端
210
+
211
+ PyPI 上的 `streamprobe` 发行包只包含 CLI;服务端代码不随 PyPI 包发布。服务端通过 Docker 镜像部署,或从仓库源码运行:
212
+
213
+ ```bash
214
+ git clone https://github.com/Dup4/streamprobe
215
+ cd streamprobe
216
+ uv sync --group server
217
+
218
+ export STREAMPROBE_ENV=production
219
+ export STREAMPROBE_API_TOKEN_FILE=/path/to/api-token # 至少 32 字符
220
+ export STREAMPROBE_PUBLIC_BASE_URL=https://streamprobe.example.com
221
+ export STREAMPROBE_WEB_DIR=/path/to/web # Nuxt generate 的产物
222
+ export STREAMPROBE_DATA_DIR=/var/lib/streamprobe
223
+ uv run uvicorn streamprobe.server.main:create_app --factory --host 0.0.0.0 --port 8000 --workers 1 --proxy-headers
224
+ ```
225
+
226
+ 服务端主要环境变量:
227
+
228
+ | 变量 | 默认值 | 说明 |
229
+ |---|---|---|
230
+ | `STREAMPROBE_ENV` | `development` | `production` 时强制 HTTPS、token 长度与 web dir |
231
+ | `STREAMPROBE_DATA_DIR` | `/data` | 报告、暂存与临时文件 |
232
+ | `STREAMPROBE_PUBLIC_BASE_URL` | `http://127.0.0.1:8000` | 报告中使用的公开地址 |
233
+ | `STREAMPROBE_API_TOKEN` / `STREAMPROBE_API_TOKEN_FILE` | 空 | 共享上传 token;生产建议用文件 |
234
+ | `STREAMPROBE_WEB_DIR` | 空 | 构建好的 Nuxt UI(`web/.output/public`) |
235
+ | `STREAMPROBE_TTL_DAYS` | `7` | 报告保留天数 |
236
+ | `STREAMPROBE_CONCURRENCY` | `2` | 并发分析数 |
237
+ | `STREAMPROBE_QUEUE_SIZE` | `8` | 等待队列长度 |
238
+ | `STREAMPROBE_RATE_LIMIT` | `12/600` | 每个 IP 的窗口内上传次数 |
239
+ | `STREAMPROBE_MAX_UPLOAD_BYTES` | `300MB` | 单次 multipart 上限 |
240
+ | `STREAMPROBE_MAX_MANIFEST_BYTES` | `64KiB` | manifest 文本上限 |
241
+ | `STREAMPROBE_MIN_FREE_BYTES` | `2GB` | 低于此值拒绝上传 |
242
+ | `STREAMPROBE_MAX_DURATION` | `60` | 最长分析窗口 |
243
+ | `STREAMPROBE_ANALYSIS_TIMEOUT_SEC` | `480` | 单任务超时 |
244
+ | `STREAMPROBE_QUEUE_WAIT_TIMEOUT_SEC` | `60` | 排队超时 |
245
+ | `STREAMPROBE_TARGET_LUFS` | `-14` | 响度评分目标 |
246
+ | `STREAMPROBE_MEDIA_MAX_BYTES` | `50MB` | 可播放样本大小上限 |
247
+ | `STREAMPROBE_MEDIA_MAX_HEIGHT` | `720` | 转码样本最高分辨率 |
248
+ | `STREAMPROBE_MEDIA_TIMEOUT_SEC` | `180` | 样本生成超时 |
249
+ | `STREAMPROBE_CAPTURE_DATA_GRACE_SEC` | `5` | 允许抓取时长超出窗口的宽限 |
250
+ | `STREAMPROBE_FFMPEG` / `STREAMPROBE_FFPROBE` | `ffmpeg` / `ffprobe` | 服务端工具路径 |
251
+ | `STREAMPROBE_PLATFORMS` / `STREAMPROBE_HEALTH_CONFIG` | 包内数据 | 平台列表 / 评分配置路径 |
252
+ | `STREAMPROBE_TRUST_PROXY` | `false` | 信任 `X-Forwarded-For` |
253
+ | `STREAMPROBE_TRUSTED_HOSTS` | 空 | `Host` 白名单,逗号分隔 |
254
+ | `STREAMPROBE_KEEP_SAMPLE` | `false` | 保留上传的原始抓取 |
255
+
256
+ Docker:
257
+
258
+ ```bash
259
+ docker build -t streamprobe:dev .
260
+ docker run --rm -p 8000:8000 \
261
+ -e STREAMPROBE_ENV=development \
262
+ -e STREAMPROBE_API_TOKEN=dev-token \
263
+ -e STREAMPROBE_PUBLIC_BASE_URL=http://127.0.0.1:8000 \
264
+ -v streamprobe-data:/data \
265
+ streamprobe:dev
266
+ ```
267
+
268
+ 或使用 `docker-compose.yml`(需要设置 `STREAMPROBE_API_TOKEN`)。镜像内同时包含 FastAPI、构建好的 UI 与系统 ffmpeg,以非 root uid `10001` 运行。
269
+
270
+ 服务端不会访问客户端提供的任何 URL;所有上传都被视为不可信媒体。ffmpeg/ffprobe 输入固定带 `-protocol_whitelist file,pipe`,容器非 root、`cap_drop: ALL`、有超时与资源限制。
271
+
272
+ ## 安全与隐私
273
+
274
+ - 共享 token 只用于上传与鉴权;常量时间比较,不写日志,不放进 URL。网页只把 token 存在当前标签页的 `sessionStorage`。
275
+ - Bilibili session 只存在于 CLI 的 `~/.streamprobe/config.json`(`0600`);manifest、报告、服务端、worker 环境与日志都不包含它。
276
+ - 上传的原始抓取在分析后删除;报告与可播放样本按 TTL 保留。`report.json` 中的 URL 只保留 scheme/host/path,失败消息经过脱敏。
277
+ - 报告 ID 不可猜,但查看是公开的;拿到链接的人可以看到报告与媒体样本。不要上传无权公开的内容。
278
+ - 报告页带 `noindex` / `no-referrer`,报告链接默认 7 天后失效。
279
+ - 请只探测你有权访问的流;本项目不绕过登录、订阅或 DRM。配置自己的登录态不等于获得绕过权限。
280
+
281
+ ## 开发
282
+
283
+ 前置:Python 3.11+、[uv](https://docs.astral.sh/uv/)、Node.js(见 `.nvmrc`)、pnpm。
284
+
285
+ ```bash
286
+ make install # uv sync --group server + pnpm install
287
+ make web-assets # 构建 UI 到 web/.output/public
288
+ make lint # ruff + eslint
289
+ make typecheck # mypy + nuxt typecheck
290
+ make test # pytest(不含 e2e)+ vitest
291
+ make test-e2e # 需要本机 ffmpeg
292
+ make check # lint + typecheck + test
293
+ make package # 构建 wheel/sdist 并校验布局
294
+ ```
295
+
296
+ 仓库结构:
297
+
298
+ ```text
299
+ src/streamprobe/ Python 包:CLI、抓取、上传、manifest、分析与报告
300
+ server/ 托管服务:FastAPI、队列、worker、存储、上传
301
+ data/ 平台列表与 health.toml
302
+ tests/ pytest(含 e2e)
303
+ web/ Nuxt 4 报告 UI(SSG,由 Docker 镜像提供)
304
+ docs/ finding code 与报告 schema
305
+ Dockerfile 单镜像:FastAPI + UI + ffmpeg
306
+ ```
307
+
308
+ 本地跑服务端:
309
+
310
+ ```bash
311
+ uv run uvicorn streamprobe.server.main:create_app --factory --port 8000
312
+ ```
313
+
314
+ 默认 `development` 模式不要求 token、不要求 HTTPS;需要 UI 时先 `make web-assets`,并设置 `STREAMPROBE_WEB_DIR=web/.output/public`。
315
+
316
+ ## 发布
317
+
318
+ 版本号唯一来源是 `src/streamprobe/version.py`,同步更新 `web/package.json` 后打 `vX.Y.Z` tag。Release workflow 会:
319
+
320
+ 1. 校验 tag 与版本一致,构建并校验 wheel/sdist;
321
+ 2. 通过 PyPI trusted publishing 发布 CLI(wheel/sdist 只包含 CLI,不含 `streamprobe/server`);
322
+ 3. 构建 `linux/amd64` Docker 镜像并推送到 `registry.cn-shanghai.aliyuncs.com/dup4/streamprobe:<tag>`。
323
+
324
+ PyPI 需要 trusted publisher:仓库 `Dup4/streamprobe`、workflow `release.yml`、environment `pypi`。ACR 推送需要 secrets `ALIYUN_REGISTRY_USERNAME` / `ALIYUN_REGISTRY_TOKEN`。部署由 homelab Ansible 的 `streamprobe` role 完成。
325
+
326
+ ## 限制
327
+
328
+ - 样本窗口不代表整场直播;广告、转场、静帧、黑场与节目静音都可能触发提示。
329
+ - 浏览器上传没有网络遥测,传输指标明确显示“未测量”,不能被解读为“通过”。
330
+ - 容器 PTS 偏移不等于真实唇音同步误差。
331
+ - 服务端为单实例内存队列(`workers=1`),不支持水平扩容。
332
+ - 主要在 macOS / Linux 验证;Windows 可运行 CLI,但未纳入 CI。
333
+ - 需要登录、地区限制或 DRM 的流会在解析阶段给出明确错误。
334
+
335
+ ## 许可证
336
+
337
+ [MIT](LICENSE)