@torrent-tv/proxy 2.87.3 → 2.87.5

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/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@torrent-tv/proxy",
3
- "version": "2.87.3",
4
- "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
- "license": "GPL-3.0-or-later",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "type": "module",
10
- "engines": {
11
- "node": ">=24"
12
- },
13
- "bin": {
14
- "torrent-tv-proxy": "./bin/cli.js"
15
- },
16
- "scripts": {
17
- "patch": "npm whoami && npm version patch && npm publish && git push --follow-tags",
18
- "minor": "npm whoami && npm version minor && npm publish && git push --follow-tags",
19
- "major": "npm whoami && npm version major && npm publish && git push --follow-tags",
20
- "start": "node ./bin/cli.js",
21
- "dev": "node --inspect=0 --experimental-network-inspection ./bin/cli.js",
22
- "test": "npm run lint && node --test",
23
- "graph": "node scripts/render-run-graph.js",
24
- "lint": "biome lint ."
25
- },
26
- "dependencies": {
27
- "@fastify/cors": "^11.2.0",
28
- "@fastify/helmet": "^13.0.2",
29
- "@fastify/static": "^10.1.2",
30
- "@silentbot1/nat-api": "^0.4.9",
31
- "chalk": "^5.4.1",
32
- "commander": "^12.1.0",
33
- "fastify": "^5.8.5",
34
- "ffmpeg-static": "^5.3.0",
35
- "franc": "^6.2.0",
36
- "get-port": "^7.1.0",
37
- "node-datachannel": "^0.32.0",
38
- "parse-torrent": "^11.0.23",
39
- "uint8-util": "2.2.6",
40
- "webtorrent": "2.8.5",
41
- "werift": "^0.24.2",
42
- "ws": "^8.18.2"
43
- },
44
- "devDependencies": {
45
- "@biomejs/biome": "^2.5.7"
46
- },
47
- "overrides": {
48
- "utp-native": "npm:@torrent-tv/utp-native@2.5.3-ttv.8"
49
- }
50
- }
1
+ {
2
+ "name": "@torrent-tv/proxy",
3
+ "version": "2.87.5",
4
+ "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
+ "license": "GPL-3.0-or-later",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "type": "module",
10
+ "engines": {
11
+ "node": ">=24"
12
+ },
13
+ "bin": {
14
+ "torrent-tv-proxy": "./bin/cli.js"
15
+ },
16
+ "scripts": {
17
+ "patch": "npm whoami && npm version patch && npm publish && git push --follow-tags",
18
+ "minor": "npm whoami && npm version minor && npm publish && git push --follow-tags",
19
+ "major": "npm whoami && npm version major && npm publish && git push --follow-tags",
20
+ "start": "node ./bin/cli.js",
21
+ "dev": "node --inspect=0 --experimental-network-inspection ./bin/cli.js",
22
+ "test": "npm run lint && node --test",
23
+ "graph": "node scripts/render-run-graph.js",
24
+ "lint": "biome lint ."
25
+ },
26
+ "dependencies": {
27
+ "@fastify/cors": "^11.2.0",
28
+ "@fastify/helmet": "^13.0.2",
29
+ "@fastify/static": "^10.1.2",
30
+ "@silentbot1/nat-api": "^0.4.9",
31
+ "chalk": "^5.4.1",
32
+ "commander": "^12.1.0",
33
+ "fastify": "^5.8.5",
34
+ "ffmpeg-static": "^5.3.0",
35
+ "franc": "^6.2.0",
36
+ "get-port": "^7.1.0",
37
+ "node-datachannel": "^0.32.0",
38
+ "parse-torrent": "^11.0.23",
39
+ "uint8-util": "2.2.6",
40
+ "webtorrent": "2.8.5",
41
+ "werift": "^0.24.2",
42
+ "ws": "^8.18.2"
43
+ },
44
+ "devDependencies": {
45
+ "@biomejs/biome": "^2.5.7"
46
+ },
47
+ "overrides": {
48
+ "utp-native": "npm:@torrent-tv/utp-native@2.5.3-ttv.8"
49
+ }
50
+ }
@@ -31,6 +31,6 @@ export async function handleApiSourcesPost(req, reply, { sourceRegistry }) {
31
31
  return reply.code(400).send({ error: "sourceType and source are required." });
32
32
  }
33
33
 
34
- const sourceKey = sourceRegistry.upsert(sourceType, source);
34
+ const sourceKey = await sourceRegistry.upsert(sourceType, source);
35
35
  return reply.send({ sourceKey });
36
36
  }
@@ -1,181 +1,217 @@
1
- import { logger } from "../../../../utils/logger.js";
2
- import { TEXT_SUBTITLE_SIDECAR_EXTENSIONS } from "../../../../services/torrent/files.js";
3
- import { contentsOf } from "../../../../services/torrent/Contents.js";
4
-
5
- /**
6
- * Start fetching a source before anyone asks to play it.
7
- *
8
- * POST /api/sources/:sourceKey/warm { fileIndex?: number }
9
- *
10
- * Everything a torrent must do before the first byte of video can be served
11
- * takes seconds and none of it depends on the viewer: announce to the
12
- * trackers, connect to peers, be unchoked by them, and fetch the two pieces at
13
- * the file's edges that the codec probe reads. Measured 2026-08-04 on a cold
14
- * 7.4 GB torrent: 6.7 s of the 10.3 s before playback was those two pieces
15
- * arriving, with the swarm ramping from nothing.
16
- *
17
- * That work used to begin only when a file had been chosen, because it was
18
- * buried inside the playback plan. It can begin as soon as the viewer has
19
- * picked a TORRENT — while they are still reading the list of episodes — and
20
- * then most or all of it has happened by the time they choose.
21
- *
22
- * Returns as soon as the work is under way. The caller is not waiting for a
23
- * result; it is only saying "you may start". Failures are logged and answered
24
- * as `started: false` rather than as an error, because nothing is broken if a
25
- * warm-up does not happen — the ordinary path still does all of it.
26
- *
27
- * @param {import("fastify").FastifyRequest} req
28
- * @param {import("fastify").FastifyReply} reply
29
- * @param {{
30
- * sourceRegistry: ReturnType<import("../../../../store/source-registry.js").createSourceRegistry>,
31
- * torrentPool: import("../../../../services/torrent/torrent-pool.js").TorrentPool
32
- * }} deps
33
- * @returns {Promise<void>}
34
- */
35
- export async function handleApiSourceWarmPost(req, reply, { sourceRegistry, torrentPool, durationOf = null }) {
36
- const sourceKey = typeof req.params.sourceKey === "string" ? req.params.sourceKey.trim() : "";
37
- if (!sourceKey) {
38
- return reply.code(400).send({ error: "sourceKey is required." });
39
- }
40
-
41
- const sourceRecord = sourceRegistry.get(sourceKey);
42
- if (!sourceRecord) {
43
- return reply.code(404).send({ error: "Source key was not found." });
44
- }
45
-
46
- const body = req.body && typeof req.body === "object" && !Array.isArray(req.body) ? req.body : {};
47
- const requestedIndex = Number(body.fileIndex);
48
- const fileIndex = Number.isInteger(requestedIndex) && requestedIndex >= 0 ? requestedIndex : null;
49
- // Where the viewer is about to resume, if they are resuming. The edges below
50
- // are what the codec probe reads; this is what the VIEWER will read, and until
51
- // now nothing asked for it before the encoder did.
52
- const requestedPosition = Number(body.positionSeconds);
53
- const positionSeconds = Number.isFinite(requestedPosition) && requestedPosition > 0
54
- ? requestedPosition
55
- : 0;
56
-
57
- // Adding the torrent is what announces to the trackers and starts connecting
58
- // to peers, and it is also what a magnet needs in order to fetch its
59
- // metadata. It is awaited because everything else needs the torrent object,
60
- // and because until it resolves there is nothing to report.
61
- let torrent;
62
- try {
63
- torrent = await torrentPool.getTorrent(sourceRecord.sourceType, sourceRecord.source);
64
- } catch (error) {
65
- const message = error instanceof Error ? error.message : String(error);
66
- logger.warn(`warm ${sourceKey.slice(0, 8)}: could not add the torrent: ${message}`);
67
- return reply.send({ started: false, swarm: false, edges: false });
68
- }
69
-
70
- // WHICH FILE THIS IS ABOUT. The caller names one when it knows — a torrent
71
- // with a single video, or an episode the viewer has settled on — and on a
72
- // season pack it names none, because nobody has chosen yet.
73
- //
74
- // Then the first item of the torrent stands in for the choice. One item, not
75
- // twenty: warming a whole pack's worth of edges would spend the pool owner's
76
- // bandwidth on nineteen files nobody opened, while one item is two pieces and
77
- // is also the likeliest pick. It is stated as something nobody is waiting
78
- // for, so on a proxy serving somebody else it costs nothing at all until
79
- // their own film has everything it needs.
80
- const contents = contentsOf(torrent);
81
- const named = fileIndex !== null && torrent.files?.[fileIndex] ? fileIndex : null;
82
- const candidate = named ?? contents.items[0]?.fileIndex ?? null;
83
-
84
- let edges = false;
85
- if (candidate !== null) {
86
- edges = true;
87
- // Deliberately not awaited: this is the multi-second part, and the point of
88
- // the whole route is that the viewer goes on choosing while it happens.
89
- Promise.resolve(torrentPool.prefetchFileEdges(torrent, candidate)).catch((error) => {
90
- const message = error instanceof Error ? error.message : String(error);
91
- logger.warn(`warm ${sourceKey.slice(0, 8)}: file edges failed: ${message}`);
92
- });
93
- // Started AFTER the edges, and not awaited by them either: the edges gate
94
- // the playback plan, so they must not queue behind a region nobody is
95
- // reading yet. This one only has to arrive before the encoder does, and the
96
- // encoder is a plan and a session away.
97
- if (named !== null && positionSeconds > 0 && typeof torrentPool.warmResumePosition === "function") {
98
- Promise.resolve(
99
- (typeof durationOf === "function"
100
- ? durationOf({ sourceKey, fileIndex: named })
101
- : Promise.resolve(null)
102
- ).then((durationSeconds) =>
103
- torrentPool.warmResumePosition(torrent, named, positionSeconds, durationSeconds)
104
- )
105
- ).catch(
106
- (error) => {
107
- const message = error instanceof Error ? error.message : String(error);
108
- logger.warn(`warm ${sourceKey.slice(0, 8)}: the viewer's position failed: ${message}`);
109
- }
110
- );
111
- }
112
- }
113
-
114
- // The files that carry this episode's OTHER soundtracks and its subtitles.
115
- //
116
- // Warmed here for the same reason the picture is: none of it depends on the
117
- // viewer, and every second of it that happens now is a second they do not
118
- // spend waiting later. Without this the first thing to ask for a dub's header
119
- // is the playback plan, on the path to the first frame, and the first thing to
120
- // ask for a subtitle file is the browser once the film is already running —
121
- // which is why a track the container marks default appears after the opening
122
- // rather than during it.
123
- //
124
- // How much of each is fetched follows from what the file IS, not from a size
125
- // anyone chose. A text subtitle file is smaller than one piece of this
126
- // torrent, so its edges and the whole of it are the same pieces — fetch all of
127
- // it. A soundtrack is tens of megabytes and only its header is needed to name
128
- // and describe it, so it gets the head and the tail, exactly as the picture
129
- // does. The rest of it is fetched when it is played, and nothing here spends
130
- // the pool owner's bandwidth on a track nobody chose.
131
- let sidecars = 0;
132
- if (candidate !== null && Array.isArray(torrent.files)) {
133
- const matched = contents.sidecarsOf(candidate);
134
- const warmOne = (file, options) => {
135
- sidecars += 1;
136
- // Not awaited, like the picture's own edges above: the point of this route
137
- // is that the viewer goes on choosing while it happens.
138
- Promise.resolve(torrentPool.prefetchFileEdges(torrent, file.fileIndex, options)).catch(
139
- (error) => {
140
- const message = error instanceof Error ? error.message : String(error);
141
- logger.warn(`warm ${sourceKey.slice(0, 8)}: "${file.name}" failed: ${message}`);
142
- }
143
- );
144
- };
145
- for (const file of matched.audio) {
146
- warmOne(file, { tailBytes: 0 });
147
- // And then the whole of it, in the room the viewer's own reading leaves.
148
- // The head is enough to NAME the track; it is not enough to play one, and
149
- // a viewer who switches otherwise waits for the swarm to deliver its
150
- // first pieces — 27.7 s in the field on 2026-08-31, longer than the
151
- // switch is willing to wait. A soundtrack is about a twentieth of the
152
- // picture, and the fill stands aside for every moment the picture's own
153
- // reader is blocked, so it uses capacity the viewer is not using.
154
- if (typeof torrentPool.fillFileInBackground === "function") {
155
- Promise.resolve(torrentPool.fillFileInBackground(torrent, file.fileIndex)).catch((error) => {
156
- const message = error instanceof Error ? error.message : String(error);
157
- logger.warn(`warm ${sourceKey.slice(0, 8)}: filling "${file.name}" failed: ${message}`);
158
- });
159
- }
160
- }
161
- for (const file of matched.subtitles) {
162
- warmOne(
163
- file,
164
- TEXT_SUBTITLE_SIDECAR_EXTENSIONS.has(file.extension)
165
- ? { headBytes: Math.max(1, file.length), tailBytes: 0 }
166
- : { tailBytes: 0 }
167
- );
168
- }
169
- }
170
-
171
- logger.info(
172
- `warm ${sourceKey.slice(0, 8)}: swarm started for "${torrent.name}"` +
173
- (edges
174
- ? `, fetching the edges of file ${candidate}` +
175
- (named === null ? " — the first item, since nothing is chosen yet" : "")
176
- : ", and it holds nothing to fetch the edges of") +
177
- (sidecars > 0 ? ` and of ${sidecars} file(s) beside it` : "")
178
- );
179
-
180
- return reply.send({ started: true, swarm: true, edges, sidecars });
181
- }
1
+ import { logger } from "../../../../utils/logger.js";
2
+ import { TEXT_SUBTITLE_SIDECAR_EXTENSIONS } from "../../../../services/torrent/files.js";
3
+ import { contentsOf } from "../../../../services/torrent/Contents.js";
4
+
5
+ const metadataWarmups = new Map();
6
+ const METADATA_RETRY_MS = 2500;
7
+
8
+ function startMetadataWarmup({ sourceKey, items, preferredFileIndex, userAgent, playbackPlanner, torrentPool, torrent }) {
9
+ if (!playbackPlanner || !Array.isArray(items) || items.length === 0) {
10
+ return false;
11
+ }
12
+ let state = metadataWarmups.get(sourceKey);
13
+ if (!state) {
14
+ state = { pending: new Set(), preferredFileIndex: null, running: false, items: [] };
15
+ metadataWarmups.set(sourceKey, state);
16
+ }
17
+ state.items = items;
18
+ for (const item of items) {
19
+ if (Number.isInteger(item?.fileIndex)) {
20
+ state.pending.add(item.fileIndex);
21
+ }
22
+ }
23
+ if (Number.isInteger(preferredFileIndex) && state.pending.has(preferredFileIndex)) {
24
+ state.preferredFileIndex = preferredFileIndex;
25
+ }
26
+ if (state.running) {
27
+ return true;
28
+ }
29
+ state.running = true;
30
+ void (async () => {
31
+ try {
32
+ while (state.pending.size > 0) {
33
+ const fileIndex = state.preferredFileIndex !== null && state.pending.has(state.preferredFileIndex)
34
+ ? state.preferredFileIndex
35
+ : state.pending.values().next().value;
36
+ state.preferredFileIndex = null;
37
+ if (!Number.isInteger(fileIndex)) {
38
+ break;
39
+ }
40
+ const item = state.items.find((entry) => entry.fileIndex === fileIndex);
41
+ if (!item) {
42
+ state.pending.delete(fileIndex);
43
+ continue;
44
+ }
45
+ const sidecars = contentsOf(torrent).sidecarsOf(fileIndex);
46
+ const sidecarFiles = [...sidecars.audio, ...sidecars.subtitles];
47
+ await Promise.all(sidecarFiles.map((file) =>
48
+ torrentPool.prefetchFileEdges(torrent, file.fileIndex, {
49
+ tailBytes: 0,
50
+ headBytes: TEXT_SUBTITLE_SIDECAR_EXTENSIONS.has(file.extension)
51
+ ? Math.max(1, file.length)
52
+ : undefined,
53
+ timeoutMs: 10_000
54
+ }).catch((error) => {
55
+ logger.info(`warm ${sourceKey.slice(0, 8)}:${fileIndex}: sidecar metadata not ready for "${file.name}": ${error?.message ?? error}`);
56
+ })
57
+ ));
58
+ const plan = await playbackPlanner.getPlan({
59
+ sourceKey,
60
+ fileIndex,
61
+ userAgent,
62
+ maxWaitMs: 0,
63
+ background: true
64
+ }).catch((error) => {
65
+ logger.info(`warm ${sourceKey.slice(0, 8)}:${fileIndex}: media metadata not ready: ${error?.message ?? error}`);
66
+ return null;
67
+ });
68
+ if (plan && !plan.pending) {
69
+ state.pending.delete(fileIndex);
70
+ } else if (torrent.files?.[fileIndex]?.done === true) {
71
+ state.pending.delete(fileIndex);
72
+ }
73
+ if (state.pending.size > 0) {
74
+ await new Promise((resolve) => setTimeout(resolve, METADATA_RETRY_MS));
75
+ }
76
+ }
77
+ } catch (error) {
78
+ logger.warn(`warm ${sourceKey.slice(0, 8)}: metadata queue stopped: ${error?.message ?? error}`);
79
+ } finally {
80
+ state.running = false;
81
+ if (state.pending.size === 0) {
82
+ metadataWarmups.delete(sourceKey);
83
+ }
84
+ }
85
+ })();
86
+ return true;
87
+ }
88
+
89
+ /**
90
+ * Start fetching a source before anyone asks to play it.
91
+ *
92
+ * POST /api/sources/:sourceKey/warm { fileIndex?: number, positionSeconds?: number, userAgent?: string }
93
+ *
94
+ * Everything a torrent must do before the first byte of video can be served
95
+ * takes seconds and none of it depends on the viewer: announce to the
96
+ * trackers, connect to peers, be unchoked by them, and fetch the two pieces at
97
+ * the file's edges that the codec probe reads. Measured 2026-08-04 on a cold
98
+ * 7.4 GB torrent: 6.7 s of the 10.3 s before playback was those two pieces
99
+ * arriving, with the swarm ramping from nothing.
100
+ *
101
+ * That work used to begin only when a file had been chosen, because it was
102
+ * buried inside the playback plan. It can begin as soon as the viewer has
103
+ * picked a TORRENT — while they are still reading the list of episodes — and
104
+ * then most or all of it has happened by the time they choose.
105
+ *
106
+ * Returns as soon as the work is under way. The caller is not waiting for a
107
+ * result; it is only saying "you may start". Failures are logged and answered
108
+ * as `started: false` rather than as an error, because nothing is broken if a
109
+ * warm-up does not happen — the ordinary path still does all of it.
110
+ *
111
+ * @param {import("fastify").FastifyRequest} req
112
+ * @param {import("fastify").FastifyReply} reply
113
+ * @param {{
114
+ * sourceRegistry: ReturnType<import("../../../../store/source-registry.js").createSourceRegistry>,
115
+ * torrentPool: import("../../../../services/torrent/torrent-pool.js").TorrentPool,
116
+ * playbackPlanner?: ReturnType<import("../../../../services/media/playback-planner.js").createPlaybackPlanner>,
117
+ * durationOf?: ({ sourceKey: string, fileIndex: number }) => Promise<number | null>
118
+ * }} deps
119
+ * @returns {Promise<void>}
120
+ */
121
+ export async function handleApiSourceWarmPost(req, reply, { sourceRegistry, torrentPool, playbackPlanner = null, durationOf = null }) {
122
+ const sourceKey = typeof req.params.sourceKey === "string" ? req.params.sourceKey.trim() : "";
123
+ if (!sourceKey) {
124
+ return reply.code(400).send({ error: "sourceKey is required." });
125
+ }
126
+
127
+ const sourceRecord = sourceRegistry.get(sourceKey);
128
+ if (!sourceRecord) {
129
+ return reply.code(404).send({ error: "Source key was not found." });
130
+ }
131
+
132
+ const body = req.body && typeof req.body === "object" && !Array.isArray(req.body) ? req.body : {};
133
+ const requestedIndex = Number(body.fileIndex);
134
+ const fileIndex = Number.isInteger(requestedIndex) && requestedIndex >= 0 ? requestedIndex : null;
135
+ // Where the viewer is about to resume, if they are resuming. The edges below
136
+ // are what the codec probe reads; this is what the VIEWER will read, and until
137
+ // now nothing asked for it before the encoder did.
138
+ const requestedPosition = Number(body.positionSeconds);
139
+ const positionSeconds = Number.isFinite(requestedPosition) && requestedPosition > 0
140
+ ? requestedPosition
141
+ : 0;
142
+ const userAgent = typeof body.userAgent === "string" ? body.userAgent : "";
143
+
144
+ // Adding the torrent is what announces to the trackers and starts connecting
145
+ // to peers, and it is also what a magnet needs in order to fetch its
146
+ // metadata. It is awaited because everything else needs the torrent object,
147
+ // and because until it resolves there is nothing to report.
148
+ let torrent;
149
+ try {
150
+ torrent = await torrentPool.getTorrent(sourceRecord.sourceType, sourceRecord.source);
151
+ } catch (error) {
152
+ const message = error instanceof Error ? error.message : String(error);
153
+ logger.warn(`warm ${sourceKey.slice(0, 8)}: could not add the torrent: ${message}`);
154
+ return reply.send({ started: false, swarm: false, edges: false });
155
+ }
156
+
157
+ const contents = contentsOf(torrent);
158
+ const named = fileIndex !== null && torrent.files?.[fileIndex] ? fileIndex : null;
159
+ if (named !== null) {
160
+ const selectedSidecars = contents.sidecarsOf(named);
161
+ for (const file of [...selectedSidecars.audio, ...selectedSidecars.subtitles]) {
162
+ void torrentPool.prefetchFileEdges(torrent, file.fileIndex, {
163
+ tailBytes: 0,
164
+ headBytes: TEXT_SUBTITLE_SIDECAR_EXTENSIONS.has(file.extension)
165
+ ? Math.max(1, file.length)
166
+ : undefined,
167
+ timeoutMs: 10_000,
168
+ awaited: true
169
+ }).catch((error) => {
170
+ logger.info(`warm ${sourceKey.slice(0, 8)}:${named}: selected sidecar metadata not ready for "${file.name}": ${error?.message ?? error}`);
171
+ });
172
+ }
173
+ }
174
+ const orderedItems = named === null
175
+ ? contents.items
176
+ : [...contents.items.filter((item) => item.fileIndex === named), ...contents.items.filter((item) => item.fileIndex !== named)];
177
+ const metadataStarted = startMetadataWarmup({
178
+ sourceKey,
179
+ items: orderedItems,
180
+ preferredFileIndex: named,
181
+ userAgent,
182
+ playbackPlanner,
183
+ torrentPool,
184
+ torrent
185
+ });
186
+ const sidecarCount = new Set(orderedItems.flatMap((item) => {
187
+ const matched = contents.sidecarsOf(item.fileIndex);
188
+ return [...matched.audio, ...matched.subtitles].map((file) => file.fileIndex);
189
+ })).size;
190
+ const fillStarted = typeof torrentPool.fillTorrent === "function"
191
+ ? await torrentPool.fillTorrent(torrent).catch((error) => {
192
+ logger.warn(`warm ${sourceKey.slice(0, 8)}: whole-torrent fill could not start: ${error?.message ?? error}`);
193
+ return false;
194
+ })
195
+ : false;
196
+ if (named !== null && positionSeconds > 0 && typeof torrentPool.warmResumePosition === "function") {
197
+ void Promise.resolve(
198
+ (typeof durationOf === "function"
199
+ ? durationOf({ sourceKey, fileIndex: named })
200
+ : Promise.resolve(null)
201
+ ).then((durationSeconds) =>
202
+ torrentPool.warmResumePosition(torrent, named, positionSeconds, durationSeconds)
203
+ )
204
+ ).catch((error) => {
205
+ logger.warn(`warm ${sourceKey.slice(0, 8)}: the viewer's position failed: ${error?.message ?? error}`);
206
+ });
207
+ }
208
+
209
+ logger.info(
210
+ `warm ${sourceKey.slice(0, 8)}: swarm started for "${torrent.name}"` +
211
+ `, metadata for ${contents.items.length} video file(s) ${metadataStarted ? "queued" : "unavailable"}` +
212
+ `, ${sidecarCount} related audio/subtitle file(s)` +
213
+ (fillStarted ? ", whole-torrent fill enabled at TAIL urgency" : ", whole-torrent fill unavailable")
214
+ );
215
+
216
+ return reply.send({ started: true, swarm: true, edges: metadataStarted, sidecars: sidecarCount, fill: fillStarted });
217
+ }