@torrent-tv/proxy 2.89.17 → 2.89.18

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 (299) hide show
  1. package/README.md +14 -3
  2. package/package.json +10 -2
  3. package/server.js +0 -11
  4. package/.claude/commands/opsx/apply.md +0 -155
  5. package/.claude/commands/opsx/archive.md +0 -160
  6. package/.claude/commands/opsx/explore.md +0 -174
  7. package/.claude/commands/opsx/propose.md +0 -109
  8. package/.claude/commands/opsx/sync.md +0 -143
  9. package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
  10. package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
  11. package/.claude/skills/openspec-explore/SKILL.md +0 -289
  12. package/.claude/skills/openspec-propose/SKILL.md +0 -113
  13. package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
  14. package/.dockerignore +0 -5
  15. package/AGENTS.md +0 -363
  16. package/CHANGELOG.md +0 -2377
  17. package/Dockerfile +0 -30
  18. package/biome.json +0 -412
  19. package/corpus.tmp.json +0 -1
  20. package/docs/browser-proxy-contract.md +0 -155
  21. package/docs/container-architecture.md +0 -273
  22. package/docs/download-architecture.md +0 -261
  23. package/docs/encode-architecture.md +0 -765
  24. package/docs/encode-run-state.md +0 -96
  25. package/docs/logs.md +0 -151
  26. package/docs/playback-start-forecast.md +0 -113
  27. package/docs/socks5-egress-research.md +0 -114
  28. package/docs/storage-architecture.md +0 -273
  29. package/knip.json +0 -14
  30. package/main2.cpuprofile +0 -1
  31. package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
  32. package/openspec/changes/adaptive-bitrate/design.md +0 -92
  33. package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
  34. package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
  35. package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
  36. package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
  37. package/openspec/changes/binary-distribution/proposal.md +0 -53
  38. package/openspec/changes/chunked-request-bodies/design.md +0 -81
  39. package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
  40. package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
  41. package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
  42. package/openspec/changes/cold-start/design.md +0 -98
  43. package/openspec/changes/cold-start/proposal.md +0 -62
  44. package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
  45. package/openspec/changes/cold-start/tasks.md +0 -48
  46. package/openspec/changes/disk-cap/.openspec.yaml +0 -2
  47. package/openspec/changes/disk-cap/proposal.md +0 -37
  48. package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
  49. package/openspec/changes/disk-cap/tasks.md +0 -19
  50. package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
  51. package/openspec/changes/proxy-observability/design.md +0 -38
  52. package/openspec/changes/proxy-observability/proposal.md +0 -49
  53. package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
  54. package/openspec/changes/proxy-observability/tasks.md +0 -21
  55. package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
  56. package/openspec/changes/seek-debounce/design.md +0 -118
  57. package/openspec/changes/seek-debounce/proposal.md +0 -59
  58. package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
  59. package/openspec/changes/seek-debounce/tasks.md +0 -33
  60. package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
  61. package/openspec/changes/subtitle-language/proposal.md +0 -50
  62. package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
  63. package/openspec/changes/subtitle-language/tasks.md +0 -26
  64. package/openspec/changes/track-selection/.openspec.yaml +0 -2
  65. package/openspec/changes/track-selection/design.md +0 -47
  66. package/openspec/changes/track-selection/proposal.md +0 -45
  67. package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
  68. package/openspec/changes/track-selection/tasks.md +0 -20
  69. package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
  70. package/openspec/changes/transcode-quality/proposal.md +0 -51
  71. package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
  72. package/openspec/changes/transcode-quality/tasks.md +0 -63
  73. package/openspec/config.yaml +0 -38
  74. package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
  75. package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
  76. package/research/double-spawn-2026-09-10.md +0 -171
  77. package/research/handover-2026-09-13.md +0 -209
  78. package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
  79. package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
  80. package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
  81. package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
  82. package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
  83. package/scripts/build-audio-samples.mjs +0 -31
  84. package/scripts/render-run-graph.js +0 -173
  85. package/test/asset-paths.test.js +0 -28
  86. package/test/audio-buffer-continuity.test.js +0 -77
  87. package/test/audio-calibration.test.js +0 -23
  88. package/test/audio-inventory.test.js +0 -212
  89. package/test/audio-track-bitrate.test.js +0 -40
  90. package/test/audio-warm-recorded.test.js +0 -63
  91. package/test/auto-quality-step.test.js +0 -762
  92. package/test/available-share.test.js +0 -76
  93. package/test/background-fill.test.js +0 -190
  94. package/test/client-log-file.test.js +0 -126
  95. package/test/client-logs-route.test.js +0 -34
  96. package/test/coalesce.test.js +0 -39
  97. package/test/completed-files.test.js +0 -115
  98. package/test/concurrent-cost.test.js +0 -148
  99. package/test/container-media-info.test.js +0 -228
  100. package/test/contention.test.js +0 -76
  101. package/test/core-dumps.test.js +0 -57
  102. package/test/coverage-follows-the-disk.test.js +0 -233
  103. package/test/coverage-map.test.js +0 -195
  104. package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
  105. package/test/cut-times-timeline.test.js +0 -65
  106. package/test/cuts-follow-published-grid.test.js +0 -109
  107. package/test/data-channel-frame.test.js +0 -63
  108. package/test/data-channel-viewer-lifecycle.test.js +0 -193
  109. package/test/dead-torrent-handle.test.js +0 -52
  110. package/test/declared-rates.test.js +0 -116
  111. package/test/declared-tracks.test.js +0 -43
  112. package/test/decode-cost-fit.test.js +0 -202
  113. package/test/decode-cost.test.js +0 -475
  114. package/test/delivery-probe-field.test.js +0 -173
  115. package/test/delivery-probe.test.js +0 -382
  116. package/test/demand-register.test.js +0 -206
  117. package/test/dht-bootstrap.test.js +0 -72
  118. package/test/drain-threat.test.js +0 -65
  119. package/test/duplicate-add.test.js +0 -48
  120. package/test/encode-admission.test.js +0 -170
  121. package/test/encode-cost.test.js +0 -275
  122. package/test/encode-exit.test.js +0 -111
  123. package/test/encode-orchestrator.test.js +0 -426
  124. package/test/encode-plan-viewers.test.js +0 -725
  125. package/test/encode-plan.test.js +0 -545
  126. package/test/encode-run-state.test.js +0 -314
  127. package/test/encode-run.test.js +0 -248
  128. package/test/encode-slope.test.js +0 -46
  129. package/test/encoded-output.test.js +0 -39
  130. package/test/encoder-kinds.test.js +0 -122
  131. package/test/encoder-readings.test.js +0 -68
  132. package/test/episode-naming.test.js +0 -131
  133. package/test/every-claimant-is-told-its-share.test.js +0 -152
  134. package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
  135. package/test/failed-start-breaker.test.js +0 -202
  136. package/test/fastest-wires.test.js +0 -143
  137. package/test/ffmpeg-stream-counts.test.js +0 -101
  138. package/test/file-edges.test.js +0 -191
  139. package/test/files-in-use.test.js +0 -34
  140. package/test/fixtures/audio-frame-boundary.json +0 -1
  141. package/test/fixtures/refused-audio-20261002.json +0 -10
  142. package/test/fmp4-presentation-clock.test.js +0 -148
  143. package/test/fmp4-self-contained.test.js +0 -80
  144. package/test/fmp4-timestamps.test.js +0 -140
  145. package/test/fmp4-track-completeness.test.js +0 -41
  146. package/test/format-keyed-outputs.test.js +0 -78
  147. package/test/health-metrics.test.js +0 -36
  148. package/test/held-read-ownership.test.js +0 -77
  149. package/test/held-request-width.test.js +0 -157
  150. package/test/helpers/encode-run.js +0 -248
  151. package/test/helpers/held-file.js +0 -77
  152. package/test/helpers/manager.js +0 -62
  153. package/test/helpers/matroska-file.js +0 -296
  154. package/test/helpers/output-spec.js +0 -63
  155. package/test/host-load.test.js +0 -68
  156. package/test/index-accuracy-is-about-the-file.test.js +0 -128
  157. package/test/init-compat.test.js +0 -219
  158. package/test/input-lost-quiets-the-plan.test.js +0 -261
  159. package/test/input-unavailable.test.js +0 -48
  160. package/test/installation-id.test.js +0 -39
  161. package/test/keeping-period.test.js +0 -83
  162. package/test/keyframe-index-accuracy.test.js +0 -188
  163. package/test/keyframe-table-budget.test.js +0 -123
  164. package/test/keyframes-belong-to-the-file.test.js +0 -249
  165. package/test/learned-median.test.js +0 -37
  166. package/test/letting-go-asks-who-is-watching.test.js +0 -191
  167. package/test/limit-row-by-area.test.js +0 -60
  168. package/test/link-budget.test.js +0 -111
  169. package/test/link-probe.test.js +0 -56
  170. package/test/local-encoding-data.test.js +0 -273
  171. package/test/logger-repeats.test.js +0 -134
  172. package/test/look-ahead-coverage.test.js +0 -56
  173. package/test/manager-surface.test.js +0 -291
  174. package/test/matroska-blocks.test.js +0 -0
  175. package/test/matroska-cluster-discovery.test.js +0 -323
  176. package/test/matroska-cues-track.test.js +0 -192
  177. package/test/media-time.test.js +0 -62
  178. package/test/memory-budget.test.js +0 -390
  179. package/test/move-cost.test.js +0 -216
  180. package/test/mp4-composition-times.test.js +0 -0
  181. package/test/mp4-subtitles.test.js +0 -173
  182. package/test/one-authority.test.js +0 -285
  183. package/test/one-budget.test.js +0 -149
  184. package/test/one-output-one-session.test.js +0 -273
  185. package/test/one-resource-divided.test.js +0 -185
  186. package/test/one-serving-output-per-height.test.js +0 -458
  187. package/test/orchestrator-wired.test.js +0 -207
  188. package/test/output-catalog.test.js +0 -39
  189. package/test/output-shape.test.js +0 -21
  190. package/test/output-spec.test.js +0 -251
  191. package/test/output-speed.test.js +0 -92
  192. package/test/outputs-being-prepared.test.js +0 -40
  193. package/test/packet-witness-ring.test.js +0 -236
  194. package/test/packet-witness.test.js +0 -148
  195. package/test/piece-completeness.test.js +0 -78
  196. package/test/piece-disk-store.test.js +0 -401
  197. package/test/piece-from-whole-file.test.js +0 -129
  198. package/test/piece-lru.test.js +0 -319
  199. package/test/piece-reader.test.js +0 -162
  200. package/test/piece-selection-offset.test.js +0 -85
  201. package/test/piece-store-eviction.test.js +0 -595
  202. package/test/piece-store-never-refuses.test.js +0 -153
  203. package/test/piece-store-reservations.test.js +0 -403
  204. package/test/piece-store-slow-disk.test.js +0 -159
  205. package/test/piece-tail.test.js +0 -97
  206. package/test/plan-host-timings.test.js +0 -68
  207. package/test/plan-is-steady.test.js +0 -225
  208. package/test/playback-readiness.test.js +0 -518
  209. package/test/playback-start-regressions.test.js +0 -101
  210. package/test/priority-map-download.test.js +0 -174
  211. package/test/priority-map-emptied.test.js +0 -204
  212. package/test/priority-map-per-output.test.js +0 -215
  213. package/test/priority-map.test.js +0 -163
  214. package/test/probe-wedge-certainty.test.js +0 -60
  215. package/test/produced-copy-choice.test.js +0 -213
  216. package/test/published-timeline.test.js +0 -83
  217. package/test/quality-offer.test.js +0 -160
  218. package/test/quality-variants.test.js +0 -1274
  219. package/test/rate-control-in-the-output.test.js +0 -181
  220. package/test/read-survives-withdrawal.test.js +0 -164
  221. package/test/read-window.test.js +0 -365
  222. package/test/reads-not-yet-arrived.test.js +0 -218
  223. package/test/resume-warm.test.js +0 -39
  224. package/test/run-graph-drift.test.js +0 -37
  225. package/test/run-inputs.test.js +0 -80
  226. package/test/run-intervals.test.js +0 -100
  227. package/test/run-position-follows-published-grid.test.js +0 -89
  228. package/test/run-progress.test.js +0 -64
  229. package/test/same-height-switch.test.js +0 -663
  230. package/test/seek-frees-the-viewers-requests.test.js +0 -217
  231. package/test/seek-landing.test.js +0 -109
  232. package/test/seek-target-not-superseded.test.js +0 -195
  233. package/test/segment-closed-on-both-branches.test.js +0 -114
  234. package/test/segment-cut-times.test.js +0 -63
  235. package/test/segment-demand.test.js +0 -80
  236. package/test/segment-hold-supersede.test.js +0 -91
  237. package/test/segment-judged-by-its-own-header.test.js +0 -222
  238. package/test/segment-serve-wiring.test.js +0 -481
  239. package/test/segment-store-eviction.test.js +0 -247
  240. package/test/segment-store.test.js +0 -352
  241. package/test/segment-true-start.test.js +0 -86
  242. package/test/segments-are-shared.test.js +0 -176
  243. package/test/send-chunk-bytes.test.js +0 -86
  244. package/test/serving-existing-output.test.js +0 -111
  245. package/test/serving-output.test.js +0 -102
  246. package/test/shared-piece-store.test.js +0 -310
  247. package/test/sidecar-naming.test.js +0 -142
  248. package/test/soundtrack-rate-bound.test.js +0 -289
  249. package/test/source-file.test.js +0 -133
  250. package/test/source-files-route.test.js +0 -113
  251. package/test/source-registry.test.js +0 -18
  252. package/test/split-a-stretch.test.js +0 -139
  253. package/test/stale-request-after-seek.test.js +0 -158
  254. package/test/startup-readings.test.js +0 -124
  255. package/test/stream-route.test.js +0 -237
  256. package/test/subtitle-cue-framing.test.js +0 -200
  257. package/test/subtitle-cue-source.test.js +0 -102
  258. package/test/subtitle-cue-walk.test.js +0 -385
  259. package/test/subtitle-cursor.test.js +0 -63
  260. package/test/subtitle-defaults.test.js +0 -118
  261. package/test/subtitle-language.test.js +0 -252
  262. package/test/subtitle-metadata.test.js +0 -15
  263. package/test/subtitle-plan-waits.test.js +0 -125
  264. package/test/subtitle-track-numbering.test.js +0 -391
  265. package/test/supply-margin.test.js +0 -190
  266. package/test/swarm-follows-readers.test.js +0 -174
  267. package/test/swarm-reach.test.js +0 -130
  268. package/test/swarm-selection.test.js +0 -220
  269. package/test/tail-duplication.test.js +0 -167
  270. package/test/the-channel-has-both-ends.test.js +0 -91
  271. package/test/the-torrent-thread-serves-bytes.test.js +0 -107
  272. package/test/thread-pool.test.js +0 -53
  273. package/test/timeline.test.js +0 -84
  274. package/test/torrent-contents.test.js +0 -235
  275. package/test/torrent-cost.test.js +0 -71
  276. package/test/torrent-files.test.js +0 -221
  277. package/test/torrent-naming.test.js +0 -255
  278. package/test/tracks-begin-together.test.js +0 -209
  279. package/test/tunnel-renewal.test.js +0 -167
  280. package/test/two-viewers-one-picture.test.js +0 -508
  281. package/test/upload-hurry.test.js +0 -186
  282. package/test/usrsctp-state.test.js +0 -131
  283. package/test/video-facts.test.js +0 -102
  284. package/test/viewer-assignments.test.js +0 -143
  285. package/test/viewer-outputs.test.js +0 -285
  286. package/test/viewer-presence.test.js +0 -116
  287. package/test/viewer-requests-admission.test.js +0 -92
  288. package/test/viewer-starts-on-map.test.js +0 -27
  289. package/test/viewer-states.test.js +0 -192
  290. package/test/viewer-subtitle-subscription.test.js +0 -96
  291. package/test/viewer.test.js +0 -139
  292. package/test/viewing-generations.test.js +0 -390
  293. package/test/visible-rung.test.js +0 -37
  294. package/test/wait-ledger.test.js +0 -100
  295. package/test/webrtc-shim.test.js +0 -149
  296. package/test/wedge-certainty.test.js +0 -131
  297. package/test/whole-file-held-read.test.js +0 -30
  298. package/test/withdraw-piece-claim.test.js +0 -212
  299. package/test/worker-channel.test.js +0 -158
