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:
parent
8f3f907311
commit
beca01c351
13 changed files with 1431 additions and 17 deletions
|
|
@ -83,19 +83,25 @@ export function uploadImage(file: File, keepOriginal: boolean): Promise<MediaIte
|
|||
return upload("/admin/media", form).then((data) => data.media);
|
||||
}
|
||||
|
||||
export function useMediaLibrary(query: string) {
|
||||
/* `type` narrows to one kind of file: image fields pick images only.
|
||||
Blank lists everything, videos and audio saved from the clip tool
|
||||
included. */
|
||||
export function useMediaLibrary(query: string, type?: "image" | "video" | "audio") {
|
||||
const [items, setItems] = useState<MediaItem[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const reload = useCallback(() => {
|
||||
const q = query.trim();
|
||||
const params = new URLSearchParams();
|
||||
if (q) params.set("q", q);
|
||||
if (type) params.set("type", type);
|
||||
setError(null);
|
||||
get(`/admin/media${q ? `?q=${encodeURIComponent(q)}` : ""}`, { ttl: 0 })
|
||||
get(`/admin/media${params.size ? `?${params}` : ""}`, { ttl: 0 })
|
||||
.then((data) => setItems(data.media))
|
||||
.catch((err) =>
|
||||
setError(err instanceof ApiError ? err.message : "Couldn't load the library."),
|
||||
);
|
||||
}, [query]);
|
||||
}, [query, type]);
|
||||
|
||||
useEffect(reload, [reload]);
|
||||
|
||||
|
|
@ -204,12 +210,21 @@ export function MediaGrid({
|
|||
const thumb = (
|
||||
<>
|
||||
<div className="aspect-[4/3] overflow-hidden rounded-lg" style={CHECKER}>
|
||||
<img
|
||||
src={item.url}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-full w-full object-contain"
|
||||
/>
|
||||
{item.content_type.startsWith("video/") ? (
|
||||
// A still of the first frame; metadata only, not the file.
|
||||
<video src={item.url} preload="metadata" muted className="h-full w-full bg-black object-contain" />
|
||||
) : item.content_type.startsWith("audio/") ? (
|
||||
<div className="flex h-full w-full items-center justify-center bg-[#eef9fb] text-3xl" aria-hidden="true">
|
||||
♪
|
||||
</div>
|
||||
) : (
|
||||
<img
|
||||
src={item.url}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-full w-full object-contain"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-1.5 truncate text-xs font-medium text-[#26454c]" title={item.original_name}>
|
||||
{item.original_name}
|
||||
|
|
@ -258,7 +273,7 @@ export function MediaPicker({
|
|||
}) {
|
||||
const { user } = useAuth();
|
||||
const [query, setQuery] = useState("");
|
||||
const { items, error, setItems } = useMediaLibrary(query);
|
||||
const { items, error, setItems } = useMediaLibrary(query, "image");
|
||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||
|
||||
// showModal gives focus trapping, Escape and the backdrop for free.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue