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:
victorcavero14 2026-09-26 01:57:30 +02:00
parent a9818832b3
commit 77d3a1143e
9 changed files with 129 additions and 46 deletions

5
app.py
View file

@ -4927,6 +4927,7 @@ class HookRequest(BaseModel):
size: Optional[str] = "M" # S, M, L
duration_seconds: Optional[float] = None # None = hook visible for the whole clip
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
@app.post("/api/hook")
@ -5002,7 +5003,7 @@ async def add_hook(req: HookRequest, request: Request):
try:
# Run in thread pool
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()
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)
else:
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,
}

Binary file not shown.

View file

@ -424,8 +424,9 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected }
<div className="divide-y divide-rule">
{(videos || []).map((v) => {
const run = v.run;
const canRun = eligible && (!run || run.status === 'failed'
|| (run.status === 'skipped' && run.reason !== 'youtube_short'));
// Skipped runs can be retried too: private videos used to be
// misread as Shorts, and a real Short just skips again.
const canRun = eligible && (!run || run.status === 'failed' || run.status === 'skipped');
return (
<div key={v.id} className="flex items-center gap-3 py-3">
{v.thumbnail_url ? (

View file

@ -22,6 +22,20 @@ const HOOK_STYLES = [
{ 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 = [
{ value: 'top', label: 'top' },
{ 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 [size, setSize] = useState(prefs.size || 'M');
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 [displayDuration, setDisplayDuration] = useState(5);
@ -57,6 +74,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
position,
size,
style,
font: effectiveFont,
entranceAnimation,
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 (
<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>
<div className="flex flex-col md:flex-row gap-6">
{/* 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 ? (
<RemotionPreview
videoUrl={videoUrl}
@ -104,7 +123,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
style={{
...getSizeStyle(),
backgroundColor: 'rgba(255, 255, 255, 0.82)',
fontFamily: 'Noto Serif, serif',
...FONT_CSS[effectiveFont],
boxShadow: '0 4px 15px rgba(0,0,0,0.5)',
paddingTop: '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)]'}`}
title={s.label}
>
<span
className="block rounded px-1 py-1 font-bold"
style={{
backgroundColor: s.box,
color: s.text,
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',
}}
>Aa</span>
{s.value === 'pill' ? (
<span className="flex flex-col items-center gap-0.5 py-0.5" style={FONT_CSS[font || styleFont(s.value)]}>
<span className="rounded-md px-1.5 text-[13px] leading-5 bg-white text-black">Aa Bb</span>
<span className="rounded-md px-1.5 text-[13px] leading-5 bg-white text-black">Cc</span>
</span>
) : (
<span
className="block rounded-md px-1 py-1.5 text-[15px] leading-5"
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>
</button>
))}
</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 */}
<div>
<p className="eyebrow mb-2">Position</p>
@ -190,7 +234,8 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
</div>
{/* Entrance Animation (new) */}
<div className={serverRender ? 'opacity-50' : ''}>
{!serverRender && (
<div>
<p className="eyebrow mb-2">Entrance</p>
<SegmentedControl
options={ENTRANCE_OPTIONS}
@ -199,13 +244,8 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
columns={2}
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>
)}
{/* Display Duration (new) */}
<div>
@ -258,11 +298,11 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
onClick={() => {
try {
localStorage.setItem('os_hook_prefs', JSON.stringify({
style, position, size, entranceAnimation,
style, font, position, size, entranceAnimation,
}));
} catch { /* ignore */ }
onGenerate({
text, position, size, style,
text, position, size, style, font: effectiveFont,
// Remotion data
remotion: hookConfig,
});
@ -271,7 +311,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
className="btn-primary flex-1"
>
{isProcessing && <Loader2 size={16} className="animate-spin text-brassink" />}
{isProcessing ? 'generating...' : 'add hook'}
{isProcessing ? 'saving...' : (burnedHook ? 'update hook' : 'add hook')}
</button>
</div>
</div>

View file

@ -539,7 +539,8 @@ export default function ResultCard({ clip, index, jobId, durable, uploadPostKey,
text: payload.text,
position: payload.position,
size: payload.size,
style: payload.style || 'classic',
style: payload.style || 'pill',
font: payload.font || null,
duration_seconds: payload.remotion?.displayDurationSec ?? null,
input_filename: serverVideoFile
})
@ -956,7 +957,7 @@ export default function ResultCard({ clip, index, jobId, durable, uploadPostKey,
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 ? 'adding…' : 'viral hook'}
{isHooking ? 'saving…' : 'edit hook'}
</button>
<button

View file

@ -10,9 +10,9 @@ import {
import type { HookConfig } from "../lib/types";
import {
notoSerifFontFace,
NOTO_SERIF_FONT_FAMILY,
montserratFontFace,
MONTSERRAT_FONT_FAMILY,
antonFontFace,
HOOK_FONTS,
} from "../lib/fonts";
interface HookOverlayProps {
@ -59,7 +59,7 @@ export const HookOverlay: React.FC<HookOverlayProps> = ({ config }) => {
return (
<AbsoluteFill>
<style>{notoSerifFontFace + montserratFontFace}</style>
<style>{notoSerifFontFace + montserratFontFace + antonFontFace}</style>
<Sequence from={0} durationInFrames={displayFrames} layout="none">
<HookBox config={config} displayFrames={displayFrames} />
</Sequence>
@ -127,9 +127,10 @@ const HookBox: React.FC<HookBoxProps> = ({ config, displayFrames }) => {
const positionStyle = POSITION_STYLE[config.position] ?? POSITION_STYLE.top;
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.
const baseFontSize = 1080 * 0.9 * (look.pills ? 0.064 : 0.05 / 0.9);
const fontSize = Math.round(baseFontSize * scale);
// Typeface and size as hooks.py: the chosen font, else the style's own;
// font size = factor x the 90%-of-width box.
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);
if (look.pills) {
@ -157,9 +158,9 @@ const HookBox: React.FC<HookBoxProps> = ({ config, displayFrames }) => {
>
<span
style={{
fontFamily: `'${MONTSERRAT_FONT_FAMILY}', 'Montserrat', sans-serif`,
fontFamily: typeface.family,
fontSize,
fontWeight: 800,
fontWeight: typeface.weight,
color: look.text,
backgroundColor: look.box ?? "transparent",
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
style={{
fontFamily: `'${NOTO_SERIF_FONT_FAMILY}', 'Noto Serif', Georgia, serif`,
fontFamily: typeface.family,
fontSize,
fontWeight: 700,
fontWeight: typeface.weight,
color: look.text,
lineHeight: 1.4,
wordBreak: "break-word",

View file

@ -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.
* These match the options available in SubtitleModal.jsx.

View file

@ -45,11 +45,15 @@ export type HookStyle =
| "outline"
| "outline_yellow";
export type HookFont = "montserrat" | "anton" | "serif";
export interface HookConfig {
text: string;
position: HookPosition;
size: HookSize;
style?: HookStyle;
/** montserrat | anton | serif; unset = the style's own typeface. */
font?: HookFont;
entranceAnimation: HookEntrance;
displayDurationSec: number;
}
@ -114,6 +118,7 @@ export const hookConfigSchema = z.object({
style: z
.enum(["pill", "classic", "dark", "yellow", "red", "outline", "outline_yellow"])
.default("pill"),
font: z.enum(["montserrat", "anton", "serif"]).optional(),
entranceAnimation: z.enum(["spring", "fade", "slide-up", "none"]),
displayDurationSec: z.number().positive(),
});

View file

@ -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.
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).
_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
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.
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)
pills = bool(look.get("pills"))
font_path = look.get("font") or FONT_PATH
# The pill sans reads smaller than Noto Serif at the same size: 6.4% of
# the box width puts both at the same visual weight.
base_font_size = int(target_width * (0.064 if pills else 0.05))
# A chosen typeface (HOOK_FONTS key) wins; otherwise the style's own
# (pill -> Montserrat, the rest -> Noto Serif, as they always rendered).
default_font = "montserrat" if look.get("font") == PILL_FONT_PATH else "serif"
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)
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
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.
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")
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
overlay_x = (video_width - box_w) // 2