diff --git a/app.py b/app.py index 2874b80..209d679 100644 --- a/app.py +++ b/app.py @@ -2224,9 +2224,10 @@ async def get_clip_transcript(job_id: str, clip_index: int, request: Request): # --- Clip editor: EDL + re-render --- -# How much transcript to send around the clip's segments — enough for the -# editor's word-level trimming without shipping a whole podcast's words. -EDL_WORD_CONTEXT_SECONDS = 45.0 +# The editor ships the WHOLE source transcript, not a window around the clip: +# the point of the source track is extending a cut into material the clip never +# covered, and you cannot pick a new in-point from words you were not sent. +# Cost is about 7 KB of JSON per minute of speech, fetched once per editor open. def _source_duration_seconds(path): @@ -2295,11 +2296,9 @@ async def get_clip_edl(job_id: str, clip_index: int, request: Request): candidates.append(words[-1]['e']) source_duration = round(max(candidates), 3) - lo = min(s['start'] for s in segments) - EDL_WORD_CONTEXT_SECONDS - hi = max(s['end'] for s in segments) + EDL_WORD_CONTEXT_SECONDS words_out = [ {"w": w["w"], "s": round(w["s"], 3), "e": round(w["e"], 3)} - for w in words if w["e"] >= lo and w["s"] <= hi + for w in words ] current_file = (clip.get('video_url') or '').split('/')[-1] diff --git a/dashboard/src/components/ClipEditor.jsx b/dashboard/src/components/ClipEditor.jsx index b699b48..28a456b 100644 --- a/dashboard/src/components/ClipEditor.jsx +++ b/dashboard/src/components/ClipEditor.jsx @@ -1,7 +1,8 @@ -import React, { useState, useEffect, useReducer, useRef, useCallback, useMemo } from 'react'; +import React, { useState, useEffect, useReducer, useRef, useCallback, useMemo, useDeferredValue } from 'react'; import { X, Loader2, Plus, Trash2, ChevronUp, ChevronDown, Scissors, - AlertCircle, Undo2, Redo2, Film, + AlertCircle, Undo2, Redo2, ChevronsRight, ChevronsLeft, + PanelLeft, PanelLeftClose, Film, } from 'lucide-react'; import { getApiUrl } from '../config'; import { apiFetch, apiJson, QuotaError } from '../lib/api'; @@ -12,7 +13,16 @@ import { apiFetch, apiJson, QuotaError } from '../lib/api'; const MIN_SEGMENT_SECONDS = 0.5; const SNAP_WINDOW_SECONDS = 0.35; -const WORD_CONTEXT_SECONDS = 15; + +// Hiding the source is a working preference, not a per-clip one, so it sticks. +const HIDE_SOURCE_KEY = 'openshorts_editor_hide_source'; + +// Words per memoised transcript slice. See TranscriptChunk for why this exists. +const CHUNK_WORDS = 50; + +// Segment edges round-trip through 3 decimals, so coverage arithmetic needs a +// hair of tolerance before it calls a millisecond sliver "not rendered". +const COVERAGE_EPSILON = 0.02; const SEGMENT_COLORS = [ 'oklch(76% .17 50)', // brass @@ -104,7 +114,16 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer const [confirmClose, setConfirmClose] = useState(false); const [selectedWord, setSelectedWord] = useState(null); const [playhead, setPlayhead] = useState(0); - const [showSource, setShowSource] = useState(false); + const [showSource, setShowSource] = useState(() => { + try { return localStorage.getItem(HIDE_SOURCE_KEY) !== '1'; } catch { return true; } + }); + // Where the source monitor's playhead is, for the transcript to follow. + const [sourceTime, setSourceTime] = useState(0); + // Three-point editing, like a Premiere source monitor: mark IN and OUT on + // the source, then send that range to the clip. Kept as two independent + // numbers rather than a range so either end can be re-marked on its own. + const [markIn, setMarkIn] = useState(null); + const [markOut, setMarkOut] = useState(null); const videoRef = useRef(null); const sourceRef = useRef(null); @@ -112,6 +131,50 @@ export default function ClipEditor({ jobId, clipIndex, clipTitle, onClose, onRer const sourceTrackRef = useRef(null); const dragRef = useRef(null); const [ghost, setGhost] = useState(null); // in-progress new segment on the source track + const transcriptRef = useRef(null); + + useEffect(() => { + try { localStorage.setItem(HIDE_SOURCE_KEY, showSource ? '0' : '1'); } catch { /* private mode */ } + }, [showSource]); + + // ---- scrubbing the source monitor --------------------------------------- + // Dragging on the source track drives this