@@ -1,34 +0,0 @@
1
- # subtitle-language — delta spec
2
-
3
- ## ADDED Requirements
4
-
5
- ### Requirement: Proxy converts subtitles and reports the language
6
- `GET /api/subtitles` SHALL serve every subtitle as WebVTT and report the
7
- detected language in `X-Subtitle-Language` (ISO 639-1) and
8
- `X-Subtitle-Language-Name`. It SHALL handle two modes: an embedded track
9
- (`trackIndex` given — extracted via ffmpeg) and an external subtitle file (no
10
- `trackIndex` — the file is read, its encoding decoded, and `.srt`/`.ass`/
11
- `.ssa` converted to WebVTT on the proxy). A leading BOM SHALL be stripped and
12
- Windows-1251 bytes decoded when the file is not valid UTF-8.
13
-
14
- #### Scenario: External Russian .srt without a filename code
15
- - **WHEN** an external `.srt` whose name has no language code is requested
16
- - **THEN** the response is WebVTT and `X-Subtitle-Language` is `ru`
17
-
18
- #### Scenario: Ukrainian is not reported as Russian
19
- - **WHEN** the subtitle text is Ukrainian
20
- - **THEN** the detected language is `uk`, not `ru`
21
-
22
- #### Scenario: Unsupported format
23
- - **WHEN** an image-based or unconvertible subtitle is requested
24
- - **THEN** the proxy responds 422
25
-
26
- ### Requirement: Detection is confidence-gated
27
- Language detection SHALL be restricted to a curated set of plausible subtitle
28
- languages and SHALL return no language (omit the header) when the text is too
29
- short or undetermined, rather than emitting a wrong guess.
30
-
31
- #### Scenario: Too little text
32
- - **WHEN** the subtitle has only a few characters
33
- - **THEN** no language header is set (the browser falls back to filename or
34
- audio language)
@@ -1,26 +0,0 @@
1
- # Tasks: Proxy subtitle conversion + language detection
2
-
3
- ## 1. Proxy
4
-
5
- - [x] 1.1 `services/subtitle-convert.js`: encoding-aware decode (UTF-8/BOM/
6
- Windows-1251) + srt/ass/ssa → WebVTT (ported, BOM-stripped)
7
- - [x] 1.2 `services/language-detect.js`: franc restricted to a curated
8
- ISO 639-3→639-1 allowlist; null when undetermined/too short
9
- - [x] 1.3 `routes/api/subtitles/get.js`: external-file mode (read, decode,
10
- convert, detect) + `X-Subtitle-Language(-Name)` on both modes
11
- - [x] 1.4 franc dependency added to proxy
12
- - [x] 1.5 Verified: unit-tested convert+detect (ru/uk/en/de, short→null) and
13
- the route end-to-end on the real Enola .srt (→ ru, 19 cues)
14
-
15
- ## 2. Server (browser)
16
-
17
- - [x] 2.1 External subs fetch VTT from `/api/subtitles` (no client convert)
18
- - [x] 2.2 Language priority: filename code → X-Subtitle-Language → audio-track
19
- language → und; embedded track uses metadata → header → audio
20
- - [x] 2.3 Removed the client-side convertSubtitleToVtt call + dead import
21
-
22
- ## 3. Release
23
-
24
- - [ ] 3.1 Proxy publish (OTP) + ha-addon bump + server patch
25
- - [ ] 3.2 Field-check: Enola external .srt labels "Russian"; a Ukrainian sub
26
- labels "Ukrainian"; embedded tracks keep their metadata language
@@ -1,2 +0,0 @@
1
- schema: spec-driven
2
- created: 2026-07-07
@@ -1,47 +0,0 @@
1
- # Design: Track inventory, audio selection and embedded-subtitle extraction
2
-
3
- ## Context
4
-
5
- The probe already captures the full ffmpeg `-i` banner; the HLS session
6
- manager already restarts ffmpeg per (source, file, settings) key; the
7
- `/stream` route already drives prioritised sequential download. All three
8
- features ride those mechanisms.
9
-
10
- ## Goals / Non-Goals
11
-
12
- **Goals:** expose every track; select audio server-side; deliver embedded
13
- text subtitles as WebVTT.
14
-
15
- **Non-Goals:** seamless (no-restart) audio switching via HLS alternate
16
- renditions; image-based subtitles (PGS/VobSub — needs OCR or burn-in);
17
- subtitle extraction that avoids downloading the file (impossible: cues are
18
- interleaved across the whole container).
19
-
20
- ## Decisions
21
-
22
- 1. **Parse tracks from the existing probe output** (zero extra probe cost).
23
- The scanner reads only the Input section — ffmpeg prints Stream lines for
24
- the null output too, which would duplicate every track (caught against
25
- real output). Titles come from each stream's `title` metadata line.
26
- 2. **Audio switch = new session.** `audioTrackIndex` joins the session key;
27
- the old session dies via the existing idle TTL. Reuses the proven
28
- seek-restart machinery instead of building HLS alternate renditions;
29
- the cost is a few seconds' gap on switch — acceptable v1.
30
- 3. **Extraction as a streaming route.** ffmpeg writes WebVTT to stdout piped
31
- into the HTTP response; the first stdout chunk decides 200-vs-422 (a
32
- non-text track dies before producing output). Client disconnect kills
33
- ffmpeg; a 30-minute hard cap guards dead swarms. The transport layer's
34
- 60 s request timeout must be raised per-request by the browser (done in
35
- the paired server change).
36
- 4. **Accepted v1 cost:** extraction reads to the last cue → cold torrents
37
- download while extracting. For the transcode path the file downloads
38
- anyway; for direct play this is extra traffic the viewer opted into by
39
- picking a subtitle.
40
-
41
- ## Risks / Trade-offs
42
-
43
- - [Extraction competes with playback for piece priority] → both readers move
44
- the 8 MB critical window; sequential download serves both. Field-watch; if
45
- playback stalls appear, throttle extraction reads later.
46
- - [Stream-line format drift across ffmpeg versions] → regex kept permissive;
47
- a parse miss degrades to an empty inventory (menus simply do not appear).
@@ -1,45 +0,0 @@
1
- # Proposal: Track inventory, audio selection and embedded-subtitle extraction
2
-
3
- ## Why
4
-
5
- Torrents routinely carry several audio languages and embedded subtitles
6
- (the owner's own test MKVs embed ASS subtitles), but the proxy exposed only
7
- "the first audio track" and no subtitles at all: the probe reported a single
8
- audio/video codec pair, the HLS session hard-mapped `0:a:0`, and embedded
9
- subtitle streams were unreachable by the browser.
10
-
11
- ## What Changes
12
-
13
- - **Probe returns the full track inventory**: `audioTracks` and
14
- `subtitleTracks` in the playback plan (type-relative index, codec,
15
- language, `title` metadata, default flag, `textBased` for subtitles) —
16
- parsed from the same single ffmpeg banner, no extra probe cost.
17
- - **Audio selection**: `POST /api/transcode-sessions` accepts
18
- `audioTrackIndex`; the ffmpeg map becomes `0:a:N` and the index joins the
19
- session key (switch = fresh session via the existing restart machinery).
20
- - **Embedded subtitle extraction**: `GET /api/subtitles` streams a chosen
21
- text subtitle track as WebVTT (ffmpeg `-map 0:s:N -f webvtt`). Image-based
22
- tracks (PGS/VobSub) are refused with 422. Known cost, accepted for v1:
23
- extraction reads the file to the last cue, so a cold torrent downloads
24
- sequentially while extracting.
25
- - Announce log masks the tracker query string (passkey).
26
-
27
- ## Capabilities
28
-
29
- ### New Capabilities
30
-
31
- - `track-selection`: track inventory in the plan, audio mapping, subtitle
32
- extraction.
33
-
34
- ### Modified Capabilities
35
-
36
- - `observability`: announce log masks the passkey (delta note; the change is
37
- still unarchived so the edit lands there).
38
-
39
- ## Impact
40
-
41
- - `services/playback-planner.js`, `services/hls-session-manager.js`,
42
- `routes/api/transcode-sessions/post.js`, new `routes/api/subtitles/get.js`,
43
- `server.js` wiring, `services/torrent/torrent-pool.js` (log masking).
44
- - Pairs with the server-side `track-selection-ui` change; requires the usual
45
- ha-addon bump.
@@ -1,41 +0,0 @@
1
- # track-selection — delta spec
2
-
3
- ## ADDED Requirements
4
-
5
- ### Requirement: The playback plan lists every track
6
- The playback plan SHALL include `audioTracks` and `subtitleTracks` arrays
7
- parsed from the probe: for each track its type-relative index (what
8
- `-map 0:a:N` / `0:s:N` selects), codec, language tag, `title` metadata,
9
- default disposition, and — for subtitles — a `textBased` flag. Output-side
10
- streams of the probe run MUST NOT leak into the inventory.
11
-
12
- #### Scenario: MKV with an embedded subtitle
13
- - **WHEN** the plan is requested for an MKV with one video, one audio and one
14
- ASS subtitle stream
15
- - **THEN** the plan lists exactly one audio track and one subtitle track with
16
- `textBased: true`
17
-
18
- ### Requirement: Audio track selection
19
- `POST /api/transcode-sessions` SHALL accept `audioTrackIndex` (type-relative,
20
- default 0) and the session SHALL map that audio track. The index SHALL be
21
- part of the session identity so different tracks never share a session.
22
-
23
- #### Scenario: Second audio track
24
- - **WHEN** a session is created with `audioTrackIndex: 1`
25
- - **THEN** ffmpeg maps `0:a:1` and a later request with `audioTrackIndex: 0`
26
- gets a different session
27
-
28
- ### Requirement: Embedded subtitles as WebVTT
29
- `GET /api/subtitles?sourceKey&fileIndex&trackIndex` SHALL stream the chosen
30
- embedded TEXT subtitle track converted to WebVTT, starting the response as
31
- soon as ffmpeg produces output. A track that produces no output (image-based
32
- or broken) SHALL return 422 before any body. Extraction MUST stop when the
33
- client disconnects.
34
-
35
- #### Scenario: Text track extracted
36
- - **WHEN** the client requests a text subtitle track
37
- - **THEN** the response is `text/vtt` starting with `WEBVTT` and real cues
38
-
39
- #### Scenario: Image-based track refused
40
- - **WHEN** the client requests a PGS/VobSub track
41
- - **THEN** the proxy responds 422 with an explanatory error
@@ -1,20 +0,0 @@
1
- # Tasks: Track inventory, audio selection and embedded-subtitle extraction
2
-
3
- ## 1. Implementation
4
-
5
- - [x] 1.1 playback-planner: input-section stream scanner (index, codec,
6
- language, title, default, textBased); `audioTracks`/`subtitleTracks`
7
- in the plan (verified against real ffmpeg output from the owner's MKV:
8
- hevc + flac + ass(eng) parsed, output streams excluded)
9
- - [x] 1.2 hls-session-manager: `audioTrackIndex` option → `-map 0:a:N`,
10
- part of the session key; transcode-sessions route passthrough
11
- - [x] 1.3 routes/api/subtitles/get.js: streaming WebVTT extraction, 422 on
12
- no-output tracks, kill on client disconnect, 30 min cap (verified:
13
- real cues extracted from the embedded ASS track over the LAN proxy)
14
- - [x] 1.4 torrent-pool: mask the announce query string (passkey)
15
-
16
- ## 2. Release
17
-
18
- - [ ] 2.1 `npm run patch` (2.9.26; needs npm 2FA), then ha-addon 0.2.48
19
- - [ ] 2.2 After the addon updates: verify plan lists tracks and
20
- /api/subtitles serves VTT from the addon proxy
@@ -1,2 +0,0 @@
1
- schema: spec-driven
2
- created: 2026-07-07
@@ -1,51 +0,0 @@
1
- # Proposal: Transcode quality — source fps, realtime budget, HDR, manual quality
2
-
3
- ## Why
4
-
5
- The transcode pipeline was tuned for "make it play at all" and left several
6
- quality/robustness gaps flagged in the project analysis: output was hard-
7
- locked to 24 fps (25/30 fps content played with resampling judder); the
8
- encoder profile could be slower than realtime on weak hosts (stalls instead
9
- of graceful degradation); 10-bit/HDR sources transcoded to 8-bit H.264
10
- without tone mapping (washed-out colours); and the viewer had no way to force
11
- a resolution. This change is the transcode-stage batch (proxy side; the
12
- manual-quality menu also needs the server UI).
13
-
14
- ## What Changes
15
-
16
- - **Source fps** (DONE): the output frame rate is inherited from the source
17
- (rounded to an integer, capped at 30), replacing the fixed 24. The
18
- fixed-GOP encoders keep the fps↔GOP relationship exact so keyframes stay on
19
- the segment grid; time-based-keyframe encoders (nvenc) just use it as the
20
- rate; VAAPI/QSV already inherited.
21
- - **Realtime budget** (planned): the startup benchmark picks the
22
- encoder/preset/resolution/fps combination whose predicted throughput stays
23
- above realtime; a source that would not encode in time is downscaled
24
- (720/540p) rather than refused, and a sustained runtime `speed<1` triggers
25
- a restart with a lighter profile. `-maxrate`/`-bufsize` cap bitrate spikes.
26
- - **HDR tone mapping** (planned): detect 10-bit/HDR (pix_fmt,
27
- color_transfer smpte2084/HLG) and insert a tone-map chain when re-encoding
28
- to 8-bit H.264, so colours are not washed out. Depends on the ffmpeg build
29
- having the tonemap filters.
30
- - **Manual quality** (planned): a player Quality menu — Auto (current
31
- viewport/DPR behaviour) plus forced resolutions — the proxy already
32
- honours a requested target height.
33
-
34
- ## Capabilities
35
-
36
- ### New Capabilities
37
-
38
- - `transcode-quality`: output frame rate, realtime encode budget, HDR tone
39
- mapping, and explicit quality selection.
40
-
41
- ### Modified Capabilities
42
-
43
- <!-- none -->
44
-
45
- ## Impact
46
-
47
- - `services/encode/hwaccel.js` (fps, benchmark, tonemap args),
48
- `services/hls-session-manager.js` (fps probe, runtime speed watch),
49
- `services/playback-planner.js` (HDR/fps in the plan);
50
- server player UI for the Quality menu; ha-addon bump.
51
- - Released as a batch (proxy 2.9.29 + addon) after the pieces land.
@@ -1,139 +0,0 @@
1
- # transcode-quality — delta spec
2
-
3
- ## ADDED Requirements
4
-
5
- ### Requirement: Output frame rate follows the source
6
- When re-encoding video, the proxy SHALL NOT force a fixed 24 fps. The output
7
- rate SHALL follow the source, and the fps handling SHALL depend on how the
8
- chosen encoder places keyframes:
9
-
10
- - Frame-count-GOP encoders (software libx264, v4l2m2m) SHALL use an INTEGER
11
- output rate — source rate rounded and capped — with the `fps` filter and
12
- the GOP length (`segmentDuration × fps`) using that same integer, so a
13
- keyframe lands on every segment boundary and segments do not drift off the
14
- synthetic playlist's uniform grid. When the source rate is unknown they
15
- SHALL fall back to the default rate.
16
- - Time-based-keyframe encoders (nvenc, vaapi, qsv) SHALL inherit the exact
17
- source rate with no fps filter (their keyframes are forced by output time,
18
- so any rate segments correctly); no rounding, no cap.
19
-
20
- #### Scenario: 25 fps source on the software encoder
21
- - **WHEN** a 25 fps video is re-encoded with libx264 and 4-second segments
22
- - **THEN** the output is 25 fps and the GOP is 100 frames (keyframe every
23
- segment)
24
-
25
- #### Scenario: High-fps source on the software encoder
26
- - **WHEN** a 60 fps video is re-encoded with libx264/v4l2m2m
27
- - **THEN** the output rate is capped at 30 fps (speed guard)
28
-
29
- #### Scenario: Fractional source on a hardware time-based encoder
30
- - **WHEN** a 23.976 fps video is re-encoded with nvenc/vaapi/qsv
31
- - **THEN** the exact source rate is kept (no fps filter) and segments are
32
- still cut on time
33
-
34
- #### Scenario: Unknown source rate
35
- - **WHEN** the source frame rate cannot be probed on the software path
36
- - **THEN** the output falls back to the default rate and playback still
37
- segments correctly
38
-
39
- ### Requirement: Software encode fits a realtime budget at startup
40
-
41
- For the software encoder, the proxy SHALL choose the output resolution and
42
- libx264 preset a startup benchmark predicts this host can encode faster than
43
- realtime (with a margin), rather than always encoding at the client-requested
44
- resolution. The client-requested box, capped to the source resolution (never
45
- upscaled), is the ceiling; the proxy SHALL pick the highest resolution rung at
46
- or below that ceiling that clears the realtime margin, then the highest-quality
47
- preset that still clears it at that resolution. When even the lowest rung
48
- cannot clear the margin, the proxy SHALL use the lowest rung (best effort). The
49
- realtime need SHALL be computed from the session's actual output frame rate.
50
- Hardware encoders and the no-benchmark case SHALL keep the ceiling resolution
51
- and the default preset.
52
-
53
- #### Scenario: Weak host, source above realtime capacity
54
- - **WHEN** the software benchmark shows the host cannot encode the source-capped
55
- resolution faster than realtime (e.g. 720p60→30 that runs below 1×)
56
- - **THEN** the proxy downscales to the highest ladder rung that clears the
57
- realtime margin (e.g. 480p) instead of encoding sub-realtime at full size
58
-
59
- #### Scenario: Capable host
60
- - **WHEN** the benchmark shows ample headroom at the ceiling resolution
61
- - **THEN** the proxy keeps the ceiling resolution and spends the headroom on a
62
- higher-quality (slower) preset
63
-
64
- #### Scenario: Hardware encoder
65
- - **WHEN** a hardware encoder is selected
66
- - **THEN** no benchmark-based downscale is applied and the ceiling resolution
67
- is used
68
-
69
- ### Requirement: Software encode downswitches at runtime when CPU-bound
70
-
71
- The proxy SHALL, for the software encoder, step the output resolution one rung
72
- down the ladder and restart the encode at the segment currently being watched
73
- when a transcode runs below realtime for a sustained window. Before downscaling
74
- it SHALL determine whether the limit is the encoder or a download-starved
75
- input — comparing the torrent download rate with the source's average byte rate
76
- (a fully-downloaded file is never download-bound) — and SHALL NOT downscale when
77
- the limit is the download (it SHALL log that instead). The downswitch SHALL be
78
- bounded by a sustained-slow window, a post-action cooldown, a maximum number of
79
- steps, and a resolution floor, and SHALL reset its slow window on every encode
80
- (re)start. There SHALL be no automatic upswitch in this version.
81
-
82
- #### Scenario: Sustained CPU-bound transcode
83
- - **WHEN** a software transcode's encoder speed stays below realtime for the
84
- sustained window while the input download keeps up
85
- - **THEN** the proxy downscales one rung and restarts at the current segment,
86
- up to the step cap / resolution floor
87
-
88
- #### Scenario: Download-limited, not CPU-limited
89
- - **WHEN** the encoder speed is below realtime but the torrent cannot download
90
- the source's byte rate and the file is not fully downloaded
91
- - **THEN** the proxy does not downscale and logs that the download is the limit
92
-
93
- #### Scenario: No thrash after a switch
94
- - **WHEN** a downswitch (or a viewer seek) has just restarted the encode
95
- - **THEN** the slow window is reset and no further downswitch occurs until a new
96
- sustained-slow window elapses after the cooldown
97
-
98
- ### Requirement: Manual quality forces a constant resolution
99
-
100
- The viewer SHALL be able to force a specific output resolution instead of Auto.
101
- When a resolution is forced the proxy SHALL encode exactly that box (capped to
102
- the source, never upscaled) with the realtime budget disabled — no startup
103
- auto-downscale and no runtime downswitch — so the resolution stays constant for
104
- the whole session. The browser SHALL offer Auto plus resolutions at or below the
105
- source height, built from the source resolution reported in the playback plan.
106
- Selecting a quality SHALL re-open the stream at the new resolution with the
107
- playback position preserved. Auto SHALL keep the current realtime-budget
108
- behaviour.
109
-
110
- #### Scenario: Forced resolution is constant
111
- - **WHEN** the viewer forces a resolution (e.g. 480p)
112
- - **THEN** the proxy encodes at that resolution for the whole session, with no
113
- budget downscale or runtime downswitch, and playback resumes at the same
114
- position
115
-
116
- #### Scenario: Auto
117
- - **WHEN** the viewer selects Auto
118
- - **THEN** the proxy applies the realtime budget (startup selection + runtime
119
- downswitch) as before
120
-
121
- ### Requirement: HDR sources are tone-mapped when re-encoded to SDR
122
-
123
- The proxy SHALL apply an HDR→BT.709 SDR tone-map chain when re-encoding an HDR
124
- source (a BT.2020 PQ `smpte2084` or HLG `arib-std-b67` transfer) to 8-bit SDR on
125
- the software path, so the output is not washed-out — provided this ffmpeg build
126
- has the required filters. The proxy SHALL detect filter availability (`zscale`
127
- and `tonemap`) at startup and, when either is missing, SHALL fall back to a
128
- plain 8-bit convert without failing playback.
129
-
130
- #### Scenario: HDR source, filters available
131
- - **WHEN** an HDR source is re-encoded on the software path and the build has
132
- `zscale` + `tonemap`
133
- - **THEN** the tone-map chain is inserted and the output is BT.709 SDR (not
134
- washed-out)
135
-
136
- #### Scenario: HDR source, filters missing
137
- - **WHEN** an HDR source is re-encoded but the build lacks `zscale`/`tonemap`
138
- - **THEN** playback still proceeds with a plain 8-bit convert (no tone map) and
139
- the limitation is logged
@@ -1,63 +0,0 @@
1
- # Tasks: Transcode quality
2
-
3
- ## 1. Source fps
4
-
5
- - [x] 1.1 hwaccel: `chooseOutputFps` (integer, capped); `buildVideoArgs`
6
- takes `fps`, threaded into the filter + frame-count GOP (software,
7
- v4l2m2m) and the filter only (nvenc); VAAPI/QSV unchanged (already
8
- inherit); startup test-encode/benchmark keep the fixed rate
9
- - [x] 1.2 hls-session-manager: parse source fps from the probe, compute
10
- `session.outputFps`, pass it into `buildVideoArgs`
11
- - [x] 1.3 Unit-verify fps choice and fps↔GOP consistency (25→100, 24→96,
12
- default→96); syntax checks
13
-
14
- ## 2. Realtime budget
15
-
16
- - [x] 2.1 Startup: benchmark picks resolution + preset within a realtime
17
- margin; downscale below the client-target ceiling instead of refusing
18
- (`chooseSoftwareEncodeSettings`/`buildResolutionLadder` in hwaccel;
19
- `#chooseEncodeBudget` + `encodeWidth`/`encodeHeight` in the session
20
- manager; fixed the needed-pixels calc to use the session's `outputFps`
21
- not the fixed `TRANSCODE_FPS`). Verified on the FIFA host profile
22
- (720p60→480p) + strong/weak/no-benchmark profiles.
23
- - [x] 2.2 Runtime `speed<1` watch → step down the resolution ladder + restart
24
- at the current segment (hard-restart tier). Gate on CPU-bound only:
25
- compare `getFileStats().downloadSpeed` with the source byte-rate so a
26
- download-starved input is NOT misread as an encoder limit (don't degrade
27
- quality for a download bottleneck — log it instead). Hysteresis +
28
- cooldown + floor + max steps; slow window reset on every (re)start; no
29
- upswitch in v1 (oscillation risk). `#enforceRealtimeBudget` +
30
- `#classifyTranscodeBound` + `#applyBudgetDownshift` in the session
31
- manager; `getSourceStats` injected from server.js.
32
- NOTE (follow-up 2.2b): seamless switch via `EXT-X-DISCONTINUITY` /
33
- parallel encoder tier keyed by host resources — the hard restart can blip
34
- at the switch point.
35
- - [ ] 2.3 `-maxrate`/`-bufsize`
36
-
37
- ## 3. HDR tone mapping
38
-
39
- - [x] 3.1 Detect HDR from the probe (PQ `smpte2084` / HLG `arib-std-b67`
40
- transfer); insert a `zscale`+`tonemap` (hable) BT.2020→BT.709 SDR chain
41
- when re-encoding video on the software path (after the downscale).
42
- - [x] 3.2 Guard on tonemap-filter availability: startup `detectTonemapSupport`
43
- checks `ffmpeg -filters` for `zscale` + `tonemap`; when missing, HDR
44
- falls back to the plain 8-bit convert (washed-out but plays). Logged.
45
- NOTE (follow-up 3.3): hardware-encoder tone mapping (tonemap_vaapi / npp /
46
- opencl) — software path only for now.
47
-
48
- ## 4. Manual quality
49
-
50
- - [x] 4.1 Proxy honours a forced resolution: `manualQuality` flag on the
51
- transcode-session request encodes the requested box exactly (capped to
52
- source, budget + runtime downswitch disabled); `manualQuality` in the
53
- session key; playback plan reports source `videoWidth`/`videoHeight`.
54
- - [x] 4.2 Server Quality menu (Auto + forced resolutions <= source). Custom
55
- media-chrome submenu mirroring the audio menu; selection re-opens the
56
- stream at the forced resolution with the position preserved (reuses the
57
- audio-switch machinery); shared settings button shows for audio OR
58
- quality.
59
-
60
- ## 5. Release
61
-
62
- - [ ] 5.1 Batch release: proxy 2.9.29 + ha-addon bump; field-test on the
63
- owner's hardware (25/30 fps content plays without judder; seek intact)
@@ -1,38 +0,0 @@
1
- schema: spec-driven
2
-
3
- context: |
4
- @torrent-tv/proxy — WebTorrent + ffmpeg, published to npm. Downloads a torrent
5
- and streams the chosen file to the browser over a WebRTC data channel (plain
6
- HTTPS transport planned), transcoding to HLS only for the track(s) the browser
7
- cannot play natively (supported track = copied).
8
- Constraints (see CLAUDE.md for the full set):
9
- - Deployment-agnostic: the HA addon is only one way to run it. No
10
- Home-Assistant assumptions; runtime detection with graceful fallback only.
11
- - Routes: routes/<path>/<method>.js exporting handle<Name><Method>.
12
- - All code, comments and docs in English.
13
- - Every behavioural change adds a CHANGELOG.md entry at current package.json
14
- version + 1 patch. Never edit package.json version (npm run patch bumps it).
15
- - Any behavioural proxy change requires bumping ha-addon config.yaml version
16
- in the same changeset (the addon must be re-released to pull the new proxy).
17
- - HLS is VOD-only with server-side seeking (never -hls_playlist_type event).
18
- - Hardware encoders are gated by a strict startup test; software libx264 is
19
- the fallback.
20
-
21
- # Project context (optional)
22
- # This is shown to AI when creating artifacts.
23
- # Add your tech stack, conventions, style guides, domain knowledge, etc.
24
- # Example:
25
- # context: |
26
- # Tech stack: TypeScript, React, Node.js
27
- # We use conventional commits
28
- # Domain: e-commerce platform
29
-
30
- # Per-artifact rules (optional)
31
- # Add custom rules for specific artifacts.
32
- # Example:
33
- # rules:
34
- # proposal:
35
- # - Keep proposals under 500 words
36
- # - Always include a "Non-goals" section
37
- # tasks:
38
- # - Break tasks into chunks of max 2 hours