@torrent-tv/proxy 2.80.18 → 2.81.0

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 (67) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/docs/encode-architecture.md +51 -2
  3. package/package.json +1 -1
  4. package/research/double-spawn-2026-09-10.md +171 -0
  5. package/services/disk/DiskSpace.js +146 -0
  6. package/services/disk/wire.js +60 -0
  7. package/services/encode/EncodeRun.js +37 -9
  8. package/services/encode/SegmentStore.js +284 -232
  9. package/services/encode/run-command.js +16 -1
  10. package/services/hls-session-manager.js +31 -128
  11. package/services/orchestrators/EncodeOrchestrator.js +52 -38
  12. package/services/piece-store/allowance.js +107 -0
  13. package/services/piece-store/piece-disk-store.js +365 -0
  14. package/services/piece-store/shared-piece-store.js +1549 -1535
  15. package/services/segment-formats/fmp4.js +54 -0
  16. package/services/segment-formats/mpegts.js +54 -0
  17. package/services/torrent-worker/client.js +32 -0
  18. package/services/torrent-worker/pool-adapter.js +15 -0
  19. package/services/torrent-worker/protocol.js +9 -0
  20. package/services/torrent-worker/worker.js +8 -1
  21. package/services/viewer/positions.js +48 -0
  22. package/test/audio-inventory.test.js +176 -176
  23. package/test/auto-quality-step.test.js +514 -514
  24. package/test/concurrent-cost.test.js +138 -138
  25. package/test/coverage-follows-the-disk.test.js +191 -187
  26. package/test/coverage-map.test.js +195 -195
  27. package/test/declared-tracks.test.js +35 -35
  28. package/test/disk-space.test.js +138 -0
  29. package/test/encode-orchestrator.test.js +0 -3
  30. package/test/encode-run.test.js +5 -12
  31. package/test/held-request-width.test.js +155 -155
  32. package/test/helpers/encode-run.js +2 -2
  33. package/test/matroska-blocks.test.js +0 -0
  34. package/test/matroska-cues-track.test.js +192 -192
  35. package/test/mp4-composition-times.test.js +0 -0
  36. package/test/mp4-subtitles.test.js +173 -173
  37. package/test/one-authority.test.js +281 -220
  38. package/test/orchestrator-wired.test.js +199 -195
  39. package/test/packet-witness-ring.test.js +236 -236
  40. package/test/packet-witness.test.js +148 -148
  41. package/test/piece-disk-store.test.js +267 -0
  42. package/test/piece-reader.test.js +4 -4
  43. package/test/piece-store-eviction.test.js +17 -17
  44. package/test/piece-store-reservations.test.js +20 -1
  45. package/test/piece-store-slow-disk.test.js +16 -1
  46. package/test/produced-copy-choice.test.js +258 -358
  47. package/test/read-window.test.js +6 -6
  48. package/test/run-intervals.test.js +100 -100
  49. package/test/seek-landing.test.js +109 -109
  50. package/test/segment-serve-wiring.test.js +8 -9
  51. package/test/segment-store-eviction.test.js +232 -0
  52. package/test/segment-store.test.js +238 -216
  53. package/test/segments-are-shared.test.js +1 -1
  54. package/test/shared-piece-store.test.js +12 -12
  55. package/test/sidecar-naming.test.js +142 -142
  56. package/test/subtitle-cue-framing.test.js +200 -200
  57. package/test/subtitle-cue-walk.test.js +369 -369
  58. package/test/subtitle-defaults.test.js +97 -97
  59. package/test/subtitle-track-numbering.test.js +370 -370
  60. package/test/tail-duplication.test.js +167 -167
  61. package/test/tracks-begin-together.test.js +195 -195
  62. package/test/two-viewers-one-picture.test.js +374 -374
  63. package/test/video-facts.test.js +102 -102
  64. package/test/wedge-certainty.test.js +131 -131
  65. package/services/encode/open-piece.js +0 -135
  66. package/services/piece-store/disk-tier.js +0 -151
  67. package/test/open-piece.test.js +0 -152
