Compare commits

...

2 commits

Author SHA1 Message Date
Zaldimmar
7e501a3aca Bump SITE_VERSION to v1.8.2-video-mgmt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 03:21:07 -05:00
Zaldimmar
a393bde2da Let yt-dlp sign in with cookies when YouTube asks
When YouTube answers the server with "sign in to confirm you're not a
bot", yt-dlp needs a signed-in account's cookies. YTDLP_COOKIES points
at an exported cookies.txt, copied per download so the original is
never rewritten; YTDLP_COOKIES_FROM_BROWSER passes yt-dlp's
--cookies-from-browser for a browser on the server. Setup, and the
advice to use a separate account, is in docs/video-clips.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 03:03:48 -05:00
3 changed files with 107 additions and 42 deletions

View file

@ -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.
**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
them their own block so nginx passes them straight through:

View file

@ -12,6 +12,20 @@
FFMPEG_PATH default "ffmpeg"
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 ──
Only links on YouTube and Facebook are accepted (SOURCE_HOSTS),
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 FFMPEG = process.env.FFMPEG_PATH ?? "ffmpeg";
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_SIZE = "4G";
@ -229,14 +245,38 @@ 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) {
const template = path.join(CLIPS_DIR, `source-${job.id}.%(ext)s`);
let file = null;
let title = null;
const cookies = await cookieArgs(job.id);
try {
await run(
YTDLP,
[
...cookies.args,
job.source_url,
// YouTube needs a JavaScript runtime to list formats; the one
// running this server will do.
@ -277,6 +317,10 @@ async function download(db, job) {
},
);
} finally {
await cookies.cleanup();
}
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 { size } = await stat(file);

View file

@ -7,4 +7,4 @@
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";