Compare commits
2 commits
f1ac690abe
...
7e501a3aca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e501a3aca | ||
|
|
a393bde2da |
3 changed files with 107 additions and 42 deletions
|
|
@ -57,6 +57,27 @@ to an hour. Limits are constants at the top of `server/src/clips.js`.
|
||||||
|
|
||||||
A source can be several GB, so leave room on that disk.
|
A source can be several GB, so leave room on that disk.
|
||||||
|
|
||||||
|
**If YouTube says "Sign in to confirm you're not a bot"**, it's
|
||||||
|
refusing the VPS's address, and yt-dlp needs a signed-in account's
|
||||||
|
cookies. Use a separate Google account made for this, never a
|
||||||
|
personal one: whoever has the cookies is signed in as it. Then set
|
||||||
|
one of:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# A cookies.txt exported from a browser signed in to that account
|
||||||
|
# (a "Get cookies.txt" browser extension, Netscape format). Keep it
|
||||||
|
# readable only by the service: chmod 600, owned by its user.
|
||||||
|
Environment=YTDLP_COOKIES=/var/lib/ngu/youtube-cookies.txt
|
||||||
|
|
||||||
|
# Or: read them from a browser installed and signed in on the VPS
|
||||||
|
# itself, as yt-dlp's --cookies-from-browser takes it.
|
||||||
|
# Environment=YTDLP_COOKIES_FROM_BROWSER=firefox
|
||||||
|
```
|
||||||
|
|
||||||
|
The file is copied for each download, so yt-dlp never rewrites the
|
||||||
|
original. Cookies expire; when downloads start failing again, export
|
||||||
|
a fresh file.
|
||||||
|
|
||||||
4. **nginx**: the editor's video and clip downloads are big streams. Give
|
4. **nginx**: the editor's video and clip downloads are big streams. Give
|
||||||
them their own block so nginx passes them straight through:
|
them their own block so nginx passes them straight through:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,20 @@
|
||||||
FFMPEG_PATH default "ffmpeg"
|
FFMPEG_PATH default "ffmpeg"
|
||||||
FFPROBE_PATH default "ffprobe"
|
FFPROBE_PATH default "ffprobe"
|
||||||
|
|
||||||
|
When YouTube asks the server to "sign in to confirm you're not a
|
||||||
|
bot", yt-dlp needs a signed-in account's cookies. One of:
|
||||||
|
|
||||||
|
YTDLP_COOKIES a cookies.txt exported from a browser
|
||||||
|
(Netscape format). Copied per download,
|
||||||
|
so yt-dlp never writes to the original
|
||||||
|
YTDLP_COOKIES_FROM_BROWSER a browser on this machine to read them
|
||||||
|
from, as yt-dlp's --cookies-from-browser
|
||||||
|
takes it: "firefox", "chrome", or
|
||||||
|
"firefox:/path/to/profile"
|
||||||
|
|
||||||
|
Use a separate Google account, not a personal one: the cookies
|
||||||
|
are that account's sign-in. If both are set, the file wins.
|
||||||
|
|
||||||
── Safety ──
|
── Safety ──
|
||||||
Only links on YouTube and Facebook are accepted (SOURCE_HOSTS),
|
Only links on YouTube and Facebook are accepted (SOURCE_HOSTS),
|
||||||
so yt-dlp can't be pointed at anything else, internal addresses
|
so yt-dlp can't be pointed at anything else, internal addresses
|
||||||
|
|
@ -44,6 +58,8 @@ export const CLIPS_DIR = path.resolve(process.env.CLIPS_DIR ?? "./clips");
|
||||||
const YTDLP = process.env.YTDLP_PATH ?? "yt-dlp";
|
const YTDLP = process.env.YTDLP_PATH ?? "yt-dlp";
|
||||||
const FFMPEG = process.env.FFMPEG_PATH ?? "ffmpeg";
|
const FFMPEG = process.env.FFMPEG_PATH ?? "ffmpeg";
|
||||||
const FFPROBE = process.env.FFPROBE_PATH ?? "ffprobe";
|
const FFPROBE = process.env.FFPROBE_PATH ?? "ffprobe";
|
||||||
|
const COOKIES_FILE = process.env.YTDLP_COOKIES || null;
|
||||||
|
const COOKIES_FROM_BROWSER = process.env.YTDLP_COOKIES_FROM_BROWSER || null;
|
||||||
|
|
||||||
const MAX_SOURCE_SECONDS = 4 * 60 * 60;
|
const MAX_SOURCE_SECONDS = 4 * 60 * 60;
|
||||||
const MAX_SOURCE_SIZE = "4G";
|
const MAX_SOURCE_SIZE = "4G";
|
||||||
|
|
@ -229,53 +245,81 @@ function update(db, id, fields) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* yt-dlp's cookie options, from the environment. A cookies file is
|
||||||
|
copied first: yt-dlp saves updated cookies back to the file it's
|
||||||
|
given, and the original may be read-only to the service. */
|
||||||
|
async function cookieArgs(jobId) {
|
||||||
|
if (COOKIES_FILE) {
|
||||||
|
const copy = path.join(CLIPS_DIR, `.cookies-${jobId}.txt`);
|
||||||
|
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" : ""}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return { args: ["--cookies", copy], cleanup: () => rm(copy, { force: true }) };
|
||||||
|
}
|
||||||
|
if (COOKIES_FROM_BROWSER) {
|
||||||
|
return { args: ["--cookies-from-browser", COOKIES_FROM_BROWSER], cleanup: async () => {} };
|
||||||
|
}
|
||||||
|
return { args: [], cleanup: async () => {} };
|
||||||
|
}
|
||||||
|
|
||||||
async function download(db, job) {
|
async function download(db, job) {
|
||||||
const template = path.join(CLIPS_DIR, `source-${job.id}.%(ext)s`);
|
const template = path.join(CLIPS_DIR, `source-${job.id}.%(ext)s`);
|
||||||
let file = null;
|
let file = null;
|
||||||
let title = null;
|
let title = null;
|
||||||
|
const cookies = await cookieArgs(job.id);
|
||||||
|
|
||||||
await run(
|
try {
|
||||||
YTDLP,
|
await run(
|
||||||
[
|
YTDLP,
|
||||||
job.source_url,
|
[
|
||||||
// YouTube needs a JavaScript runtime to list formats; the one
|
...cookies.args,
|
||||||
// running this server will do.
|
job.source_url,
|
||||||
"--js-runtimes",
|
// YouTube needs a JavaScript runtime to list formats; the one
|
||||||
`node:${process.execPath}`,
|
// running this server will do.
|
||||||
"--no-playlist",
|
"--js-runtimes",
|
||||||
"--no-simulate",
|
`node:${process.execPath}`,
|
||||||
"--newline",
|
"--no-playlist",
|
||||||
"--progress",
|
"--no-simulate",
|
||||||
"--progress-template",
|
"--newline",
|
||||||
"download:PROGRESS %(progress._percent_str)s",
|
"--progress",
|
||||||
"--print",
|
"--progress-template",
|
||||||
"before_dl:TITLE %(title)s",
|
"download:PROGRESS %(progress._percent_str)s",
|
||||||
"--print",
|
"--print",
|
||||||
"after_move:FILE %(filepath)s",
|
"before_dl:TITLE %(title)s",
|
||||||
"-f",
|
"--print",
|
||||||
"bv*[height<=1080][ext=mp4]+ba[ext=m4a]/b[height<=1080][ext=mp4]/bv*[height<=1080]+ba/b",
|
"after_move:FILE %(filepath)s",
|
||||||
"--merge-output-format",
|
"-f",
|
||||||
"mp4",
|
"bv*[height<=1080][ext=mp4]+ba[ext=m4a]/b[height<=1080][ext=mp4]/bv*[height<=1080]+ba/b",
|
||||||
"--max-filesize",
|
"--merge-output-format",
|
||||||
MAX_SOURCE_SIZE,
|
"mp4",
|
||||||
"--match-filter",
|
"--max-filesize",
|
||||||
`duration <= ${MAX_SOURCE_SECONDS}`,
|
MAX_SOURCE_SIZE,
|
||||||
// Only when a path is configured: on the PATH, yt-dlp finds it.
|
"--match-filter",
|
||||||
...(process.env.FFMPEG_PATH ? ["--ffmpeg-location", process.env.FFMPEG_PATH] : []),
|
`duration <= ${MAX_SOURCE_SECONDS}`,
|
||||||
"-o",
|
// Only when a path is configured: on the PATH, yt-dlp finds it.
|
||||||
template,
|
...(process.env.FFMPEG_PATH ? ["--ffmpeg-location", process.env.FFMPEG_PATH] : []),
|
||||||
],
|
"-o",
|
||||||
{
|
template,
|
||||||
onLine: (line) => {
|
],
|
||||||
const percent = line.match(/^PROGRESS\s+([\d.]+)%/);
|
{
|
||||||
if (percent) update(db, job.id, { progress: Math.min(0.99, Number(percent[1]) / 100) });
|
onLine: (line) => {
|
||||||
const t = line.match(/^TITLE (.+)$/);
|
const percent = line.match(/^PROGRESS\s+([\d.]+)%/);
|
||||||
if (t) title = t[1].slice(0, 300);
|
if (percent) update(db, job.id, { progress: Math.min(0.99, Number(percent[1]) / 100) });
|
||||||
const f = line.match(/^FILE (.+)$/);
|
const t = line.match(/^TITLE (.+)$/);
|
||||||
if (f) file = f[1].trim();
|
if (t) title = t[1].slice(0, 300);
|
||||||
|
const f = line.match(/^FILE (.+)$/);
|
||||||
|
if (f) file = f[1].trim();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
);
|
||||||
);
|
|
||||||
|
} finally {
|
||||||
|
await cookies.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
if (!file) throw new Error("The video couldn't be downloaded. It may be private, too long, or too big.");
|
if (!file) throw new Error("The video couldn't be downloaded. It may be private, too long, or too big.");
|
||||||
const info = await probe(file);
|
const info = await probe(file);
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,4 @@
|
||||||
box or a build banner can read the same value later.
|
box or a build banner can read the same value later.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
export const SITE_VERSION = "NGU-Web.v1.8.1-video-mgmt";
|
export const SITE_VERSION = "NGU-Web.v1.8.2-video-mgmt";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue