cursedbelt-server 4.56.0 → 4.57.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.
|
@@ -54,6 +54,14 @@ export interface YtDownload {
|
|
|
54
54
|
interface YtDlpCallOptions {
|
|
55
55
|
/** A Netscape-format cookie jar yt-dlp reads (`--cookies`). The caller owns and removes it. */
|
|
56
56
|
cookiesFile?: string;
|
|
57
|
+
/**
|
|
58
|
+
* A RESUMABLE download: yt-dlp writes into this directory, which the CALLER owns — made if it is
|
|
59
|
+
* missing, kept with its `.part` files when the download fails, so the next call with the same
|
|
60
|
+
* directory continues where the bytes stopped instead of starting a 25 GB film again. The owner,
|
|
61
|
+
* 2026-10-29: *"if my internet was to go out … my downloads in process could be picked back up
|
|
62
|
+
* where they left off"* (forge task 4010). `dispose` still removes it once the file is had.
|
|
63
|
+
*/
|
|
64
|
+
workDir?: string;
|
|
57
65
|
}
|
|
58
66
|
/**
|
|
59
67
|
* Fetch one video. `target` is a YouTube video id, or a page URL (`https://…`) of any site yt-dlp
|
|
@@ -96,6 +104,7 @@ export declare function ytDlpArgs(target: string, outDir: string, profile: Pick<
|
|
|
96
104
|
cacheDir?: string;
|
|
97
105
|
jsRuntime?: string;
|
|
98
106
|
cookiesFile?: string;
|
|
107
|
+
resumable?: boolean;
|
|
99
108
|
}): string[];
|
|
100
109
|
/** Run a program, handing each stdout line over as it arrives. Injected in tests. */
|
|
101
110
|
export type RunLines = (binary: string, args: string[], onLine: (line: string) => void) => Promise<{
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* age check) is handed the owner's own cookie jar per call; reading that jar is the app's business.
|
|
20
20
|
*
|
|
21
21
|
* ── The file stays on disk ──────────────────────────────────────────────────────────────
|
|
22
|
-
* A download resolves to a PATH inside a fresh temporary directory
|
|
22
|
+
* A download resolves to a PATH inside a fresh temporary directory — or inside the caller's own
|
|
23
|
+
* `workDir`, which makes it resumable across failures (forge task 4010) — and the caller disposes of
|
|
23
24
|
* it. A 1080p video is gigabytes, and reading it into memory to hand it over would make the
|
|
24
25
|
* agent's footprint the size of the largest video in a playlist. Music, whose files are a few
|
|
25
26
|
* MB, reads the bytes and disposes at once.
|
|
@@ -178,7 +179,9 @@ export function ytDlpArgs(target, outDir, profile, options = {}) {
|
|
|
178
179
|
...(profile.extraArgs ?? []),
|
|
179
180
|
"--max-filesize",
|
|
180
181
|
profile.maxFilesize,
|
|
181
|
-
|
|
182
|
+
// Resumable: keep the `.part` and continue it. Otherwise no `.part` at all — a fresh directory
|
|
183
|
+
// per run has nothing to continue, and a half file there is only litter.
|
|
184
|
+
...(options.resumable ? ["--continue"] : ["--no-part"]),
|
|
182
185
|
"--no-mtime",
|
|
183
186
|
"--no-colors",
|
|
184
187
|
"--newline",
|
|
@@ -189,7 +192,9 @@ export function ytDlpArgs(target, outDir, profile, options = {}) {
|
|
|
189
192
|
"--print",
|
|
190
193
|
`after_move:${INFO_MARK}%()j`,
|
|
191
194
|
"-o",
|
|
192
|
-
|
|
195
|
+
// Resumable runs name the file for the directory, not the site's id: a signed URL resolved
|
|
196
|
+
// afresh on the next try can carry a different id, and a different name is a fresh download.
|
|
197
|
+
join(outDir, options.resumable ? "download.%(ext)s" : "%(id)s.%(ext)s"),
|
|
193
198
|
"--",
|
|
194
199
|
isPageUrl(target) ? target : `https://www.youtube.com/watch?v=${target}`,
|
|
195
200
|
];
|
|
@@ -293,7 +298,10 @@ export function createYtDlp(options) {
|
|
|
293
298
|
};
|
|
294
299
|
/** One yt-dlp run into a fresh directory. Throws a classified error on failure. */
|
|
295
300
|
const attempt = async (target, onProgress, call = {}) => {
|
|
296
|
-
const
|
|
301
|
+
const resumable = call.workDir !== undefined;
|
|
302
|
+
const dir = call.workDir ?? (await mkdtemp(join(options.tmpRoot ?? tmpdir(), "ytdlp-")));
|
|
303
|
+
if (resumable)
|
|
304
|
+
await mkdir(dir, { recursive: true });
|
|
297
305
|
const dispose = () => rm(dir, { recursive: true, force: true });
|
|
298
306
|
try {
|
|
299
307
|
let info = null;
|
|
@@ -301,6 +309,7 @@ export function createYtDlp(options) {
|
|
|
301
309
|
...(options.cacheDir ? { cacheDir: options.cacheDir } : {}),
|
|
302
310
|
...(jsRuntime ? { jsRuntime } : {}),
|
|
303
311
|
...(call.cookiesFile ? { cookiesFile: call.cookiesFile } : {}),
|
|
312
|
+
...(resumable ? { resumable } : {}),
|
|
304
313
|
}), (line) => {
|
|
305
314
|
const fraction = parseYtProgress(line);
|
|
306
315
|
if (fraction !== null)
|
|
@@ -318,7 +327,9 @@ export function createYtDlp(options) {
|
|
|
318
327
|
return { path: found.filepath, extension, info: found, dir, dispose };
|
|
319
328
|
}
|
|
320
329
|
catch (error) {
|
|
321
|
-
|
|
330
|
+
// 🔴 A resumable directory is the caller's, and its `.part` is the whole point: keep it.
|
|
331
|
+
if (!resumable)
|
|
332
|
+
await dispose();
|
|
322
333
|
throw error;
|
|
323
334
|
}
|
|
324
335
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedbelt-server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.57.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The app-facing Bun/Hono server tier of the cursedbelt split — storage, sharing, activity, guard, sync. React-free; cursedbelt-core below it.",
|
|
@@ -187,6 +187,19 @@ describe("the fetcher", () => {
|
|
|
187
187
|
expect((await readdir(dir)).filter((name) => name.startsWith("ytdlp-"))).toEqual([]);
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
+
test("🔴 a resumable download keeps its directory and its partial bytes through a failure, and continues there", async () => {
|
|
191
|
+
const work = join(dir, "job-1");
|
|
192
|
+
await make(scripted("Connection reset by peer"))("abc", undefined, { workDir: work }).catch(() => undefined);
|
|
193
|
+
// The partial is where the next call looks — never deleted on a failure.
|
|
194
|
+
expect((await stat(work)).isDirectory()).toBe(true);
|
|
195
|
+
const args = runs.at(-1) as string[];
|
|
196
|
+
expect(args).toContain("--continue");
|
|
197
|
+
expect(args).not.toContain("--no-part");
|
|
198
|
+
expect(args[args.indexOf("-o") + 1]).toBe(join(work, "download.%(ext)s"));
|
|
199
|
+
// A non-resumable call is unchanged: no partial, a fresh directory, gone on failure.
|
|
200
|
+
expect(ytDlpArgs("abc", "/out", VIDEO)).toContain("--no-part");
|
|
201
|
+
});
|
|
202
|
+
|
|
190
203
|
test("the ceiling sentence uses the profile's own noun and size", async () => {
|
|
191
204
|
const failure = await make(scripted("File is larger than max-filesize (9 > 8). Aborting."), VIDEO)("abc").then(
|
|
192
205
|
() => {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* age check) is handed the owner's own cookie jar per call; reading that jar is the app's business.
|
|
20
20
|
*
|
|
21
21
|
* ── The file stays on disk ──────────────────────────────────────────────────────────────
|
|
22
|
-
* A download resolves to a PATH inside a fresh temporary directory
|
|
22
|
+
* A download resolves to a PATH inside a fresh temporary directory — or inside the caller's own
|
|
23
|
+
* `workDir`, which makes it resumable across failures (forge task 4010) — and the caller disposes of
|
|
23
24
|
* it. A 1080p video is gigabytes, and reading it into memory to hand it over would make the
|
|
24
25
|
* agent's footprint the size of the largest video in a playlist. Music, whose files are a few
|
|
25
26
|
* MB, reads the bytes and disposes at once.
|
|
@@ -123,6 +124,14 @@ export interface YtDownload {
|
|
|
123
124
|
interface YtDlpCallOptions {
|
|
124
125
|
/** A Netscape-format cookie jar yt-dlp reads (`--cookies`). The caller owns and removes it. */
|
|
125
126
|
cookiesFile?: string;
|
|
127
|
+
/**
|
|
128
|
+
* A RESUMABLE download: yt-dlp writes into this directory, which the CALLER owns — made if it is
|
|
129
|
+
* missing, kept with its `.part` files when the download fails, so the next call with the same
|
|
130
|
+
* directory continues where the bytes stopped instead of starting a 25 GB film again. The owner,
|
|
131
|
+
* 2026-10-29: *"if my internet was to go out … my downloads in process could be picked back up
|
|
132
|
+
* where they left off"* (forge task 4010). `dispose` still removes it once the file is had.
|
|
133
|
+
*/
|
|
134
|
+
workDir?: string;
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
/**
|
|
@@ -270,7 +279,7 @@ export function ytDlpArgs(
|
|
|
270
279
|
target: string,
|
|
271
280
|
outDir: string,
|
|
272
281
|
profile: Pick<YtDlpProfile, "format" | "extraArgs" | "maxFilesize">,
|
|
273
|
-
options: { cacheDir?: string; jsRuntime?: string; cookiesFile?: string } = {},
|
|
282
|
+
options: { cacheDir?: string; jsRuntime?: string; cookiesFile?: string; resumable?: boolean } = {},
|
|
274
283
|
): string[] {
|
|
275
284
|
return [
|
|
276
285
|
...(options.jsRuntime ? ["--js-runtimes", `bun:${options.jsRuntime}`] : []),
|
|
@@ -282,7 +291,9 @@ export function ytDlpArgs(
|
|
|
282
291
|
...(profile.extraArgs ?? []),
|
|
283
292
|
"--max-filesize",
|
|
284
293
|
profile.maxFilesize,
|
|
285
|
-
|
|
294
|
+
// Resumable: keep the `.part` and continue it. Otherwise no `.part` at all — a fresh directory
|
|
295
|
+
// per run has nothing to continue, and a half file there is only litter.
|
|
296
|
+
...(options.resumable ? ["--continue"] : ["--no-part"]),
|
|
286
297
|
"--no-mtime",
|
|
287
298
|
"--no-colors",
|
|
288
299
|
"--newline",
|
|
@@ -293,7 +304,9 @@ export function ytDlpArgs(
|
|
|
293
304
|
"--print",
|
|
294
305
|
`after_move:${INFO_MARK}%()j`,
|
|
295
306
|
"-o",
|
|
296
|
-
|
|
307
|
+
// Resumable runs name the file for the directory, not the site's id: a signed URL resolved
|
|
308
|
+
// afresh on the next try can carry a different id, and a different name is a fresh download.
|
|
309
|
+
join(outDir, options.resumable ? "download.%(ext)s" : "%(id)s.%(ext)s"),
|
|
297
310
|
"--",
|
|
298
311
|
isPageUrl(target) ? target : `https://www.youtube.com/watch?v=${target}`,
|
|
299
312
|
];
|
|
@@ -429,7 +442,9 @@ export function createYtDlp(options: YtDlpOptions): YtDlpFetch {
|
|
|
429
442
|
|
|
430
443
|
/** One yt-dlp run into a fresh directory. Throws a classified error on failure. */
|
|
431
444
|
const attempt = async (target: string, onProgress?: (fraction: number) => void, call: YtDlpCallOptions = {}): Promise<YtDownload> => {
|
|
432
|
-
const
|
|
445
|
+
const resumable = call.workDir !== undefined;
|
|
446
|
+
const dir = call.workDir ?? (await mkdtemp(join(options.tmpRoot ?? tmpdir(), "ytdlp-")));
|
|
447
|
+
if (resumable) await mkdir(dir, { recursive: true });
|
|
433
448
|
const dispose = () => rm(dir, { recursive: true, force: true });
|
|
434
449
|
try {
|
|
435
450
|
let info: YtInfo | null = null;
|
|
@@ -439,6 +454,7 @@ export function createYtDlp(options: YtDlpOptions): YtDlpFetch {
|
|
|
439
454
|
...(options.cacheDir ? { cacheDir: options.cacheDir } : {}),
|
|
440
455
|
...(jsRuntime ? { jsRuntime } : {}),
|
|
441
456
|
...(call.cookiesFile ? { cookiesFile: call.cookiesFile } : {}),
|
|
457
|
+
...(resumable ? { resumable } : {}),
|
|
442
458
|
}),
|
|
443
459
|
(line) => {
|
|
444
460
|
const fraction = parseYtProgress(line);
|
|
@@ -455,7 +471,8 @@ export function createYtDlp(options: YtDlpOptions): YtDlpFetch {
|
|
|
455
471
|
const extension = (found.ext || found.filepath.split(".").at(-1) || "bin").toLowerCase();
|
|
456
472
|
return { path: found.filepath, extension, info: found, dir, dispose };
|
|
457
473
|
} catch (error) {
|
|
458
|
-
|
|
474
|
+
// 🔴 A resumable directory is the caller's, and its `.part` is the whole point: keep it.
|
|
475
|
+
if (!resumable) await dispose();
|
|
459
476
|
throw error;
|
|
460
477
|
}
|
|
461
478
|
};
|