@@ -1,142 +1,142 @@
1
- /**
2
- * @file What a torrent's own names say about a track shipped as its own file.
3
- *
4
- * The rule worth pinning is the releaser one, because getting it wrong invents
5
- * an author. In the field case — `[HorribleSubs] Drifters - 02 [1080p].mka` in
6
- * `Rus Sound/`, beside `[HorribleSubs] Drifters - 02 [1080p].mkv` — the dub
7
- * carries the picture's own brackets and nothing else, so there is nothing
8
- * truthful to say about who made it. The subtitles of the same release sit in
9
- * `Sub/[Stan WarHammer & Nesitach]/`, a bracket the picture does not carry, and
10
- * that one IS their author.
11
- */
12
-
13
- import test from "node:test";
14
- import assert from "node:assert/strict";
15
- import {
16
- languageFromFolderNames,
17
- releaserFrom,
18
- sidecarNaming
19
- } from "../services/torrent/naming.js";
20
- /**
21
- * Read a whole path, the way the pairing does. `code` is `"und"` where nothing
22
- * was read, and `group` is what the browser calls the releaser.
23
- *
24
- * @param {string} relativePath
25
- * @param {string} [videoName]
26
- * @returns {{ code: string, group: string | null }}
27
- */
28
- function readPath(relativePath, videoName = "") {
29
- const parts = String(relativePath).split("/");
30
- const naming = sidecarNaming({
31
- folders: parts.slice(0, -1),
32
- fileName: parts[parts.length - 1],
33
- videoName
34
- });
35
- return { ...naming, code: naming.code ?? "und", group: naming.releaser };
36
- }
37
-
38
-
39
- const VIDEO_NAME = "[HorribleSubs] Drifters - 02 [1080p].mkv";
40
-
41
- test("a folder naming a language is read, whole segment or word", () => {
42
- assert.equal(languageFromFolderNames(["ENG"])?.code, "en");
43
- assert.equal(languageFromFolderNames(["Rus Sound"])?.code, "ru");
44
- assert.equal(languageFromFolderNames(["Sub", "Russian"])?.code, "ru");
45
- assert.equal(languageFromFolderNames([])?.code, undefined);
46
- });
47
-
48
- test("the innermost folder answers first", () => {
49
- assert.equal(languageFromFolderNames(["Russian", "English Dub"])?.code, "en");
50
- });
51
-
52
- test("a two-letter word inside a longer folder name is not taken for a language", () => {
53
- // "No" is Norwegian as a whole segment, but a word in `No Subs` is a word.
54
- assert.equal(languageFromFolderNames(["No Subs"]), null);
55
- assert.equal(languageFromFolderNames(["no"])?.code, "no");
56
- });
57
-
58
- test("a bracket the picture also carries is not the sidecar's author", () => {
59
- assert.equal(
60
- releaserFrom({
61
- folders: ["Rus Sound"],
62
- fileName: "[HorribleSubs] Drifters - 02 [1080p].mka",
63
- videoName: VIDEO_NAME
64
- }),
65
- null
66
- );
67
- });
68
-
69
- test("a bracket only the sidecar carries is its author", () => {
70
- assert.equal(
71
- releaserFrom({
72
- folders: ["Sub", "[Stan WarHammer & Nesitach]"],
73
- fileName: "[HorribleSubs] Drifters - 02 [1080p].ass",
74
- videoName: VIDEO_NAME
75
- }),
76
- "Stan WarHammer & Nesitach"
77
- );
78
- });
79
-
80
- test("a bracket describing the encode is never an author", () => {
81
- for (const token of ["1080p", "x264", "HEVC", "WEB-DL", "AAC", "5.1", "10bit", "78EFD746", "RUS"]) {
82
- assert.equal(
83
- releaserFrom({ folders: [], fileName: `Film [${token}].mka`, videoName: "Other.mkv" }),
84
- null,
85
- `[${token}] should not be read as a releaser`
86
- );
87
- }
88
- });
89
-
90
- test("the innermost folder is preferred to the file name", () => {
91
- assert.equal(
92
- releaserFrom({ folders: ["[TeamA]"], fileName: "[TeamB] ep.ass", videoName: "ep.mkv" }),
93
- "TeamA"
94
- );
95
- });
96
-
97
- test("language and author together, for the field case", () => {
98
- assert.deepEqual(
99
- sidecarNaming({
100
- folders: ["Rus Sound"],
101
- fileName: "[HorribleSubs] Drifters - 02 [1080p].mka",
102
- videoName: VIDEO_NAME
103
- }),
104
- { code: "ru", name: "Russian", releaser: null, isForced: false, isHearingImpaired: false, isDefault: false }
105
- );
106
- assert.deepEqual(
107
- sidecarNaming({
108
- folders: ["Sub", "[Stan WarHammer & Nesitach]"],
109
- fileName: "[HorribleSubs] Drifters - 02 [1080p].ass",
110
- videoName: VIDEO_NAME
111
- }),
112
- {
113
- code: null,
114
- name: null,
115
- releaser: "Stan WarHammer & Nesitach",
116
- isForced: false,
117
- isHearingImpaired: false,
118
- isDefault: false
119
- }
120
- );
121
- });
122
-
123
- test("a subtitle file takes its author from the folder the release put it in", () => {
124
- const info = readPath("Sub/[Stan WarHammer & Nesitach]/[HorribleSubs] Drifters - 02 [1080p].ass", VIDEO_NAME);
125
- assert.equal(info.group, "Stan WarHammer & Nesitach");
126
- });
127
-
128
- test("the picture's own release group is never reported as the translator", () => {
129
- const info = readPath("Sub/[HorribleSubs] Drifters - 02 [1080p].ass", VIDEO_NAME);
130
- assert.equal(info.group, null);
131
- });
132
-
133
- test("the language of a subtitle folder is read where the whole segment is not a language", () => {
134
- const info = readPath("Rus Sub/ep.srt", "ep.mkv");
135
- assert.equal(info.code, "ru");
136
- });
137
-
138
- test("what the rules answer with nothing to go on", () => {
139
- const info = readPath("ep.srt");
140
- assert.equal(info.code, "und");
141
- assert.equal(info.group, null);
142
- });
1
+ /**
2
+ * @file What a torrent's own names say about a track shipped as its own file.
3
+ *
4
+ * The rule worth pinning is the releaser one, because getting it wrong invents
5
+ * an author. In the field case — `[HorribleSubs] Drifters - 02 [1080p].mka` in
6
+ * `Rus Sound/`, beside `[HorribleSubs] Drifters - 02 [1080p].mkv` — the dub
7
+ * carries the picture's own brackets and nothing else, so there is nothing
8
+ * truthful to say about who made it. The subtitles of the same release sit in
9
+ * `Sub/[Stan WarHammer & Nesitach]/`, a bracket the picture does not carry, and
10
+ * that one IS their author.
11
+ */
12
+
13
+ import test from "node:test";
14
+ import assert from "node:assert/strict";
15
+ import {
16
+ languageFromFolderNames,
17
+ releaserFrom,
18
+ sidecarNaming
19
+ } from "../services/torrent/naming.js";
20
+ /**
21
+ * Read a whole path, the way the pairing does. `code` is `"und"` where nothing
22
+ * was read, and `group` is what the browser calls the releaser.
23
+ *
24
+ * @param {string} relativePath
25
+ * @param {string} [videoName]
26
+ * @returns {{ code: string, group: string | null }}
27
+ */
28
+ function readPath(relativePath, videoName = "") {
29
+ const parts = String(relativePath).split("/");
30
+ const naming = sidecarNaming({
31
+ folders: parts.slice(0, -1),
32
+ fileName: parts[parts.length - 1],
33
+ videoName
34
+ });
35
+ return { ...naming, code: naming.code ?? "und", group: naming.releaser };
36
+ }
37
+
38
+
39
+ const VIDEO_NAME = "[HorribleSubs] Drifters - 02 [1080p].mkv";
40
+
41
+ test("a folder naming a language is read, whole segment or word", () => {
42
+ assert.equal(languageFromFolderNames(["ENG"])?.code, "en");
43
+ assert.equal(languageFromFolderNames(["Rus Sound"])?.code, "ru");
44
+ assert.equal(languageFromFolderNames(["Sub", "Russian"])?.code, "ru");
45
+ assert.equal(languageFromFolderNames([])?.code, undefined);
46
+ });
47
+
48
+ test("the innermost folder answers first", () => {
49
+ assert.equal(languageFromFolderNames(["Russian", "English Dub"])?.code, "en");
50
+ });
51
+
52
+ test("a two-letter word inside a longer folder name is not taken for a language", () => {
53
+ // "No" is Norwegian as a whole segment, but a word in `No Subs` is a word.
54
+ assert.equal(languageFromFolderNames(["No Subs"]), null);
55
+ assert.equal(languageFromFolderNames(["no"])?.code, "no");
56
+ });
57
+
58
+ test("a bracket the picture also carries is not the sidecar's author", () => {
59
+ assert.equal(
60
+ releaserFrom({
61
+ folders: ["Rus Sound"],
62
+ fileName: "[HorribleSubs] Drifters - 02 [1080p].mka",
63
+ videoName: VIDEO_NAME
64
+ }),
65
+ null
66
+ );
67
+ });
68
+
69
+ test("a bracket only the sidecar carries is its author", () => {
70
+ assert.equal(
71
+ releaserFrom({
72
+ folders: ["Sub", "[Stan WarHammer & Nesitach]"],
73
+ fileName: "[HorribleSubs] Drifters - 02 [1080p].ass",
74
+ videoName: VIDEO_NAME
75
+ }),
76
+ "Stan WarHammer & Nesitach"
77
+ );
78
+ });
79
+
80
+ test("a bracket describing the encode is never an author", () => {
81
+ for (const token of ["1080p", "x264", "HEVC", "WEB-DL", "AAC", "5.1", "10bit", "78EFD746", "RUS"]) {
82
+ assert.equal(
83
+ releaserFrom({ folders: [], fileName: `Film [${token}].mka`, videoName: "Other.mkv" }),
84
+ null,
85
+ `[${token}] should not be read as a releaser`
86
+ );
87
+ }
88
+ });
89
+
90
+ test("the innermost folder is preferred to the file name", () => {
91
+ assert.equal(
92
+ releaserFrom({ folders: ["[TeamA]"], fileName: "[TeamB] ep.ass", videoName: "ep.mkv" }),
93
+ "TeamA"
94
+ );
95
+ });
96
+
97
+ test("language and author together, for the field case", () => {
98
+ assert.deepEqual(
99
+ sidecarNaming({
100
+ folders: ["Rus Sound"],
101
+ fileName: "[HorribleSubs] Drifters - 02 [1080p].mka",
102
+ videoName: VIDEO_NAME
103
+ }),
104
+ { code: "ru", name: "Russian", releaser: null, isForced: false, isHearingImpaired: false, isDefault: false }
105
+ );
106
+ assert.deepEqual(
107
+ sidecarNaming({
108
+ folders: ["Sub", "[Stan WarHammer & Nesitach]"],
109
+ fileName: "[HorribleSubs] Drifters - 02 [1080p].ass",
110
+ videoName: VIDEO_NAME
111
+ }),
112
+ {
113
+ code: null,
114
+ name: null,
115
+ releaser: "Stan WarHammer & Nesitach",
116
+ isForced: false,
117
+ isHearingImpaired: false,
118
+ isDefault: false
119
+ }
120
+ );
121
+ });
122
+
123
+ test("a subtitle file takes its author from the folder the release put it in", () => {
124
+ const info = readPath("Sub/[Stan WarHammer & Nesitach]/[HorribleSubs] Drifters - 02 [1080p].ass", VIDEO_NAME);
125
+ assert.equal(info.group, "Stan WarHammer & Nesitach");
126
+ });
127
+
128
+ test("the picture's own release group is never reported as the translator", () => {
129
+ const info = readPath("Sub/[HorribleSubs] Drifters - 02 [1080p].ass", VIDEO_NAME);
130
+ assert.equal(info.group, null);
131
+ });
132
+
133
+ test("the language of a subtitle folder is read where the whole segment is not a language", () => {
134
+ const info = readPath("Rus Sub/ep.srt", "ep.mkv");
135
+ assert.equal(info.code, "ru");
136
+ });
137
+
138
+ test("what the rules answer with nothing to go on", () => {
139
+ const info = readPath("ep.srt");
140
+ assert.equal(info.code, "und");
141
+ assert.equal(info.group, null);
142
+ });