@torrent-tv/proxy 2.89.17 → 2.89.19
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.
- package/README.md +14 -3
- package/package.json +10 -2
- package/server.js +0 -11
- package/utils/client-log-file.js +147 -42
- package/.claude/commands/opsx/apply.md +0 -155
- package/.claude/commands/opsx/archive.md +0 -160
- package/.claude/commands/opsx/explore.md +0 -174
- package/.claude/commands/opsx/propose.md +0 -109
- package/.claude/commands/opsx/sync.md +0 -143
- package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
- package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
- package/.claude/skills/openspec-explore/SKILL.md +0 -289
- package/.claude/skills/openspec-propose/SKILL.md +0 -113
- package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
- package/.dockerignore +0 -5
- package/AGENTS.md +0 -363
- package/CHANGELOG.md +0 -2377
- package/Dockerfile +0 -30
- package/biome.json +0 -412
- package/corpus.tmp.json +0 -1
- package/docs/browser-proxy-contract.md +0 -155
- package/docs/container-architecture.md +0 -273
- package/docs/download-architecture.md +0 -261
- package/docs/encode-architecture.md +0 -765
- package/docs/encode-run-state.md +0 -96
- package/docs/logs.md +0 -151
- package/docs/playback-start-forecast.md +0 -113
- package/docs/socks5-egress-research.md +0 -114
- package/docs/storage-architecture.md +0 -273
- package/knip.json +0 -14
- package/main2.cpuprofile +0 -1
- package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
- package/openspec/changes/adaptive-bitrate/design.md +0 -92
- package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
- package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
- package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
- package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
- package/openspec/changes/binary-distribution/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/design.md +0 -81
- package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
- package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
- package/openspec/changes/cold-start/design.md +0 -98
- package/openspec/changes/cold-start/proposal.md +0 -62
- package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
- package/openspec/changes/cold-start/tasks.md +0 -48
- package/openspec/changes/disk-cap/.openspec.yaml +0 -2
- package/openspec/changes/disk-cap/proposal.md +0 -37
- package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
- package/openspec/changes/disk-cap/tasks.md +0 -19
- package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
- package/openspec/changes/proxy-observability/design.md +0 -38
- package/openspec/changes/proxy-observability/proposal.md +0 -49
- package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
- package/openspec/changes/proxy-observability/tasks.md +0 -21
- package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
- package/openspec/changes/seek-debounce/design.md +0 -118
- package/openspec/changes/seek-debounce/proposal.md +0 -59
- package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
- package/openspec/changes/seek-debounce/tasks.md +0 -33
- package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
- package/openspec/changes/subtitle-language/proposal.md +0 -50
- package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
- package/openspec/changes/subtitle-language/tasks.md +0 -26
- package/openspec/changes/track-selection/.openspec.yaml +0 -2
- package/openspec/changes/track-selection/design.md +0 -47
- package/openspec/changes/track-selection/proposal.md +0 -45
- package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
- package/openspec/changes/track-selection/tasks.md +0 -20
- package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
- package/openspec/changes/transcode-quality/proposal.md +0 -51
- package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
- package/openspec/changes/transcode-quality/tasks.md +0 -63
- package/openspec/config.yaml +0 -38
- package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
- package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
- package/research/double-spawn-2026-09-10.md +0 -171
- package/research/handover-2026-09-13.md +0 -209
- package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
- package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
- package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
- package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
- package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
- package/scripts/build-audio-samples.mjs +0 -31
- package/scripts/render-run-graph.js +0 -173
- package/test/asset-paths.test.js +0 -28
- package/test/audio-buffer-continuity.test.js +0 -77
- package/test/audio-calibration.test.js +0 -23
- package/test/audio-inventory.test.js +0 -212
- package/test/audio-track-bitrate.test.js +0 -40
- package/test/audio-warm-recorded.test.js +0 -63
- package/test/auto-quality-step.test.js +0 -762
- package/test/available-share.test.js +0 -76
- package/test/background-fill.test.js +0 -190
- package/test/client-log-file.test.js +0 -126
- package/test/client-logs-route.test.js +0 -34
- package/test/coalesce.test.js +0 -39
- package/test/completed-files.test.js +0 -115
- package/test/concurrent-cost.test.js +0 -148
- package/test/container-media-info.test.js +0 -228
- package/test/contention.test.js +0 -76
- package/test/core-dumps.test.js +0 -57
- package/test/coverage-follows-the-disk.test.js +0 -233
- package/test/coverage-map.test.js +0 -195
- package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
- package/test/cut-times-timeline.test.js +0 -65
- package/test/cuts-follow-published-grid.test.js +0 -109
- package/test/data-channel-frame.test.js +0 -63
- package/test/data-channel-viewer-lifecycle.test.js +0 -193
- package/test/dead-torrent-handle.test.js +0 -52
- package/test/declared-rates.test.js +0 -116
- package/test/declared-tracks.test.js +0 -43
- package/test/decode-cost-fit.test.js +0 -202
- package/test/decode-cost.test.js +0 -475
- package/test/delivery-probe-field.test.js +0 -173
- package/test/delivery-probe.test.js +0 -382
- package/test/demand-register.test.js +0 -206
- package/test/dht-bootstrap.test.js +0 -72
- package/test/drain-threat.test.js +0 -65
- package/test/duplicate-add.test.js +0 -48
- package/test/encode-admission.test.js +0 -170
- package/test/encode-cost.test.js +0 -275
- package/test/encode-exit.test.js +0 -111
- package/test/encode-orchestrator.test.js +0 -426
- package/test/encode-plan-viewers.test.js +0 -725
- package/test/encode-plan.test.js +0 -545
- package/test/encode-run-state.test.js +0 -314
- package/test/encode-run.test.js +0 -248
- package/test/encode-slope.test.js +0 -46
- package/test/encoded-output.test.js +0 -39
- package/test/encoder-kinds.test.js +0 -122
- package/test/encoder-readings.test.js +0 -68
- package/test/episode-naming.test.js +0 -131
- package/test/every-claimant-is-told-its-share.test.js +0 -152
- package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
- package/test/failed-start-breaker.test.js +0 -202
- package/test/fastest-wires.test.js +0 -143
- package/test/ffmpeg-stream-counts.test.js +0 -101
- package/test/file-edges.test.js +0 -191
- package/test/files-in-use.test.js +0 -34
- package/test/fixtures/audio-frame-boundary.json +0 -1
- package/test/fixtures/refused-audio-20261002.json +0 -10
- package/test/fmp4-presentation-clock.test.js +0 -148
- package/test/fmp4-self-contained.test.js +0 -80
- package/test/fmp4-timestamps.test.js +0 -140
- package/test/fmp4-track-completeness.test.js +0 -41
- package/test/format-keyed-outputs.test.js +0 -78
- package/test/health-metrics.test.js +0 -36
- package/test/held-read-ownership.test.js +0 -77
- package/test/held-request-width.test.js +0 -157
- package/test/helpers/encode-run.js +0 -248
- package/test/helpers/held-file.js +0 -77
- package/test/helpers/manager.js +0 -62
- package/test/helpers/matroska-file.js +0 -296
- package/test/helpers/output-spec.js +0 -63
- package/test/host-load.test.js +0 -68
- package/test/index-accuracy-is-about-the-file.test.js +0 -128
- package/test/init-compat.test.js +0 -219
- package/test/input-lost-quiets-the-plan.test.js +0 -261
- package/test/input-unavailable.test.js +0 -48
- package/test/installation-id.test.js +0 -39
- package/test/keeping-period.test.js +0 -83
- package/test/keyframe-index-accuracy.test.js +0 -188
- package/test/keyframe-table-budget.test.js +0 -123
- package/test/keyframes-belong-to-the-file.test.js +0 -249
- package/test/learned-median.test.js +0 -37
- package/test/letting-go-asks-who-is-watching.test.js +0 -191
- package/test/limit-row-by-area.test.js +0 -60
- package/test/link-budget.test.js +0 -111
- package/test/link-probe.test.js +0 -56
- package/test/local-encoding-data.test.js +0 -273
- package/test/logger-repeats.test.js +0 -134
- package/test/look-ahead-coverage.test.js +0 -56
- package/test/manager-surface.test.js +0 -291
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cluster-discovery.test.js +0 -323
- package/test/matroska-cues-track.test.js +0 -192
- package/test/media-time.test.js +0 -62
- package/test/memory-budget.test.js +0 -390
- package/test/move-cost.test.js +0 -216
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +0 -173
- package/test/one-authority.test.js +0 -285
- package/test/one-budget.test.js +0 -149
- package/test/one-output-one-session.test.js +0 -273
- package/test/one-resource-divided.test.js +0 -185
- package/test/one-serving-output-per-height.test.js +0 -458
- package/test/orchestrator-wired.test.js +0 -207
- package/test/output-catalog.test.js +0 -39
- package/test/output-shape.test.js +0 -21
- package/test/output-spec.test.js +0 -251
- package/test/output-speed.test.js +0 -92
- package/test/outputs-being-prepared.test.js +0 -40
- package/test/packet-witness-ring.test.js +0 -236
- package/test/packet-witness.test.js +0 -148
- package/test/piece-completeness.test.js +0 -78
- package/test/piece-disk-store.test.js +0 -401
- package/test/piece-from-whole-file.test.js +0 -129
- package/test/piece-lru.test.js +0 -319
- package/test/piece-reader.test.js +0 -162
- package/test/piece-selection-offset.test.js +0 -85
- package/test/piece-store-eviction.test.js +0 -595
- package/test/piece-store-never-refuses.test.js +0 -153
- package/test/piece-store-reservations.test.js +0 -403
- package/test/piece-store-slow-disk.test.js +0 -159
- package/test/piece-tail.test.js +0 -97
- package/test/plan-host-timings.test.js +0 -68
- package/test/plan-is-steady.test.js +0 -225
- package/test/playback-readiness.test.js +0 -518
- package/test/playback-start-regressions.test.js +0 -101
- package/test/priority-map-download.test.js +0 -174
- package/test/priority-map-emptied.test.js +0 -204
- package/test/priority-map-per-output.test.js +0 -215
- package/test/priority-map.test.js +0 -163
- package/test/probe-wedge-certainty.test.js +0 -60
- package/test/produced-copy-choice.test.js +0 -213
- package/test/published-timeline.test.js +0 -83
- package/test/quality-offer.test.js +0 -160
- package/test/quality-variants.test.js +0 -1274
- package/test/rate-control-in-the-output.test.js +0 -181
- package/test/read-survives-withdrawal.test.js +0 -164
- package/test/read-window.test.js +0 -365
- package/test/reads-not-yet-arrived.test.js +0 -218
- package/test/resume-warm.test.js +0 -39
- package/test/run-graph-drift.test.js +0 -37
- package/test/run-inputs.test.js +0 -80
- package/test/run-intervals.test.js +0 -100
- package/test/run-position-follows-published-grid.test.js +0 -89
- package/test/run-progress.test.js +0 -64
- package/test/same-height-switch.test.js +0 -663
- package/test/seek-frees-the-viewers-requests.test.js +0 -217
- package/test/seek-landing.test.js +0 -109
- package/test/seek-target-not-superseded.test.js +0 -195
- package/test/segment-closed-on-both-branches.test.js +0 -114
- package/test/segment-cut-times.test.js +0 -63
- package/test/segment-demand.test.js +0 -80
- package/test/segment-hold-supersede.test.js +0 -91
- package/test/segment-judged-by-its-own-header.test.js +0 -222
- package/test/segment-serve-wiring.test.js +0 -481
- package/test/segment-store-eviction.test.js +0 -247
- package/test/segment-store.test.js +0 -352
- package/test/segment-true-start.test.js +0 -86
- package/test/segments-are-shared.test.js +0 -176
- package/test/send-chunk-bytes.test.js +0 -86
- package/test/serving-existing-output.test.js +0 -111
- package/test/serving-output.test.js +0 -102
- package/test/shared-piece-store.test.js +0 -310
- package/test/sidecar-naming.test.js +0 -142
- package/test/soundtrack-rate-bound.test.js +0 -289
- package/test/source-file.test.js +0 -133
- package/test/source-files-route.test.js +0 -113
- package/test/source-registry.test.js +0 -18
- package/test/split-a-stretch.test.js +0 -139
- package/test/stale-request-after-seek.test.js +0 -158
- package/test/startup-readings.test.js +0 -124
- package/test/stream-route.test.js +0 -237
- package/test/subtitle-cue-framing.test.js +0 -200
- package/test/subtitle-cue-source.test.js +0 -102
- package/test/subtitle-cue-walk.test.js +0 -385
- package/test/subtitle-cursor.test.js +0 -63
- package/test/subtitle-defaults.test.js +0 -118
- package/test/subtitle-language.test.js +0 -252
- package/test/subtitle-metadata.test.js +0 -15
- package/test/subtitle-plan-waits.test.js +0 -125
- package/test/subtitle-track-numbering.test.js +0 -391
- package/test/supply-margin.test.js +0 -190
- package/test/swarm-follows-readers.test.js +0 -174
- package/test/swarm-reach.test.js +0 -130
- package/test/swarm-selection.test.js +0 -220
- package/test/tail-duplication.test.js +0 -167
- package/test/the-channel-has-both-ends.test.js +0 -91
- package/test/the-torrent-thread-serves-bytes.test.js +0 -107
- package/test/thread-pool.test.js +0 -53
- package/test/timeline.test.js +0 -84
- package/test/torrent-contents.test.js +0 -235
- package/test/torrent-cost.test.js +0 -71
- package/test/torrent-files.test.js +0 -221
- package/test/torrent-naming.test.js +0 -255
- package/test/tracks-begin-together.test.js +0 -209
- package/test/tunnel-renewal.test.js +0 -167
- package/test/two-viewers-one-picture.test.js +0 -508
- package/test/upload-hurry.test.js +0 -186
- package/test/usrsctp-state.test.js +0 -131
- package/test/video-facts.test.js +0 -102
- package/test/viewer-assignments.test.js +0 -143
- package/test/viewer-outputs.test.js +0 -285
- package/test/viewer-presence.test.js +0 -116
- package/test/viewer-requests-admission.test.js +0 -92
- package/test/viewer-starts-on-map.test.js +0 -27
- package/test/viewer-states.test.js +0 -192
- package/test/viewer-subtitle-subscription.test.js +0 -96
- package/test/viewer.test.js +0 -139
- package/test/viewing-generations.test.js +0 -390
- package/test/visible-rung.test.js +0 -37
- package/test/wait-ledger.test.js +0 -100
- package/test/webrtc-shim.test.js +0 -149
- package/test/wedge-certainty.test.js +0 -131
- package/test/whole-file-held-read.test.js +0 -30
- package/test/withdraw-piece-claim.test.js +0 -212
- package/test/worker-channel.test.js +0 -158
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The rule this pins: a subtitle cursor counts the order cues were FOUND, not
|
|
6
|
-
* where they sit in the film.
|
|
7
|
-
*
|
|
8
|
-
* Cues are read out of whichever clusters happen to be downloaded, and a
|
|
9
|
-
* torrent does not arrive in film order — a seek pulls a later stretch first,
|
|
10
|
-
* and the earlier one fills in afterwards. So the set of known cues grows in
|
|
11
|
-
* the MIDDLE as well as at the end.
|
|
12
|
-
*
|
|
13
|
-
* A cursor in film time cannot survive that: measured 2026-08-20 on a viewer at
|
|
14
|
-
* 272 s, one answer carried cues out to 1176 s, and from that moment every cue
|
|
15
|
-
* between the two was filtered away for the rest of the session — the stretch
|
|
16
|
-
* they were about to watch. 59 of 276 clusters had been read.
|
|
17
|
-
*
|
|
18
|
-
* The filter below is the route's, written out so the property can be checked
|
|
19
|
-
* without a torrent: `?since=<n>` selects by found-order, `?after=<seconds>` is
|
|
20
|
-
* the old behaviour kept for an older browser.
|
|
21
|
-
*/
|
|
22
|
-
const bySince = (cues, since) => cues.filter((cue) => (Number(cue.seq) || 0) > since);
|
|
23
|
-
const byAfter = (cues, after) => cues.filter((cue) => cue.startSeconds > after);
|
|
24
|
-
|
|
25
|
-
/** A late-arriving cluster from EARLIER in the film than what is already held. */
|
|
26
|
-
const held = [
|
|
27
|
-
{ startSeconds: 40, text: "found first, early in the film", seq: 1 },
|
|
28
|
-
{ startSeconds: 1176, text: "found second, far ahead", seq: 2 },
|
|
29
|
-
{ startSeconds: 300, text: "found third, behind the furthest held", seq: 3 }
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
test("a cue found after a further-ahead one is still delivered", () => {
|
|
33
|
-
// The browser holds seq 1 and 2 and asks for what came after.
|
|
34
|
-
const fresh = bySince(held, 2);
|
|
35
|
-
assert.deepEqual(fresh.map((cue) => cue.startSeconds), [300]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("the same case in film time loses that cue for ever", () => {
|
|
39
|
-
// This is what shipped in 2.43.1 and what the field session showed: the
|
|
40
|
-
// browser's furthest cue is 1176 s, so the 300 s cue can never reach it.
|
|
41
|
-
const fresh = byAfter(held, 1176);
|
|
42
|
-
assert.deepEqual(fresh.map((cue) => cue.startSeconds), []);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("a browser asking for the first time is sent everything", () => {
|
|
46
|
-
assert.equal(bySince(held, 0).length, 3);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("nothing new is answered with nothing", () => {
|
|
50
|
-
assert.deepEqual(bySince(held, 3), []);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("the cursor to send back is the highest found-order held", () => {
|
|
54
|
-
const cursor = held.reduce((highest, cue) => Math.max(highest, Number(cue.seq) || 0), 0);
|
|
55
|
-
assert.equal(cursor, 3);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("a cursor is unaffected by the order cues are sorted into", () => {
|
|
59
|
-
// The list is kept in film order for the WebVTT it becomes; the cursor must
|
|
60
|
-
// not depend on that.
|
|
61
|
-
const sorted = [...held].sort((left, right) => left.startSeconds - right.startSeconds);
|
|
62
|
-
assert.deepEqual(bySince(sorted, 2).map((cue) => cue.startSeconds), [300]);
|
|
63
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import test from "node:test";
|
|
3
|
-
import { Container } from "../services/media/container/Container.js";
|
|
4
|
-
|
|
5
|
-
test("a flag the container wrote is carried through, and one it did not is not", () => {
|
|
6
|
-
const banner = [
|
|
7
|
-
{ index: 0, language: "rus", title: "Forced", isDefault: true },
|
|
8
|
-
{ index: 1, language: "eng", title: "SDH", isDefault: true }
|
|
9
|
-
];
|
|
10
|
-
const declared = [
|
|
11
|
-
{ language: "rus", name: "Forced", isDefault: true, declaresDefault: true },
|
|
12
|
-
{ language: "eng", name: "SDH", isDefault: true, declaresDefault: false }
|
|
13
|
-
];
|
|
14
|
-
const merged = Container.mergeSubtitleFlags(banner, declared);
|
|
15
|
-
assert.equal(merged.aligned, true);
|
|
16
|
-
assert.deepEqual(
|
|
17
|
-
merged.tracks.map((track) => [track.isDefault, track.declaresDefault]),
|
|
18
|
-
[[true, true], [true, false]]
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("a file that wrote nothing is reported as having written nothing, though ffmpeg marked everything", () => {
|
|
23
|
-
// This is the case the banner cannot express: `FlagDefault` defaults to 1, so
|
|
24
|
-
// ffmpeg prints `(default)` against every track of a file that chose none.
|
|
25
|
-
const banner = [
|
|
26
|
-
{ index: 0, language: "rus", title: "", isDefault: true },
|
|
27
|
-
{ index: 1, language: "eng", title: "", isDefault: true }
|
|
28
|
-
];
|
|
29
|
-
const declared = [
|
|
30
|
-
{ language: "rus", name: "", isDefault: true, declaresDefault: false },
|
|
31
|
-
{ language: "eng", name: "", isDefault: true, declaresDefault: false }
|
|
32
|
-
];
|
|
33
|
-
const merged = Container.mergeSubtitleFlags(banner, declared);
|
|
34
|
-
assert.equal(merged.aligned, true);
|
|
35
|
-
assert.deepEqual(merged.tracks.map((track) => track.declaresDefault), [false, false]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("the container's own answer overrides the banner's, in both directions", () => {
|
|
39
|
-
const banner = [
|
|
40
|
-
{ index: 0, language: "rus", title: "a", isDefault: true },
|
|
41
|
-
{ index: 1, language: "eng", title: "b", isDefault: false }
|
|
42
|
-
];
|
|
43
|
-
const declared = [
|
|
44
|
-
{ language: "rus", name: "a", isDefault: false, declaresDefault: true },
|
|
45
|
-
{ language: "eng", name: "b", isDefault: true, declaresDefault: true }
|
|
46
|
-
];
|
|
47
|
-
const merged = Container.mergeSubtitleFlags(banner, declared);
|
|
48
|
-
assert.deepEqual(merged.tracks.map((track) => track.isDefault), [false, true]);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("a count that differs means the two readings are not the same list", () => {
|
|
52
|
-
// The container declares a picture track the probe did not report; position
|
|
53
|
-
// is then not the correspondence and nothing may be read across.
|
|
54
|
-
const banner = [{ index: 0, language: "rus", title: "", isDefault: true }];
|
|
55
|
-
const declared = [
|
|
56
|
-
{ language: "rus", name: "", isDefault: false, declaresDefault: true },
|
|
57
|
-
{ language: "eng", name: "", isDefault: true, declaresDefault: true }
|
|
58
|
-
];
|
|
59
|
-
const merged = Container.mergeSubtitleFlags(banner, declared);
|
|
60
|
-
assert.equal(merged.aligned, false);
|
|
61
|
-
assert.match(merged.reason, /declares 2 subtitle tracks and the probe found 1/);
|
|
62
|
-
assert.deepEqual(merged.tracks.map((track) => [track.isDefault, track.declaresDefault]), [[true, false]]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("a pair agreeing on neither language nor name refuses the whole alignment", () => {
|
|
66
|
-
const banner = [
|
|
67
|
-
{ index: 0, language: "rus", title: "", isDefault: true },
|
|
68
|
-
{ index: 1, language: "eng", title: "", isDefault: true }
|
|
69
|
-
];
|
|
70
|
-
const declared = [
|
|
71
|
-
{ language: "eng", name: "", isDefault: true, declaresDefault: true },
|
|
72
|
-
{ language: "rus", name: "", isDefault: false, declaresDefault: true }
|
|
73
|
-
];
|
|
74
|
-
const merged = Container.mergeSubtitleFlags(banner, declared);
|
|
75
|
-
assert.equal(merged.aligned, false);
|
|
76
|
-
assert.deepEqual(merged.tracks.map((track) => track.declaresDefault), [false, false]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("a container that declares nothing leaves the banner alone", () => {
|
|
80
|
-
const banner = [{ index: 0, language: "rus", title: "", isDefault: true }];
|
|
81
|
-
const merged = Container.mergeSubtitleFlags(banner, []);
|
|
82
|
-
assert.equal(merged.aligned, false);
|
|
83
|
-
assert.equal(merged.tracks[0].isDefault, true);
|
|
84
|
-
assert.equal(merged.tracks[0].declaresDefault, false);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("an implicit Matroska English default does not become the subtitle language", () => {
|
|
88
|
-
const banner = [{ index: 0, language: "eng", title: "", isDefault: true }];
|
|
89
|
-
const declared = [{ language: "", languageBcp47: "", declaresLanguage: false, name: "" }];
|
|
90
|
-
|
|
91
|
-
const merged = Container.mergeSubtitleFlags(banner, declared);
|
|
92
|
-
|
|
93
|
-
assert.equal(merged.aligned, true);
|
|
94
|
-
assert.equal(merged.tracks[0].language, "");
|
|
95
|
-
assert.equal(merged.tracks[0].declaresLanguage, false);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("an explicitly declared subtitle language is retained", () => {
|
|
99
|
-
const banner = [{ index: 0, language: "rus", title: "", isDefault: true }];
|
|
100
|
-
const declared = [{ language: "rus", languageBcp47: "", declaresLanguage: true, name: "" }];
|
|
101
|
-
|
|
102
|
-
const merged = Container.mergeSubtitleFlags(banner, declared);
|
|
103
|
-
|
|
104
|
-
assert.equal(merged.tracks[0].language, "rus");
|
|
105
|
-
assert.equal(merged.tracks[0].declaresLanguage, true);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("a name confirms a pairing when the languages are unstated", () => {
|
|
109
|
-
assert.equal(Container.pairingHolds({ language: "und", title: "Forced" }, { language: "", name: "Forced" }), true);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("two tracks that say nothing about themselves do not break the alignment", () => {
|
|
113
|
-
assert.equal(Container.pairingHolds({ language: "und", title: "" }, { language: "", name: "" }), true);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("a stated language that differs is a disagreement", () => {
|
|
117
|
-
assert.equal(Container.pairingHolds({ language: "rus", title: "" }, { language: "eng", name: "" }), false);
|
|
118
|
-
});
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file What the language detector is FED.
|
|
3
|
-
*
|
|
4
|
-
* Field 2026-09-01: a Russian subtitle file was offered to the viewer as
|
|
5
|
-
* `English (Stan WarHammer & Nesitach)`. The detector was not at fault — it was
|
|
6
|
-
* handed the raw `.ass` file, which is half Latin markup, while the markup-free
|
|
7
|
-
* WebVTT it was about to serve sat in the variable beside it. Measured on that
|
|
8
|
-
* file: 5040 Latin characters against 5983 Cyrillic, `franc(the file) = eng`,
|
|
9
|
-
* `franc(the dialogue) = rus`.
|
|
10
|
-
* `research/subtitle-language-ass-markup-2026-09-01.md`.
|
|
11
|
-
*
|
|
12
|
-
* These checks pin the input at each of the three places a language is read.
|
|
13
|
-
*
|
|
14
|
-
* **On the size of the fixtures.** franc's answer among the Cyrillic languages
|
|
15
|
-
* is not stable on a small sample: measured 2026-09-01 by growing one Russian
|
|
16
|
-
* text line by line, it answered `bul` at 129 characters, `srp` at 158, 241 and
|
|
17
|
-
* `bul` again at 292, then `rus` at every length from 337 to 881. So the
|
|
18
|
-
* dialogue here is ~880 Cyrillic characters — past that boundary by a factor of
|
|
19
|
-
* about 2.6, and still an order of magnitude below a real episode's 5983. The
|
|
20
|
-
* fixtures are NOT sized to make these checks pass; they are sized to resemble
|
|
21
|
-
* the thing. That instability is a separate defect and is recorded as one.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import test from "node:test";
|
|
25
|
-
import assert from "node:assert/strict";
|
|
26
|
-
|
|
27
|
-
import { detectLanguage } from "../services/media/tracks/language-detect.js";
|
|
28
|
-
import { SubtitleFileContainer } from "../services/media/container/SubtitleFileContainer.js";
|
|
29
|
-
import { TextSubtitleTrack } from "../services/media/tracks/TextSubtitleTrack.js";
|
|
30
|
-
import { MatroskaContainer } from "../services/media/container/MatroskaContainer.js";
|
|
31
|
-
|
|
32
|
-
/** Varied Russian dialogue, the length a few minutes of an episode carries. */
|
|
33
|
-
const RUSSIAN_DIALOGUE = [
|
|
34
|
-
"Ты видишь их?",
|
|
35
|
-
"Да.",
|
|
36
|
-
"Но не столько вижу, сколько чувствую.",
|
|
37
|
-
"Скорее всего, они будут здесь с минуты на минуту.",
|
|
38
|
-
"Почему господа октябристы решили напасть именно сейчас?",
|
|
39
|
-
"Им никогда не преодолеть эти стены.",
|
|
40
|
-
"Мы держали эту крепость три года и продержим ещё столько же.",
|
|
41
|
-
"Готовьте лучников на восточной стороне.",
|
|
42
|
-
"Если они подойдут ближе, мы откроем огонь без предупреждения.",
|
|
43
|
-
"Я не собираюсь умирать здесь, в этой богом забытой дыре.",
|
|
44
|
-
"Тогда возьми меч и вставай рядом со мной.",
|
|
45
|
-
"Сколько у нас осталось воды и хлеба?",
|
|
46
|
-
"На неделю, если не считать раненых.",
|
|
47
|
-
"Раненых считать придётся, они тоже люди.",
|
|
48
|
-
"Отправь гонца к южным воротам и передай приказ отступать.",
|
|
49
|
-
"Он не успеет, дорога перерезана ещё вчера вечером.",
|
|
50
|
-
"Значит пойду сам, а ты останешься за меня командовать.",
|
|
51
|
-
"Это безумие, и ты прекрасно об этом знаешь.",
|
|
52
|
-
"Безумие — это сидеть и ждать, пока нас перебьют по одному.",
|
|
53
|
-
"Хорошо. Но возьми с собой хотя бы двоих.",
|
|
54
|
-
"Двоих я возьму. Больше не могу себе позволить.",
|
|
55
|
-
"Береги себя. Мы будем держать стену до последнего.",
|
|
56
|
-
"Я знаю. Именно поэтому я и ухожу спокойно.",
|
|
57
|
-
"Смотри, дым над лесом. Они уже жгут деревни.",
|
|
58
|
-
"Тогда времени у нас меньше, чем мы думали."
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
/** `hh:mm:ss.cc` for the ASS `Start`/`End` fields. */
|
|
62
|
-
function assTime(seconds) {
|
|
63
|
-
const mm = String(Math.floor(seconds / 60)).padStart(2, "0");
|
|
64
|
-
const ss = String(seconds % 60).padStart(2, "0");
|
|
65
|
-
return `0:${mm}:${ss}.00`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* An ASS file in the shape a fansub release ships: an Aegisub header, a styles
|
|
70
|
-
* section with English font and style names, and Russian dialogue carrying
|
|
71
|
-
* override groups. Modelled on the field file.
|
|
72
|
-
*/
|
|
73
|
-
const RUSSIAN_ASS = `[Script Info]
|
|
74
|
-
Title: Default Aegisub file
|
|
75
|
-
ScriptType: v4.00+
|
|
76
|
-
PlayResX: 1280
|
|
77
|
-
PlayResY: 720
|
|
78
|
-
Original Translation: Nesitach
|
|
79
|
-
Original Editing: Stan WarHammer
|
|
80
|
-
WrapStyle: 0
|
|
81
|
-
ScaledBorderAndShadow: no
|
|
82
|
-
Video Aspect Ratio: c1.77778
|
|
83
|
-
YCbCr Matrix: TV.601
|
|
84
|
-
Aegisub Video Aspect Ratio: c1.777778
|
|
85
|
-
|
|
86
|
-
[Aegisub Project Garbage]
|
|
87
|
-
Last Style Storage: Default
|
|
88
|
-
Audio File: [HorribleSubs] Drifters - 03 [720p].mkv
|
|
89
|
-
Video File: [HorribleSubs] Drifters - 03 [720p].mkv
|
|
90
|
-
Video AR Mode: 4
|
|
91
|
-
Video AR Value: 1.777778
|
|
92
|
-
Video Zoom Percent: 0.600000
|
|
93
|
-
Scroll Position: 256
|
|
94
|
-
Active Line: 257
|
|
95
|
-
Video Position: 33159
|
|
96
|
-
|
|
97
|
-
[V4+ Styles]
|
|
98
|
-
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
|
|
99
|
-
Style: Default,Trebuchet MS,54,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2.5,1.5,2,20,20,25,1
|
|
100
|
-
Style: Signs,Times New Roman,48,&H00FFFF00,&H000000FF,&H00202020,&H00000000,-1,0,0,0,100,100,0,0,1,2,1,8,20,20,20,1
|
|
101
|
-
Style: Italics,Trebuchet MS Italic,54,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,-1,0,0,100,100,0,0,1,2.5,1.5,2,20,20,25,1
|
|
102
|
-
|
|
103
|
-
[Events]
|
|
104
|
-
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
|
105
|
-
${RUSSIAN_DIALOGUE.map((line, index) => {
|
|
106
|
-
const style = index % 7 === 6 ? "Signs" : "Default";
|
|
107
|
-
const tag = index % 5 === 4 ? "{\\pos(640,620)}" : "";
|
|
108
|
-
return `Dialogue: 0,${assTime(index * 4)},${assTime(index * 4 + 3)},${style},,0,0,0,,${tag}${line}`;
|
|
109
|
-
}).join("\n")}
|
|
110
|
-
`;
|
|
111
|
-
|
|
112
|
-
test("a Russian .ass is reported as Russian, and its markup does not reach the detector", () => {
|
|
113
|
-
const vtt = SubtitleFileContainer.toVtt(RUSSIAN_ASS, ".ass");
|
|
114
|
-
assert.ok(vtt.startsWith("WEBVTT"), "the conversion produced a WebVTT document");
|
|
115
|
-
|
|
116
|
-
const spoken = TextSubtitleTrack.cueTextOfVtt(vtt);
|
|
117
|
-
// Every one of these is a piece of the file the viewer never reads, and each
|
|
118
|
-
// was competing with the dialogue for the detector's answer.
|
|
119
|
-
for (const markup of [
|
|
120
|
-
"Aegisub", "Script Info", "V4+ Styles", "Format:", "Dialogue:",
|
|
121
|
-
"Trebuchet MS", "Times New Roman", "Default", "Signs", "pos(",
|
|
122
|
-
"-->", "0:00:12"
|
|
123
|
-
]) {
|
|
124
|
-
assert.ok(!spoken.includes(markup), `cue text still carries "${markup}"`);
|
|
125
|
-
}
|
|
126
|
-
assert.ok(spoken.includes("Ты видишь их?"), "cue text keeps the dialogue");
|
|
127
|
-
|
|
128
|
-
assert.deepEqual(TextSubtitleTrack.detectLanguageFromVtt(vtt), { code: "ru", name: "Russian" });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test("the fixture is the hard case: the file itself is nearly half Latin", () => {
|
|
132
|
-
// Not an assertion about franc — an assertion that this fixture reproduces the
|
|
133
|
-
// field file's proportions. A fixture whose markup were negligible would pass
|
|
134
|
-
// the check above with or without the fix.
|
|
135
|
-
const cyrillic = (RUSSIAN_ASS.match(/[Ѐ-ӿ]/gu) ?? []).length;
|
|
136
|
-
const latin = (RUSSIAN_ASS.match(/[A-Za-z]/g) ?? []).length;
|
|
137
|
-
assert.ok(cyrillic > 800, `too little dialogue: ${cyrillic} Cyrillic characters`);
|
|
138
|
-
assert.ok(latin > cyrillic * 0.5, `markup too small to reproduce the fault: ${latin} vs ${cyrillic}`);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test("cue identifiers, NOTE, STYLE and REGION blocks are not text", () => {
|
|
142
|
-
const vtt = [
|
|
143
|
-
"WEBVTT - This file has cues.",
|
|
144
|
-
"Kind: captions",
|
|
145
|
-
"Language: en",
|
|
146
|
-
"",
|
|
147
|
-
"NOTE",
|
|
148
|
-
"Translated by an English speaking volunteer, all rights reserved.",
|
|
149
|
-
"",
|
|
150
|
-
"STYLE",
|
|
151
|
-
"::cue { background-image: linear-gradient(to bottom, dimgray, lightgray); }",
|
|
152
|
-
"",
|
|
153
|
-
"REGION",
|
|
154
|
-
"id:speaker width:40% lines:3 regionanchor:0%,100%",
|
|
155
|
-
"",
|
|
156
|
-
"opening-line",
|
|
157
|
-
"00:00:12.060 --> 00:00:13.270 align:start position:0%",
|
|
158
|
-
"<v Тоёхиса>Ты видишь их?</v>",
|
|
159
|
-
"",
|
|
160
|
-
"2",
|
|
161
|
-
"00:00:15.400 --> 00:00:16.650",
|
|
162
|
-
"<i>Но не столько вижу,</i>",
|
|
163
|
-
"сколько чувствую & ощущаю.",
|
|
164
|
-
""
|
|
165
|
-
].join("\n");
|
|
166
|
-
|
|
167
|
-
const spoken = TextSubtitleTrack.cueTextOfVtt(vtt);
|
|
168
|
-
assert.equal(
|
|
169
|
-
spoken,
|
|
170
|
-
"Ты видишь их?\nНо не столько вижу,\nсколько чувствую ощущаю."
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test("a document with no cues yields no language rather than a guess", () => {
|
|
175
|
-
assert.equal(TextSubtitleTrack.cueTextOfVtt("WEBVTT\n"), "");
|
|
176
|
-
assert.equal(TextSubtitleTrack.detectLanguageFromVtt("WEBVTT\n"), null);
|
|
177
|
-
assert.equal(TextSubtitleTrack.detectLanguageFromVtt(null), null);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("an embedded ASS cue is unframed by the container, then read", () => {
|
|
181
|
-
// What a Matroska block actually holds, per
|
|
182
|
-
// `matroska.org/technical/subtitles.html`: "Events are stored in the Block in
|
|
183
|
-
// this order: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV,
|
|
184
|
-
// Effect, Text", with Start and End taken out into the block's own timing.
|
|
185
|
-
// Eight fields, and the earlier fixture here wrongly carried ten — it kept
|
|
186
|
-
// the two timestamps a FILE has, which is why it passed while the field
|
|
187
|
-
// subtitles of a real `.mkv` were shown to the viewer whole.
|
|
188
|
-
const blocks = RUSSIAN_DIALOGUE.map((line, index) => Buffer.from(
|
|
189
|
-
`${index + 1},0,Default,,0000,0000,0000,,` +
|
|
190
|
-
`${index % 5 === 4 ? "{\\pos(640,620)}" : ""}${line}`,
|
|
191
|
-
"utf8"
|
|
192
|
-
));
|
|
193
|
-
|
|
194
|
-
const cues = blocks.map((payload, index) => ({
|
|
195
|
-
startSeconds: index * 4,
|
|
196
|
-
endSeconds: index * 4 + 3,
|
|
197
|
-
text: MatroskaContainer.cueTextOf(payload, "S_TEXT/ASS")
|
|
198
|
-
}));
|
|
199
|
-
|
|
200
|
-
const spoken = TextSubtitleTrack.finalizeCues(cues, "S_TEXT/ASS").map((cue) => cue.text).join("\n");
|
|
201
|
-
assert.ok(!spoken.includes("Default"), "the style field survived into the text");
|
|
202
|
-
assert.ok(!spoken.includes("0000"), "a margin field survived into the text");
|
|
203
|
-
assert.ok(!spoken.includes("pos("), "an override group survived into the text");
|
|
204
|
-
assert.deepEqual(detectLanguage(spoken), { code: "ru", name: "Russian" });
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
test("too little text is answered with nothing, not with a guess", () => {
|
|
208
|
-
// Measured 2026-09-02 (`research/franc-boundary-2026-09-02.md`): franc's
|
|
209
|
-
// answer for Russian walks between Bulgarian, Serbian and Russian until about
|
|
210
|
-
// 650 characters. Below that the honest answer is none — the browser then
|
|
211
|
-
// shows "Unknown", and the label moves when enough of the file has arrived.
|
|
212
|
-
const short = RUSSIAN_DIALOGUE.slice(0, 6).join("\n");
|
|
213
|
-
assert.ok(short.length < 300, `the fixture must be short: ${short.length}`);
|
|
214
|
-
assert.equal(detectLanguage(short), null);
|
|
215
|
-
|
|
216
|
-
const long = RUSSIAN_DIALOGUE.join("\n");
|
|
217
|
-
assert.ok(long.length > 650, `the fixture must be long enough: ${long.length}`);
|
|
218
|
-
assert.deepEqual(detectLanguage(long), { code: "ru", name: "Russian" });
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test("an answer that does not survive losing half the text is not an answer", () => {
|
|
222
|
-
// A file carrying two languages — a bilingual release, or a track that turns
|
|
223
|
-
// into signs-only English partway. franc answers something for the whole; the
|
|
224
|
-
// halves disagree with it, and that disagreement is the text saying the
|
|
225
|
-
// answer rests on where it happened to be cut.
|
|
226
|
-
const english = [
|
|
227
|
-
"Do you see them out there beyond the wall?",
|
|
228
|
-
"I do, though not as clearly as I would like to.",
|
|
229
|
-
"They have been gathering since the morning came.",
|
|
230
|
-
"We should send word to the southern gate at once.",
|
|
231
|
-
"The road was cut yesterday and no rider will pass.",
|
|
232
|
-
"Then we hold what we have and wait for the dawn."
|
|
233
|
-
].join("\n");
|
|
234
|
-
const mixed = `${RUSSIAN_DIALOGUE.slice(0, 13).join("\n")}\n${english}`;
|
|
235
|
-
assert.equal(detectLanguage(mixed), null);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
test("a WebVTT body is decoded whole, so no character is cut in half", () => {
|
|
239
|
-
// The ffmpeg extraction path used to detect on `String(body.subarray(0, 4096))`.
|
|
240
|
-
// Two faults: a byte cut lands mid-character on any non-Latin track, and most
|
|
241
|
-
// of those bytes are timestamps rather than words. Cyrillic is two bytes per
|
|
242
|
-
// character in UTF-8, so 4096 bytes of this document is a few hundred
|
|
243
|
-
// characters of dialogue — inside the unstable region measured above.
|
|
244
|
-
const cues = RUSSIAN_DIALOGUE.map((line, index) => {
|
|
245
|
-
const start = `00:00:${String(index * 2).padStart(2, "0")}.000`;
|
|
246
|
-
const end = `00:00:${String(index * 2 + 1).padStart(2, "0")}.000`;
|
|
247
|
-
return `${start} --> ${end}\n${line}`;
|
|
248
|
-
});
|
|
249
|
-
const body = Buffer.from(`WEBVTT\n\n${cues.join("\n\n")}\n`, "utf8");
|
|
250
|
-
|
|
251
|
-
assert.deepEqual(TextSubtitleTrack.detectLanguageFromVtt(body.toString("utf8")), { code: "ru", name: "Russian" });
|
|
252
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { SubtitleFileContainer } from "../services/media/container/SubtitleFileContainer.js";
|
|
4
|
-
|
|
5
|
-
const ass = `[Script Info]\nTitle: Princess Mononoke\nYear: 1997\nMovie Title: Princess Mononoke\nScript Updated By: 2026\n\n[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\nDialogue: 0,0:00:01.00,0:00:02.00,Default,,0,0,0,,Hello`;
|
|
6
|
-
test("ASS header evidence survives conversion without changing cues", () => {
|
|
7
|
-
const vtt = SubtitleFileContainer.toVtt(ass, ".ass");
|
|
8
|
-
const json = vtt.match(/NOTE TORRENT-TV-METADATA\n([^\n]+)/u)[1];
|
|
9
|
-
assert.deepEqual(JSON.parse(json), { titles: ["Princess Mononoke"], genericTitles: ["Princess Mononoke"], years: [1997] });
|
|
10
|
-
assert.match(vtt, /00:00:01.000 --> 00:00:02.000\nHello/u);
|
|
11
|
-
});
|
|
12
|
-
test("metadata is bounded and dialogue is not scanned", () => {
|
|
13
|
-
const vtt = SubtitleFileContainer.toVtt(ass.replace("[Script Info]", "[Other]").replace("Hello", "Movie Title: Another film"), ".ass");
|
|
14
|
-
assert.equal(vtt.includes("NOTE TORRENT-TV-METADATA"), false);
|
|
15
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The subtitle plan is kept only once it has been read; a plan whose
|
|
3
|
-
* read finishes later serves the same pass; and cues the container takes back
|
|
4
|
-
* leave by the numbers they were sent under.
|
|
5
|
-
*
|
|
6
|
-
* Fakes only: a stand-in container and a held file of plain functions.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import test from "node:test";
|
|
10
|
-
import assert from "node:assert/strict";
|
|
11
|
-
|
|
12
|
-
import { cuesHeldFor, forgetSubtitles, subtitleTracksOf, warmSubtitleCues } from "../services/media/SubtitleCues.js";
|
|
13
|
-
import { BytesUnavailable } from "../services/media/container/unavailable.js";
|
|
14
|
-
|
|
15
|
-
const PLAN = {
|
|
16
|
-
tracks: [{ trackNumber: 2, declaredIndex: 0, codecId: "S_TEXT/UTF8", language: "eng", languageSource: "default", clusterPositions: [] }],
|
|
17
|
-
declared: [],
|
|
18
|
-
secondsPerTick: 0.001,
|
|
19
|
-
segmentDataOffset: 0
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function heldFile(sourceKey, container) {
|
|
23
|
-
return {
|
|
24
|
-
sourceKey,
|
|
25
|
-
fileIndex: 0,
|
|
26
|
-
name: "film.mkv",
|
|
27
|
-
length: 1000,
|
|
28
|
-
container: async () => container(),
|
|
29
|
-
heldRanges: async () => [[0, 999]],
|
|
30
|
-
readHeld: async () => Buffer.alloc(0)
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
test("a plan whose bytes have not arrived is not kept; the next ask reads it", async () => {
|
|
35
|
-
const sourceKey = "p".repeat(40);
|
|
36
|
-
forgetSubtitles(sourceKey);
|
|
37
|
-
let here = false;
|
|
38
|
-
const container = () => {
|
|
39
|
-
if (!here) {
|
|
40
|
-
throw new BytesUnavailable(900, 999, 0);
|
|
41
|
-
}
|
|
42
|
-
return { readSubtitlePlan: async () => PLAN, readHeldCues: async () => ({ found: new Map(), covered: 0, indexed: 0, withdrawn: [] }) };
|
|
43
|
-
};
|
|
44
|
-
try {
|
|
45
|
-
assert.deepEqual(await subtitleTracksOf(heldFile(sourceKey, container)), []);
|
|
46
|
-
here = true;
|
|
47
|
-
const tracks = await subtitleTracksOf(heldFile(sourceKey, container));
|
|
48
|
-
assert.deepEqual(tracks.map((track) => [track.trackNumber, track.language, track.languageSource]), [[2, "eng", "default"]]);
|
|
49
|
-
} finally {
|
|
50
|
-
forgetSubtitles(sourceKey);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("a plan read that finishes later serves the pass that asked, with no further arrival", async () => {
|
|
55
|
-
const sourceKey = "q".repeat(40);
|
|
56
|
-
forgetSubtitles(sourceKey);
|
|
57
|
-
let release;
|
|
58
|
-
let walks = 0;
|
|
59
|
-
const arrived = new Promise((resolve) => {
|
|
60
|
-
release = resolve;
|
|
61
|
-
});
|
|
62
|
-
const container = {
|
|
63
|
-
readSubtitlePlan: async () => {
|
|
64
|
-
await arrived;
|
|
65
|
-
return PLAN;
|
|
66
|
-
},
|
|
67
|
-
// A cluster is read once: the first pass finds the line, later ones nothing.
|
|
68
|
-
readHeldCues: async () => {
|
|
69
|
-
walks += 1;
|
|
70
|
-
return {
|
|
71
|
-
found: walks === 1 ? new Map([[2, [{ startSeconds: 1, endSeconds: 2, text: "line", source: 77 }]]]) : new Map(),
|
|
72
|
-
covered: 1,
|
|
73
|
-
indexed: 1,
|
|
74
|
-
withdrawn: []
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
try {
|
|
79
|
-
// The file is one somebody asked about: a browser's seed is under way.
|
|
80
|
-
const seed = cuesHeldFor(heldFile(sourceKey, () => container), 2);
|
|
81
|
-
const warm = warmSubtitleCues(heldFile(sourceKey, () => container));
|
|
82
|
-
release();
|
|
83
|
-
await seed;
|
|
84
|
-
const entries = await warm;
|
|
85
|
-
assert.equal(entries.length, 1, "the one pass pushed what the plan led to");
|
|
86
|
-
assert.deepEqual(entries[0].cues.map((cue) => [cue.text, cue.seq]), [["line", 1]]);
|
|
87
|
-
} finally {
|
|
88
|
-
forgetSubtitles(sourceKey);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("cues read from a position the container withdraws are taken back by their numbers", async () => {
|
|
93
|
-
const sourceKey = "r".repeat(40);
|
|
94
|
-
forgetSubtitles(sourceKey);
|
|
95
|
-
let passNumber = 0;
|
|
96
|
-
const container = {
|
|
97
|
-
readSubtitlePlan: async () => PLAN,
|
|
98
|
-
readHeldCues: async () => {
|
|
99
|
-
passNumber += 1;
|
|
100
|
-
return passNumber === 1
|
|
101
|
-
? {
|
|
102
|
-
found: new Map([[2, [
|
|
103
|
-
{ startSeconds: 1, endSeconds: 2, text: "real", source: 10 },
|
|
104
|
-
{ startSeconds: 3, endSeconds: 4, text: "false", source: 50 }
|
|
105
|
-
]]]),
|
|
106
|
-
covered: 2,
|
|
107
|
-
indexed: 2,
|
|
108
|
-
withdrawn: []
|
|
109
|
-
}
|
|
110
|
-
: { found: new Map(), covered: 1, indexed: 1, withdrawn: [50] };
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
try {
|
|
114
|
-
await subtitleTracksOf(heldFile(sourceKey, () => container));
|
|
115
|
-
const first = await warmSubtitleCues(heldFile(sourceKey, () => container));
|
|
116
|
-
assert.deepEqual(first[0].cues.map((cue) => [cue.text, cue.seq]), [["real", 1], ["false", 2]]);
|
|
117
|
-
const second = await warmSubtitleCues(heldFile(sourceKey, () => container));
|
|
118
|
-
assert.deepEqual(second[0].withdrawn, [2], "the false cue is named by the number it was sent under");
|
|
119
|
-
assert.deepEqual(second[0].cues, []);
|
|
120
|
-
const held = await cuesHeldFor(heldFile(sourceKey, () => container), 2);
|
|
121
|
-
assert.deepEqual(held.cues.map((cue) => cue.text), ["real"], "and it is gone from what is held");
|
|
122
|
-
} finally {
|
|
123
|
-
forgetSubtitles(sourceKey);
|
|
124
|
-
}
|
|
125
|
-
});
|