Video clip tool (v1.8.3-video-mgmt) #13
1 changed files with 26 additions and 5 deletions
|
|
@ -49,7 +49,7 @@
|
|||
|
||||
import { spawn } from "node:child_process";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { copyFile, mkdir, readdir, rm, stat } from "node:fs/promises";
|
||||
import { access, constants, copyFile, mkdir, readdir, rm, stat } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { UPLOADS_DIR, PUBLIC_PREFIX } from "./media.js";
|
||||
|
|
@ -251,12 +251,27 @@ function update(db, id, fields) {
|
|||
async function cookieArgs(jobId) {
|
||||
if (COOKIES_FILE) {
|
||||
const copy = path.join(CLIPS_DIR, `.cookies-${jobId}.txt`);
|
||||
// Two steps, so a failure names the right one: reading the
|
||||
// original, or writing the copy into CLIPS_DIR.
|
||||
try {
|
||||
await access(COOKIES_FILE, constants.R_OK);
|
||||
} catch (err) {
|
||||
const why =
|
||||
err.code === "ENOENT"
|
||||
? "it isn't there"
|
||||
: err.code === "EACCES"
|
||||
? "the service's user isn't allowed to read it (check its owner and permissions)"
|
||||
: err.code;
|
||||
throw new Error(`Couldn't read the cookies file at ${COOKIES_FILE} (YTDLP_COOKIES): ${why}.`);
|
||||
}
|
||||
try {
|
||||
await copyFile(COOKIES_FILE, copy);
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`Couldn't read the cookies file at ${COOKIES_FILE} (YTDLP_COOKIES)${err.code === "ENOENT" ? ": it isn't there" : ""}.`,
|
||||
);
|
||||
const why =
|
||||
err.code === "EACCES" || err.code === "EPERM"
|
||||
? "the service's user isn't allowed to write there"
|
||||
: err.code;
|
||||
throw new Error(`Couldn't copy the cookies file into ${CLIPS_DIR} (CLIPS_DIR): ${why}.`);
|
||||
}
|
||||
return { args: ["--cookies", copy], cleanup: () => rm(copy, { force: true }) };
|
||||
}
|
||||
|
|
@ -427,7 +442,13 @@ export function kick(db = dbRef) {
|
|||
|
||||
(async () => {
|
||||
try {
|
||||
await mkdir(CLIPS_DIR, { recursive: true });
|
||||
await mkdir(CLIPS_DIR, { recursive: true }).catch((err) => {
|
||||
throw new Error(
|
||||
`Couldn't use the working folder ${CLIPS_DIR} (CLIPS_DIR): ${
|
||||
err.code === "EACCES" || err.code === "EPERM" ? "the service's user isn't allowed to write there" : err.code
|
||||
}.`,
|
||||
);
|
||||
});
|
||||
if (job.kind === "source") await download(db, job);
|
||||
else await cut(db, job);
|
||||
update(db, job.id, { status: "done", progress: 1, finished_at: new Date().toISOString() });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue