feat(hooks): "edit hook" with a typeface picker; a preview that matches
- The clip button and modal are "edit hook" (was "viral hook"), and the submit says "update hook" when the clip already has one. - Typeface picker: Montserrat, Anton, Serif, all bundled so the server render (hooks.HOOK_FONTS, /api/hook `font`) and the Remotion preview (HOOK_FONTS in remotion/lib/fonts.ts) use the same file and size. Unset keeps each style's own typeface, so existing styles render as before. - The preview box is a true 9:16 (it was taller than the video, so the hook sat off where it lands); style swatches are larger, drawn in the real typeface, and "Pills" shows pills. - Entrance options are hidden when they cannot apply (server re-render) instead of shown greyed out. - Autopilot: skipped videos can be clipped again by hand (private videos used to be misread as Shorts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a9818832b3
commit
77d3a1143e
9 changed files with 129 additions and 46 deletions
5
app.py
5
app.py
|
|
@ -4927,6 +4927,7 @@ class HookRequest(BaseModel):
|
||||||
size: Optional[str] = "M" # S, M, L
|
size: Optional[str] = "M" # S, M, L
|
||||||
duration_seconds: Optional[float] = None # None = hook visible for the whole clip
|
duration_seconds: Optional[float] = None # None = hook visible for the whole clip
|
||||||
style: Optional[str] = "pill" # pill/classic/dark/yellow/red/outline/outline_yellow
|
style: Optional[str] = "pill" # pill/classic/dark/yellow/red/outline/outline_yellow
|
||||||
|
font: Optional[str] = None # montserrat/anton/serif (hooks.HOOK_FONTS); None = the style's own
|
||||||
remove: Optional[bool] = False # strip the burned hook instead of adding one
|
remove: Optional[bool] = False # strip the burned hook instead of adding one
|
||||||
|
|
||||||
@app.post("/api/hook")
|
@app.post("/api/hook")
|
||||||
|
|
@ -5002,7 +5003,7 @@ async def add_hook(req: HookRequest, request: Request):
|
||||||
try:
|
try:
|
||||||
# Run in thread pool
|
# Run in thread pool
|
||||||
def run_hook():
|
def run_hook():
|
||||||
add_hook_to_video(input_path, req.text, output_path, position=req.position, font_scale=font_scale, duration=req.duration_seconds, style=req.style)
|
add_hook_to_video(input_path, req.text, output_path, position=req.position, font_scale=font_scale, duration=req.duration_seconds, style=req.style, font=req.font)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
await loop.run_in_executor(None, run_hook)
|
await loop.run_in_executor(None, run_hook)
|
||||||
|
|
@ -5029,7 +5030,7 @@ async def add_hook(req: HookRequest, request: Request):
|
||||||
clip_data.pop('auto_hook', None)
|
clip_data.pop('auto_hook', None)
|
||||||
else:
|
else:
|
||||||
clip_data['auto_hook'] = {
|
clip_data['auto_hook'] = {
|
||||||
"text": req.text, "style": req.style, "position": req.position,
|
"text": req.text, "style": req.style, "font": req.font, "position": req.position,
|
||||||
"duration_seconds": req.duration_seconds,
|
"duration_seconds": req.duration_seconds,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
dashboard/public/fonts/Anton-Regular.ttf
Normal file
BIN
dashboard/public/fonts/Anton-Regular.ttf
Normal file
Binary file not shown.
|
|
@ -424,8 +424,9 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected }
|
||||||
<div className="divide-y divide-rule">
|
<div className="divide-y divide-rule">
|
||||||
{(videos || []).map((v) => {
|
{(videos || []).map((v) => {
|
||||||
const run = v.run;
|
const run = v.run;
|
||||||
const canRun = eligible && (!run || run.status === 'failed'
|
// Skipped runs can be retried too: private videos used to be
|
||||||
|| (run.status === 'skipped' && run.reason !== 'youtube_short'));
|
// misread as Shorts, and a real Short just skips again.
|
||||||
|
const canRun = eligible && (!run || run.status === 'failed' || run.status === 'skipped');
|
||||||
return (
|
return (
|
||||||
<div key={v.id} className="flex items-center gap-3 py-3">
|
<div key={v.id} className="flex items-center gap-3 py-3">
|
||||||
{v.thumbnail_url ? (
|
{v.thumbnail_url ? (
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,20 @@ const HOOK_STYLES = [
|
||||||
{ value: 'outline_yellow', label: 'Outline+', box: 'transparent', text: '#FFD600', outline: true },
|
{ value: 'outline_yellow', label: 'Outline+', box: 'transparent', text: '#FFD600', outline: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Must mirror hooks.py HOOK_FONTS (all bundled: /fonts/*.ttf).
|
||||||
|
const FONT_OPTIONS = [
|
||||||
|
{ value: 'montserrat', label: 'Montserrat' },
|
||||||
|
{ value: 'anton', label: 'Anton' },
|
||||||
|
{ value: 'serif', label: 'Serif' },
|
||||||
|
];
|
||||||
|
const FONT_CSS = {
|
||||||
|
montserrat: { fontFamily: "'Montserrat-ExtraBold', 'Montserrat', sans-serif", fontWeight: 800 },
|
||||||
|
anton: { fontFamily: "'Anton-Regular', Impact, sans-serif", fontWeight: 400 },
|
||||||
|
serif: { fontFamily: "'Noto Serif', Georgia, serif", fontWeight: 700 },
|
||||||
|
};
|
||||||
|
// The style's own typeface when none is picked (what hooks.py renders).
|
||||||
|
const styleFont = (st) => (st === 'pill' ? 'montserrat' : 'serif');
|
||||||
|
|
||||||
const POSITION_OPTIONS = [
|
const POSITION_OPTIONS = [
|
||||||
{ value: 'top', label: 'top' },
|
{ value: 'top', label: 'top' },
|
||||||
{ value: 'center', label: 'center' },
|
{ value: 'center', label: 'center' },
|
||||||
|
|
@ -46,6 +60,9 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
const [position, setPosition] = useState(prefs.position || 'top');
|
const [position, setPosition] = useState(prefs.position || 'top');
|
||||||
const [size, setSize] = useState(prefs.size || 'M');
|
const [size, setSize] = useState(prefs.size || 'M');
|
||||||
const [style, setStyle] = useState(prefs.style || 'pill');
|
const [style, setStyle] = useState(prefs.style || 'pill');
|
||||||
|
// null = follow the style's own typeface.
|
||||||
|
const [font, setFont] = useState(prefs.font || null);
|
||||||
|
const effectiveFont = font || styleFont(style);
|
||||||
const [entranceAnimation, setEntranceAnimation] = useState(prefs.entranceAnimation || 'spring');
|
const [entranceAnimation, setEntranceAnimation] = useState(prefs.entranceAnimation || 'spring');
|
||||||
const [displayDuration, setDisplayDuration] = useState(5);
|
const [displayDuration, setDisplayDuration] = useState(5);
|
||||||
|
|
||||||
|
|
@ -57,6 +74,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
position,
|
position,
|
||||||
size,
|
size,
|
||||||
style,
|
style,
|
||||||
|
font: effectiveFont,
|
||||||
entranceAnimation,
|
entranceAnimation,
|
||||||
displayDurationSec: displayDuration,
|
displayDurationSec: displayDuration,
|
||||||
};
|
};
|
||||||
|
|
@ -80,14 +98,15 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const pillFontFace = "@font-face{font-family:'Montserrat-ExtraBold';src:url('/fonts/Montserrat-ExtraBold.ttf') format('truetype');font-weight:800;}";
|
const pillFontFace = "@font-face{font-family:'Montserrat-ExtraBold';src:url('/fonts/Montserrat-ExtraBold.ttf') format('truetype');font-weight:800;}"
|
||||||
|
+ "@font-face{font-family:'Anton-Regular';src:url('/fonts/Anton-Regular.ttf') format('truetype');font-weight:400;}";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} onClose={onClose} size="lg" eyebrow="EDITOR · HOOK" title="viral hook">
|
<Modal isOpen={isOpen} onClose={onClose} size="lg" eyebrow="EDITOR · HOOK" title="edit hook">
|
||||||
<style>{pillFontFace}</style>
|
<style>{pillFontFace}</style>
|
||||||
<div className="flex flex-col md:flex-row gap-6">
|
<div className="flex flex-col md:flex-row gap-6">
|
||||||
{/* Left: Preview */}
|
{/* Left: Preview */}
|
||||||
<div className="flex-1 flex flex-col items-center justify-center bg-black rounded-card border border-rule overflow-hidden relative aspect-[9/16] max-h-[600px]">
|
<div className="w-full max-w-[300px] mx-auto md:mx-0 md:w-[300px] shrink-0 self-start flex flex-col items-center justify-center bg-black rounded-card border border-rule overflow-hidden relative aspect-[9/16]">
|
||||||
{useRemotionPreview ? (
|
{useRemotionPreview ? (
|
||||||
<RemotionPreview
|
<RemotionPreview
|
||||||
videoUrl={videoUrl}
|
videoUrl={videoUrl}
|
||||||
|
|
@ -104,7 +123,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
style={{
|
style={{
|
||||||
...getSizeStyle(),
|
...getSizeStyle(),
|
||||||
backgroundColor: 'rgba(255, 255, 255, 0.82)',
|
backgroundColor: 'rgba(255, 255, 255, 0.82)',
|
||||||
fontFamily: 'Noto Serif, serif',
|
...FONT_CSS[effectiveFont],
|
||||||
boxShadow: '0 4px 15px rgba(0,0,0,0.5)',
|
boxShadow: '0 4px 15px rgba(0,0,0,0.5)',
|
||||||
paddingTop: '10px',
|
paddingTop: '10px',
|
||||||
paddingBottom: '10px',
|
paddingBottom: '10px',
|
||||||
|
|
@ -146,21 +165,46 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
${style === s.value ? 'border-[color:var(--color-accent)]' : 'border-rule2 hover:border-[color:var(--color-accent)]'}`}
|
${style === s.value ? 'border-[color:var(--color-accent)]' : 'border-rule2 hover:border-[color:var(--color-accent)]'}`}
|
||||||
title={s.label}
|
title={s.label}
|
||||||
>
|
>
|
||||||
<span
|
{s.value === 'pill' ? (
|
||||||
className="block rounded px-1 py-1 font-bold"
|
<span className="flex flex-col items-center gap-0.5 py-0.5" style={FONT_CSS[font || styleFont(s.value)]}>
|
||||||
style={{
|
<span className="rounded-md px-1.5 text-[13px] leading-5 bg-white text-black">Aa Bb</span>
|
||||||
backgroundColor: s.box,
|
<span className="rounded-md px-1.5 text-[13px] leading-5 bg-white text-black">Cc</span>
|
||||||
color: s.text,
|
</span>
|
||||||
fontFamily: s.sans ? "'Montserrat-ExtraBold', 'Montserrat', sans-serif" : undefined,
|
) : (
|
||||||
textShadow: s.outline ? '-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000' : 'none',
|
<span
|
||||||
}}
|
className="block rounded-md px-1 py-1.5 text-[15px] leading-5"
|
||||||
>Aa</span>
|
style={{
|
||||||
|
...FONT_CSS[font || styleFont(s.value)],
|
||||||
|
backgroundColor: s.box,
|
||||||
|
color: s.text,
|
||||||
|
textShadow: s.outline ? '-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000' : 'none',
|
||||||
|
}}
|
||||||
|
>Aa</span>
|
||||||
|
)}
|
||||||
<span className="block mt-1 text-muted">{s.label}</span>
|
<span className="block mt-1 text-muted">{s.label}</span>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Typeface */}
|
||||||
|
<div>
|
||||||
|
<p className="eyebrow mb-2">Font</p>
|
||||||
|
<div className="grid grid-cols-3 gap-1.5">
|
||||||
|
{FONT_OPTIONS.map((f) => (
|
||||||
|
<button
|
||||||
|
key={f.value}
|
||||||
|
onClick={() => setFont(f.value)}
|
||||||
|
className={`px-1 py-2 rounded-input border text-[15px] text-ink transition-colors
|
||||||
|
${effectiveFont === f.value ? 'border-[color:var(--color-accent)]' : 'border-rule2 hover:border-[color:var(--color-accent)]'}`}
|
||||||
|
style={FONT_CSS[f.value]}
|
||||||
|
>
|
||||||
|
{f.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Position Control */}
|
{/* Position Control */}
|
||||||
<div>
|
<div>
|
||||||
<p className="eyebrow mb-2">Position</p>
|
<p className="eyebrow mb-2">Position</p>
|
||||||
|
|
@ -190,7 +234,8 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Entrance Animation (new) */}
|
{/* Entrance Animation (new) */}
|
||||||
<div className={serverRender ? 'opacity-50' : ''}>
|
{!serverRender && (
|
||||||
|
<div>
|
||||||
<p className="eyebrow mb-2">Entrance</p>
|
<p className="eyebrow mb-2">Entrance</p>
|
||||||
<SegmentedControl
|
<SegmentedControl
|
||||||
options={ENTRANCE_OPTIONS}
|
options={ENTRANCE_OPTIONS}
|
||||||
|
|
@ -199,13 +244,8 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
columns={2}
|
columns={2}
|
||||||
size="sm"
|
size="sm"
|
||||||
/>
|
/>
|
||||||
{serverRender && (
|
|
||||||
<p className="text-[11px] text-muted mt-1.5 leading-relaxed">
|
|
||||||
This clip re-renders on the server, where the hook is
|
|
||||||
static — the entrance animation won't apply.
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Display Duration (new) */}
|
{/* Display Duration (new) */}
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -258,11 +298,11 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem('os_hook_prefs', JSON.stringify({
|
localStorage.setItem('os_hook_prefs', JSON.stringify({
|
||||||
style, position, size, entranceAnimation,
|
style, font, position, size, entranceAnimation,
|
||||||
}));
|
}));
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
onGenerate({
|
onGenerate({
|
||||||
text, position, size, style,
|
text, position, size, style, font: effectiveFont,
|
||||||
// Remotion data
|
// Remotion data
|
||||||
remotion: hookConfig,
|
remotion: hookConfig,
|
||||||
});
|
});
|
||||||
|
|
@ -271,7 +311,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
className="btn-primary flex-1"
|
className="btn-primary flex-1"
|
||||||
>
|
>
|
||||||
{isProcessing && <Loader2 size={16} className="animate-spin text-brassink" />}
|
{isProcessing && <Loader2 size={16} className="animate-spin text-brassink" />}
|
||||||
{isProcessing ? 'generating...' : 'add hook'}
|
{isProcessing ? 'saving...' : (burnedHook ? 'update hook' : 'add hook')}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -539,7 +539,8 @@ export default function ResultCard({ clip, index, jobId, durable, uploadPostKey,
|
||||||
text: payload.text,
|
text: payload.text,
|
||||||
position: payload.position,
|
position: payload.position,
|
||||||
size: payload.size,
|
size: payload.size,
|
||||||
style: payload.style || 'classic',
|
style: payload.style || 'pill',
|
||||||
|
font: payload.font || null,
|
||||||
duration_seconds: payload.remotion?.displayDurationSec ?? null,
|
duration_seconds: payload.remotion?.displayDurationSec ?? null,
|
||||||
input_filename: serverVideoFile
|
input_filename: serverVideoFile
|
||||||
})
|
})
|
||||||
|
|
@ -956,7 +957,7 @@ export default function ResultCard({ clip, index, jobId, durable, uploadPostKey,
|
||||||
className={QUIET_BTN}
|
className={QUIET_BTN}
|
||||||
>
|
>
|
||||||
{isHooking ? <Loader2 size={16} className="animate-spin text-brass shrink-0" /> : <Wand2 size={16} className="text-muted group-hover:text-brass transition-colors shrink-0" />}
|
{isHooking ? <Loader2 size={16} className="animate-spin text-brass shrink-0" /> : <Wand2 size={16} className="text-muted group-hover:text-brass transition-colors shrink-0" />}
|
||||||
{isHooking ? 'adding…' : 'viral hook'}
|
{isHooking ? 'saving…' : 'edit hook'}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ import {
|
||||||
import type { HookConfig } from "../lib/types";
|
import type { HookConfig } from "../lib/types";
|
||||||
import {
|
import {
|
||||||
notoSerifFontFace,
|
notoSerifFontFace,
|
||||||
NOTO_SERIF_FONT_FAMILY,
|
|
||||||
montserratFontFace,
|
montserratFontFace,
|
||||||
MONTSERRAT_FONT_FAMILY,
|
antonFontFace,
|
||||||
|
HOOK_FONTS,
|
||||||
} from "../lib/fonts";
|
} from "../lib/fonts";
|
||||||
|
|
||||||
interface HookOverlayProps {
|
interface HookOverlayProps {
|
||||||
|
|
@ -59,7 +59,7 @@ export const HookOverlay: React.FC<HookOverlayProps> = ({ config }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AbsoluteFill>
|
<AbsoluteFill>
|
||||||
<style>{notoSerifFontFace + montserratFontFace}</style>
|
<style>{notoSerifFontFace + montserratFontFace + antonFontFace}</style>
|
||||||
<Sequence from={0} durationInFrames={displayFrames} layout="none">
|
<Sequence from={0} durationInFrames={displayFrames} layout="none">
|
||||||
<HookBox config={config} displayFrames={displayFrames} />
|
<HookBox config={config} displayFrames={displayFrames} />
|
||||||
</Sequence>
|
</Sequence>
|
||||||
|
|
@ -127,9 +127,10 @@ const HookBox: React.FC<HookBoxProps> = ({ config, displayFrames }) => {
|
||||||
const positionStyle = POSITION_STYLE[config.position] ?? POSITION_STYLE.top;
|
const positionStyle = POSITION_STYLE[config.position] ?? POSITION_STYLE.top;
|
||||||
const look = HOOK_LOOKS[config.style ?? "pill"] ?? HOOK_LOOKS.pill;
|
const look = HOOK_LOOKS[config.style ?? "pill"] ?? HOOK_LOOKS.pill;
|
||||||
|
|
||||||
// Base font size: 5% (serif) / 6.4% (pill sans) of the 90% box, as hooks.py.
|
// Typeface and size as hooks.py: the chosen font, else the style's own;
|
||||||
const baseFontSize = 1080 * 0.9 * (look.pills ? 0.064 : 0.05 / 0.9);
|
// font size = factor x the 90%-of-width box.
|
||||||
const fontSize = Math.round(baseFontSize * scale);
|
const typeface = HOOK_FONTS[config.font ?? (look.pills ? "montserrat" : "serif")] ?? HOOK_FONTS.serif;
|
||||||
|
const fontSize = Math.round(1080 * 0.9 * typeface.factor * scale);
|
||||||
const outlinePx = Math.round(look.outlinePx * scale);
|
const outlinePx = Math.round(look.outlinePx * scale);
|
||||||
|
|
||||||
if (look.pills) {
|
if (look.pills) {
|
||||||
|
|
@ -157,9 +158,9 @@ const HookBox: React.FC<HookBoxProps> = ({ config, displayFrames }) => {
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
fontFamily: `'${MONTSERRAT_FONT_FAMILY}', 'Montserrat', sans-serif`,
|
fontFamily: typeface.family,
|
||||||
fontSize,
|
fontSize,
|
||||||
fontWeight: 800,
|
fontWeight: typeface.weight,
|
||||||
color: look.text,
|
color: look.text,
|
||||||
backgroundColor: look.box ?? "transparent",
|
backgroundColor: look.box ?? "transparent",
|
||||||
padding: `${Math.round(fontSize * 0.2)}px ${Math.round(fontSize * 0.48)}px`,
|
padding: `${Math.round(fontSize * 0.2)}px ${Math.round(fontSize * 0.48)}px`,
|
||||||
|
|
@ -201,9 +202,9 @@ const HookBox: React.FC<HookBoxProps> = ({ config, displayFrames }) => {
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
fontFamily: `'${NOTO_SERIF_FONT_FAMILY}', 'Noto Serif', Georgia, serif`,
|
fontFamily: typeface.family,
|
||||||
fontSize,
|
fontSize,
|
||||||
fontWeight: 700,
|
fontWeight: typeface.weight,
|
||||||
color: look.text,
|
color: look.text,
|
||||||
lineHeight: 1.4,
|
lineHeight: 1.4,
|
||||||
wordBreak: "break-word",
|
wordBreak: "break-word",
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,28 @@ export const montserratFontFace = `
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
/** Anton (bundled, SIL OFL): the condensed hook typeface. */
|
||||||
|
export const ANTON_FONT_FAMILY = "Anton-Regular";
|
||||||
|
|
||||||
|
export const antonFontFace = `
|
||||||
|
@font-face {
|
||||||
|
font-family: '${ANTON_FONT_FAMILY}';
|
||||||
|
src: url('${staticFile("fonts/Anton-Regular.ttf")}') format('truetype');
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook typefaces: CSS family + share of the 90% box width used as font size.
|
||||||
|
* Must mirror hooks.py HOOK_FONTS.
|
||||||
|
*/
|
||||||
|
export const HOOK_FONTS: Record<string, { family: string; weight: number; factor: number }> = {
|
||||||
|
montserrat: { family: `'${MONTSERRAT_FONT_FAMILY}', 'Montserrat', sans-serif`, weight: 800, factor: 0.064 },
|
||||||
|
anton: { family: `'${ANTON_FONT_FAMILY}', Impact, sans-serif`, weight: 400, factor: 0.08 },
|
||||||
|
serif: { family: `'${NOTO_SERIF_FONT_FAMILY}', 'Noto Serif', Georgia, serif`, weight: 700, factor: 0.05 },
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of subtitle font families to their CSS-safe names.
|
* Map of subtitle font families to their CSS-safe names.
|
||||||
* These match the options available in SubtitleModal.jsx.
|
* These match the options available in SubtitleModal.jsx.
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,15 @@ export type HookStyle =
|
||||||
| "outline"
|
| "outline"
|
||||||
| "outline_yellow";
|
| "outline_yellow";
|
||||||
|
|
||||||
|
export type HookFont = "montserrat" | "anton" | "serif";
|
||||||
|
|
||||||
export interface HookConfig {
|
export interface HookConfig {
|
||||||
text: string;
|
text: string;
|
||||||
position: HookPosition;
|
position: HookPosition;
|
||||||
size: HookSize;
|
size: HookSize;
|
||||||
style?: HookStyle;
|
style?: HookStyle;
|
||||||
|
/** montserrat | anton | serif; unset = the style's own typeface. */
|
||||||
|
font?: HookFont;
|
||||||
entranceAnimation: HookEntrance;
|
entranceAnimation: HookEntrance;
|
||||||
displayDurationSec: number;
|
displayDurationSec: number;
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +118,7 @@ export const hookConfigSchema = z.object({
|
||||||
style: z
|
style: z
|
||||||
.enum(["pill", "classic", "dark", "yellow", "red", "outline", "outline_yellow"])
|
.enum(["pill", "classic", "dark", "yellow", "red", "outline", "outline_yellow"])
|
||||||
.default("pill"),
|
.default("pill"),
|
||||||
|
font: z.enum(["montserrat", "anton", "serif"]).optional(),
|
||||||
entranceAnimation: z.enum(["spring", "fade", "slide-up", "none"]),
|
entranceAnimation: z.enum(["spring", "fade", "slide-up", "none"]),
|
||||||
displayDurationSec: z.number().positive(),
|
displayDurationSec: z.number().positive(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
26
hooks.py
26
hooks.py
|
|
@ -26,6 +26,15 @@ FONT_PATH = os.path.join(FONT_DIR, "NotoSerif-Bold.ttf")
|
||||||
# Bundled (SIL OFL, see fonts/Montserrat-OFL.txt): the "pill" look's sans.
|
# Bundled (SIL OFL, see fonts/Montserrat-OFL.txt): the "pill" look's sans.
|
||||||
PILL_FONT_PATH = os.path.join(FONT_DIR, "Montserrat-ExtraBold.ttf")
|
PILL_FONT_PATH = os.path.join(FONT_DIR, "Montserrat-ExtraBold.ttf")
|
||||||
|
|
||||||
|
# Typefaces the hook editor offers, all bundled so the server render and the
|
||||||
|
# browser preview use the same file. The size factor (share of the box width)
|
||||||
|
# evens out their visual weight: Anton is condensed, Montserrat wide.
|
||||||
|
HOOK_FONTS = {
|
||||||
|
"montserrat": (PILL_FONT_PATH, 0.064),
|
||||||
|
"anton": (os.path.join(FONT_DIR, "Anton-Regular.ttf"), 0.08),
|
||||||
|
"serif": (FONT_PATH, 0.05),
|
||||||
|
}
|
||||||
|
|
||||||
# Codepoint ranges NotoSerif has no glyphs for (would render as tofu boxes).
|
# Codepoint ranges NotoSerif has no glyphs for (would render as tofu boxes).
|
||||||
_EMOJI_RE = re.compile(
|
_EMOJI_RE = re.compile(
|
||||||
"["
|
"["
|
||||||
|
|
@ -241,7 +250,8 @@ def _draw_pills(lines, font, emoji_font, font_size, box_fill, text_fill, output_
|
||||||
return output_image_path, canvas_w, canvas_h
|
return output_image_path, canvas_w, canvas_h
|
||||||
|
|
||||||
|
|
||||||
def create_hook_image(text, target_width, output_image_path="hook_overlay.png", font_scale=1.0, style="pill"):
|
def create_hook_image(text, target_width, output_image_path="hook_overlay.png", font_scale=1.0, style="pill",
|
||||||
|
font=None):
|
||||||
"""
|
"""
|
||||||
Generates a hook overlay image using pixel-based wrapping.
|
Generates a hook overlay image using pixel-based wrapping.
|
||||||
target_width: The max width the box should occupy (e.g. 85% of video)
|
target_width: The max width the box should occupy (e.g. 85% of video)
|
||||||
|
|
@ -266,10 +276,11 @@ def create_hook_image(text, target_width, output_image_path="hook_overlay.png",
|
||||||
|
|
||||||
# Font Size Calculation (approx 5% of width - tuned to match Noto Serif Bold metrics in browser)
|
# Font Size Calculation (approx 5% of width - tuned to match Noto Serif Bold metrics in browser)
|
||||||
pills = bool(look.get("pills"))
|
pills = bool(look.get("pills"))
|
||||||
font_path = look.get("font") or FONT_PATH
|
# A chosen typeface (HOOK_FONTS key) wins; otherwise the style's own
|
||||||
# The pill sans reads smaller than Noto Serif at the same size: 6.4% of
|
# (pill -> Montserrat, the rest -> Noto Serif, as they always rendered).
|
||||||
# the box width puts both at the same visual weight.
|
default_font = "montserrat" if look.get("font") == PILL_FONT_PATH else "serif"
|
||||||
base_font_size = int(target_width * (0.064 if pills else 0.05))
|
font_path, size_factor = HOOK_FONTS.get(font or default_font, HOOK_FONTS[default_font])
|
||||||
|
base_font_size = int(target_width * size_factor)
|
||||||
font_size = int(base_font_size * font_scale)
|
font_size = int(base_font_size * font_scale)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -415,7 +426,7 @@ def create_hook_image(text, target_width, output_image_path="hook_overlay.png",
|
||||||
return output_image_path, canvas_w, canvas_h
|
return output_image_path, canvas_w, canvas_h
|
||||||
|
|
||||||
def add_hook_to_video(video_path, text, output_path, position="top", font_scale=1.0, duration=None, style="pill",
|
def add_hook_to_video(video_path, text, output_path, position="top", font_scale=1.0, duration=None, style="pill",
|
||||||
also=None):
|
also=None, font=None):
|
||||||
"""
|
"""
|
||||||
Overlays text hook onto video.
|
Overlays text hook onto video.
|
||||||
position: 'top', 'center', 'bottom'
|
position: 'top', 'center', 'bottom'
|
||||||
|
|
@ -456,7 +467,8 @@ def add_hook_to_video(video_path, text, output_path, position="top", font_scale=
|
||||||
f"{_truncate_bytes(stem, 80)}.png")
|
f"{_truncate_bytes(stem, 80)}.png")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
img_path, box_w, box_h = create_hook_image(text, target_box_width, hook_filename, font_scale=font_scale, style=style)
|
img_path, box_w, box_h = create_hook_image(text, target_box_width, hook_filename, font_scale=font_scale, style=style,
|
||||||
|
font=font)
|
||||||
|
|
||||||
# 3. Calculate Overlay Position
|
# 3. Calculate Overlay Position
|
||||||
overlay_x = (video_width - box_w) // 2
|
overlay_x = (video_width - box_w) // 2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue