-- ═══════════════════════════════════════════════════════════════ -- 036 VIDEO CLIPS -- -- The admin's video clip tool (Tools → Video clips): download one of -- our videos from YouTube or Facebook, cut clips from it, and take -- them away as MP4 or MP3. One row per job, of two kinds: -- -- source a download (yt-dlp) of source_url. When done, file is -- the video in CLIPS_DIR and title/duration describe it. -- clip a cut (ffmpeg) of a source: params holds the JSON -- { start, end, shape, focus, format }. When done, file -- is the clip in CLIPS_DIR. -- -- Jobs run one at a time, oldest queued first (server/src/clips.js). -- A job left 'running' by a restart is marked failed at boot. -- -- Files are temporary. A clip's file is deleted once it has been -- downloaded, unless it was saved to the media library first -- (saved_media_id), and anything older than a day is swept, sources -- included. Deleting a source deletes its clips. -- -- PRAGMA user_version; -- reads 35 before this file -- ═══════════════════════════════════════════════════════════════ CREATE TABLE clip_jobs ( id INTEGER PRIMARY KEY AUTOINCREMENT, kind TEXT NOT NULL CHECK (kind IN ('source', 'clip')), status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'running', 'done', 'failed')), progress REAL NOT NULL DEFAULT 0 CHECK (progress BETWEEN 0 AND 1), source_url TEXT, -- kind 'source' source_id INTEGER REFERENCES clip_jobs (id) ON DELETE CASCADE, -- kind 'clip' params TEXT, -- kind 'clip': JSON title TEXT, duration REAL, -- seconds file TEXT, -- a name in CLIPS_DIR, once done bytes INTEGER, error TEXT, saved_media_id INTEGER REFERENCES media (id) ON DELETE SET NULL, downloaded_at TEXT, -- a clip's file went out, and was deleted created_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, created_at TEXT NOT NULL DEFAULT (datetime('now')), finished_at TEXT, CHECK ((kind = 'source') = (source_url IS NOT NULL)), CHECK ((kind = 'clip') = (source_id IS NOT NULL)) ) STRICT; CREATE INDEX clip_jobs_queue_idx ON clip_jobs (status, id); CREATE INDEX clip_jobs_source_idx ON clip_jobs (source_id);