Add a video clip tool: download our videos, cut, reshape, export

Tools → Video clips (migration 036, admins and up). Paste a YouTube
or Facebook link and the server downloads it with yt-dlp; then cut
clips: start and end set while watching, a shape (as filmed, 16:9,
square or 9:16 at the sizes the platforms ask for, cropped around a
chosen point shown over the video), and MP4 video or MP3 audio.

Jobs queue and run one at a time with progress. Only YouTube and
Facebook links are accepted, and both tools run with argument lists,
never a shell. A clip's file is deleted once it has been downloaded
in full, unless it's saved to the media library first, which now
holds video and audio (image fields still pick images only).
Everything is swept a day after it's made. Setup is in
docs/video-clips.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 02:43:05 -05:00
parent 8f3f907311
commit beca01c351
13 changed files with 1431 additions and 17 deletions

View file

@ -1,7 +1,8 @@
/* ═══════════════════════════════════════════════════════════════
MEDIA ROUTES: mounted under /api/admin
GET /media the library, newest first, ?q=name.
GET /media the library, newest first, ?q=name,
?type=image|video|audio.
Picks up images copied into the
uploads folder by hand first
(registerLooseFiles, at most every
@ -109,15 +110,19 @@ media.get("/media", async (c) => {
}
const q = (c.req.query("q") ?? "").trim().slice(0, 100);
// ?type=image (what image fields pick from), video or audio
// (clips saved from Tools → Video clips); none lists everything.
const type = ["image", "video", "audio"].includes(c.req.query("type")) ? c.req.query("type") : null;
const where = [q && "m.original_name LIKE ?", type && "m.content_type LIKE ?"].filter(Boolean);
const rows = c
.get("db")
.prepare(
`${SELECT}
${q ? "WHERE m.original_name LIKE ?" : ""}
${where.length ? `WHERE ${where.join(" AND ")}` : ""}
ORDER BY m.created_at DESC, m.id DESC
LIMIT ${MAX_LIST}`,
)
.all(...(q ? [`%${q}%`] : []));
.all(...(q ? [`%${q}%`] : []), ...(type ? [`${type}/%`] : []));
return c.json({ media: rows.map(shape) }, 200, NO_STORE);
});