feat(hooks): "pill" hook style, the new default
Every line of the hook gets its own white rounded box with black bold sans (Montserrat ExtraBold, SIL OFL, bundled in fonts/ with its license), the look short-form viewers know from TikTok. It replaces the serif white card as the default for auto hooks, the editor's hook modal and the /api/hook default; the other six styles stay selectable. - hooks.py: _draw_pills renders the stack for the FFmpeg path. - Remotion HookOverlay mirrors it (box-decoration-break: clone), so the editor preview matches the burned result. - The generate form says the hook text, style, position and size can be changed per clip afterwards; the saved style preference moves to a v2 key so the old stored default does not pin people to the serif card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0ef20db988
commit
a8509249da
13 changed files with 260 additions and 25 deletions
2
app.py
2
app.py
|
|
@ -4926,7 +4926,7 @@ class HookRequest(BaseModel):
|
||||||
position: Optional[str] = "top" # top, center, bottom
|
position: Optional[str] = "top" # top, center, bottom
|
||||||
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] = "classic" # classic/dark/yellow/red/outline/outline_yellow
|
style: Optional[str] = "pill" # pill/classic/dark/yellow/red/outline/outline_yellow
|
||||||
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")
|
||||||
|
|
|
||||||
BIN
dashboard/public/fonts/Montserrat-ExtraBold.ttf
Normal file
BIN
dashboard/public/fonts/Montserrat-ExtraBold.ttf
Normal file
Binary file not shown.
|
|
@ -542,7 +542,7 @@ function App() {
|
||||||
border_width: options.borderWidth,
|
border_width: options.borderWidth,
|
||||||
bg_color: options.bgColor,
|
bg_color: options.bgColor,
|
||||||
bg_opacity: options.bgOpacity,
|
bg_opacity: options.bgOpacity,
|
||||||
style: options.style || 'classic',
|
style: options.style || 'pill',
|
||||||
highlight_color: options.highlightColor || '#FFD700',
|
highlight_color: options.highlightColor || '#FFD700',
|
||||||
effect: options.effect || 'none',
|
effect: options.effect || 'none',
|
||||||
base_opacity: options.baseOpacity ?? 1.0,
|
base_opacity: options.baseOpacity ?? 1.0,
|
||||||
|
|
@ -984,7 +984,7 @@ function App() {
|
||||||
// Sent explicitly both ways: absent means off for raw API callers,
|
// Sent explicitly both ways: absent means off for raw API callers,
|
||||||
// but the dashboard always states the user's choice.
|
// but the dashboard always states the user's choice.
|
||||||
auto_hook: data.autoHook ? '1' : '0',
|
auto_hook: data.autoHook ? '1' : '0',
|
||||||
auto_hook_style: data.autoHook ? (data.autoHookStyle || 'classic') : null,
|
auto_hook_style: data.autoHook ? (data.autoHookStyle || 'pill') : null,
|
||||||
// 'auto' is the server default, so only a deliberate choice travels.
|
// 'auto' is the server default, so only a deliberate choice travels.
|
||||||
layouts: data.layout && data.layout !== 'auto' ? data.layout : null,
|
layouts: data.layout && data.layout !== 'auto' ? data.layout : null,
|
||||||
// Set when the user took the quota wall's "clip the first N minutes"
|
// Set when the user took the quota wall's "clip the first N minutes"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ const ENTRANCE_OPTIONS = [
|
||||||
|
|
||||||
// Must mirror hooks.py HOOK_STYLES.
|
// Must mirror hooks.py HOOK_STYLES.
|
||||||
const HOOK_STYLES = [
|
const HOOK_STYLES = [
|
||||||
|
{ value: 'pill', label: 'Pills', box: 'rgba(255,255,255,0.98)', text: '#000', sans: true },
|
||||||
{ value: 'classic', label: 'Classic', box: 'rgba(255,255,255,0.94)', text: '#000' },
|
{ value: 'classic', label: 'Classic', box: 'rgba(255,255,255,0.94)', text: '#000' },
|
||||||
{ value: 'dark', label: 'Dark', box: 'rgba(18,18,20,0.92)', text: '#fff' },
|
{ value: 'dark', label: 'Dark', box: 'rgba(18,18,20,0.92)', text: '#fff' },
|
||||||
{ value: 'yellow', label: 'Yellow', box: 'rgba(255,214,0,0.96)', text: '#000' },
|
{ value: 'yellow', label: 'Yellow', box: 'rgba(255,214,0,0.96)', text: '#000' },
|
||||||
|
|
@ -44,7 +45,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
const [text, setText] = useState(initialText || 'POV: You are using the viral hook feature');
|
const [text, setText] = useState(initialText || 'POV: You are using the viral hook feature');
|
||||||
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 || 'classic');
|
const [style, setStyle] = useState(prefs.style || 'pill');
|
||||||
const [entranceAnimation, setEntranceAnimation] = useState(prefs.entranceAnimation || 'spring');
|
const [entranceAnimation, setEntranceAnimation] = useState(prefs.entranceAnimation || 'spring');
|
||||||
const [displayDuration, setDisplayDuration] = useState(5);
|
const [displayDuration, setDisplayDuration] = useState(5);
|
||||||
|
|
||||||
|
|
@ -79,8 +80,11 @@ 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;}";
|
||||||
|
|
||||||
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="viral hook">
|
||||||
|
<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="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]">
|
||||||
|
|
@ -125,8 +129,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
value={text}
|
value={text}
|
||||||
onChange={(e) => setText(e.target.value)}
|
onChange={(e) => setText(e.target.value)}
|
||||||
rows={4}
|
rows={4}
|
||||||
className="input-field resize-none font-serif"
|
className="input-field resize-none"
|
||||||
style={{ fontFamily: 'Noto Serif, serif' }}
|
|
||||||
placeholder="Enter text that will stop the scroll..."
|
placeholder="Enter text that will stop the scroll..."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -148,6 +151,7 @@ export default function HookModal({ isOpen, onClose, onGenerate, onRemove, isPro
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: s.box,
|
backgroundColor: s.box,
|
||||||
color: s.text,
|
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',
|
textShadow: s.outline ? '-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000' : 'none',
|
||||||
}}
|
}}
|
||||||
>Aa</span>
|
>Aa</span>
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,8 @@ export default function MediaInput({ onProcess, isProcessing }) {
|
||||||
try { return localStorage.getItem('os_auto_hook') !== '0'; } catch { return true; }
|
try { return localStorage.getItem('os_auto_hook') !== '0'; } catch { return true; }
|
||||||
});
|
});
|
||||||
const [autoHookStyle, setAutoHookStyle] = useState(() => {
|
const [autoHookStyle, setAutoHookStyle] = useState(() => {
|
||||||
try { return localStorage.getItem('os_auto_hook_style') || 'classic'; } catch { return 'classic'; }
|
// v2 key: the default became 'pill'; an old saved 'classic' was just the old default.
|
||||||
|
try { return localStorage.getItem('os_auto_hook_style_v2') || 'pill'; } catch { return 'pill'; }
|
||||||
});
|
});
|
||||||
// Layout: 'auto' lets the AI pick per video (server default); the others
|
// Layout: 'auto' lets the AI pick per video (server default); the others
|
||||||
// force one on so a podcast host who knows what they uploaded doesn't
|
// force one on so a podcast host who knows what they uploaded doesn't
|
||||||
|
|
@ -126,7 +127,7 @@ export default function MediaInput({ onProcess, isProcessing }) {
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
localStorage.setItem('os_auto_hook', autoHook ? '1' : '0');
|
localStorage.setItem('os_auto_hook', autoHook ? '1' : '0');
|
||||||
localStorage.setItem('os_auto_hook_style', autoHookStyle);
|
localStorage.setItem('os_auto_hook_style_v2', autoHookStyle);
|
||||||
localStorage.setItem('os_layout', layout);
|
localStorage.setItem('os_layout', layout);
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
if (mode === 'url' && url) {
|
if (mode === 'url' && url) {
|
||||||
|
|
@ -370,6 +371,7 @@ export default function MediaInput({ onProcess, isProcessing }) {
|
||||||
onChange={(e) => setAutoHookStyle(e.target.value)}
|
onChange={(e) => setAutoHookStyle(e.target.value)}
|
||||||
className="input-field !w-auto text-xs py-1.5"
|
className="input-field !w-auto text-xs py-1.5"
|
||||||
>
|
>
|
||||||
|
<option value="pill">Pills</option>
|
||||||
<option value="classic">Classic</option>
|
<option value="classic">Classic</option>
|
||||||
<option value="dark">Dark</option>
|
<option value="dark">Dark</option>
|
||||||
<option value="yellow">Yellow</option>
|
<option value="yellow">Yellow</option>
|
||||||
|
|
@ -378,6 +380,12 @@ export default function MediaInput({ onProcess, isProcessing }) {
|
||||||
<option value="outline_yellow">Outline+</option>
|
<option value="outline_yellow">Outline+</option>
|
||||||
</select>
|
</select>
|
||||||
)}
|
)}
|
||||||
|
{autoHook && (
|
||||||
|
<p className="w-full text-[11px] leading-relaxed text-muted">
|
||||||
|
You can change each clip's hook text, style, position and size
|
||||||
|
afterwards with its hook button.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,12 @@ import {
|
||||||
interpolate,
|
interpolate,
|
||||||
} from "remotion";
|
} from "remotion";
|
||||||
import type { HookConfig } from "../lib/types";
|
import type { HookConfig } from "../lib/types";
|
||||||
import { notoSerifFontFace, NOTO_SERIF_FONT_FAMILY } from "../lib/fonts";
|
import {
|
||||||
|
notoSerifFontFace,
|
||||||
|
NOTO_SERIF_FONT_FAMILY,
|
||||||
|
montserratFontFace,
|
||||||
|
MONTSERRAT_FONT_FAMILY,
|
||||||
|
} from "../lib/fonts";
|
||||||
|
|
||||||
interface HookOverlayProps {
|
interface HookOverlayProps {
|
||||||
config: HookConfig;
|
config: HookConfig;
|
||||||
|
|
@ -34,9 +39,12 @@ interface HookLook {
|
||||||
text: string;
|
text: string;
|
||||||
outlinePx: number;
|
outlinePx: number;
|
||||||
shadow: boolean;
|
shadow: boolean;
|
||||||
|
/** One rounded box per line (hooks.py _draw_pills) instead of one card. */
|
||||||
|
pills?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const HOOK_LOOKS: Record<string, HookLook> = {
|
const HOOK_LOOKS: Record<string, HookLook> = {
|
||||||
|
pill: { box: "rgba(255, 255, 255, 0.98)", text: "#000000", outlinePx: 0, shadow: false, pills: true },
|
||||||
classic: { box: "rgba(255, 255, 255, 0.94)", text: "#000000", outlinePx: 0, shadow: true },
|
classic: { box: "rgba(255, 255, 255, 0.94)", text: "#000000", outlinePx: 0, shadow: true },
|
||||||
dark: { box: "rgba(18, 18, 20, 0.92)", text: "#FFFFFF", outlinePx: 0, shadow: true },
|
dark: { box: "rgba(18, 18, 20, 0.92)", text: "#FFFFFF", outlinePx: 0, shadow: true },
|
||||||
yellow: { box: "rgba(255, 214, 0, 0.96)", text: "#000000", outlinePx: 0, shadow: true },
|
yellow: { box: "rgba(255, 214, 0, 0.96)", text: "#000000", outlinePx: 0, shadow: true },
|
||||||
|
|
@ -51,7 +59,7 @@ export const HookOverlay: React.FC<HookOverlayProps> = ({ config }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AbsoluteFill>
|
<AbsoluteFill>
|
||||||
<style>{notoSerifFontFace}</style>
|
<style>{notoSerifFontFace + montserratFontFace}</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>
|
||||||
|
|
@ -117,13 +125,57 @@ 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 ?? "classic"] ?? HOOK_LOOKS.classic;
|
const look = HOOK_LOOKS[config.style ?? "pill"] ?? HOOK_LOOKS.pill;
|
||||||
|
|
||||||
// Base font size: 5% of 1080 width (matches hooks.py logic)
|
// Base font size: 5% (serif) / 6.4% (pill sans) of the 90% box, as hooks.py.
|
||||||
const baseFontSize = 1080 * 0.05;
|
const baseFontSize = 1080 * 0.9 * (look.pills ? 0.064 : 0.05 / 0.9);
|
||||||
const fontSize = Math.round(baseFontSize * scale);
|
const fontSize = Math.round(baseFontSize * scale);
|
||||||
const outlinePx = Math.round(look.outlinePx * scale);
|
const outlinePx = Math.round(look.outlinePx * scale);
|
||||||
|
|
||||||
|
if (look.pills) {
|
||||||
|
// box-decoration-break: clone gives every wrapped line its own padded,
|
||||||
|
// rounded box, the same stack hooks.py draws for the FFmpeg path.
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "center",
|
||||||
|
...positionStyle,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
opacity: animOpacity,
|
||||||
|
transform: `scale(${animScale}) translateY(${animTranslateY}px)`,
|
||||||
|
maxWidth: "90%",
|
||||||
|
textAlign: "center",
|
||||||
|
lineHeight: 1.62,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontFamily: `'${MONTSERRAT_FONT_FAMILY}', 'Montserrat', sans-serif`,
|
||||||
|
fontSize,
|
||||||
|
fontWeight: 800,
|
||||||
|
color: look.text,
|
||||||
|
backgroundColor: look.box ?? "transparent",
|
||||||
|
padding: `${Math.round(fontSize * 0.2)}px ${Math.round(fontSize * 0.48)}px`,
|
||||||
|
borderRadius: Math.round(fontSize * 0.36),
|
||||||
|
WebkitBoxDecorationBreak: "clone",
|
||||||
|
boxDecorationBreak: "clone",
|
||||||
|
wordBreak: "break-word",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{config.text}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,18 @@ export const notoSerifFontFace = `
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
/** Montserrat ExtraBold (bundled, SIL OFL): the "pill" hook style's sans. */
|
||||||
|
export const MONTSERRAT_FONT_FAMILY = "Montserrat-ExtraBold";
|
||||||
|
|
||||||
|
export const montserratFontFace = `
|
||||||
|
@font-face {
|
||||||
|
font-family: '${MONTSERRAT_FONT_FAMILY}';
|
||||||
|
src: url('${staticFile("fonts/Montserrat-ExtraBold.ttf")}') format('truetype');
|
||||||
|
font-weight: 800;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ export type HookPosition = "top" | "center" | "bottom";
|
||||||
export type HookSize = "S" | "M" | "L";
|
export type HookSize = "S" | "M" | "L";
|
||||||
export type HookEntrance = "spring" | "fade" | "slide-up" | "none";
|
export type HookEntrance = "spring" | "fade" | "slide-up" | "none";
|
||||||
export type HookStyle =
|
export type HookStyle =
|
||||||
|
| "pill"
|
||||||
| "classic"
|
| "classic"
|
||||||
| "dark"
|
| "dark"
|
||||||
| "yellow"
|
| "yellow"
|
||||||
|
|
@ -111,8 +112,8 @@ export const hookConfigSchema = z.object({
|
||||||
position: z.enum(["top", "center", "bottom"]),
|
position: z.enum(["top", "center", "bottom"]),
|
||||||
size: z.enum(["S", "M", "L"]),
|
size: z.enum(["S", "M", "L"]),
|
||||||
style: z
|
style: z
|
||||||
.enum(["classic", "dark", "yellow", "red", "outline", "outline_yellow"])
|
.enum(["pill", "classic", "dark", "yellow", "red", "outline", "outline_yellow"])
|
||||||
.default("classic"),
|
.default("pill"),
|
||||||
entranceAnimation: z.enum(["spring", "fade", "slide-up", "none"]),
|
entranceAnimation: z.enum(["spring", "fade", "slide-up", "none"]),
|
||||||
displayDurationSec: z.number().positive(),
|
displayDurationSec: z.number().positive(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
BIN
fonts/Montserrat-ExtraBold.ttf
Normal file
BIN
fonts/Montserrat-ExtraBold.ttf
Normal file
Binary file not shown.
93
fonts/Montserrat-OFL.txt
Normal file
93
fonts/Montserrat-OFL.txt
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
Copyright 2024 The Montserrat.Git Project Authors (https://github.com/JulietaUla/Montserrat.git)
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
https://openfontlicense.org
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting -- in part or in whole -- any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
58
hooks.py
58
hooks.py
|
|
@ -23,6 +23,8 @@ def _truncate_bytes(text, max_bytes):
|
||||||
FONT_URL = "https://github.com/googlefonts/noto-fonts/raw/main/hinted/ttf/NotoSerif/NotoSerif-Bold.ttf"
|
FONT_URL = "https://github.com/googlefonts/noto-fonts/raw/main/hinted/ttf/NotoSerif/NotoSerif-Bold.ttf"
|
||||||
FONT_DIR = "fonts"
|
FONT_DIR = "fonts"
|
||||||
FONT_PATH = os.path.join(FONT_DIR, "NotoSerif-Bold.ttf")
|
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")
|
||||||
|
|
||||||
# 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(
|
||||||
|
|
@ -190,6 +192,10 @@ def download_font_if_needed():
|
||||||
# Hook visual styles. Each maps to box fill (RGBA, alpha 0 = no box), text
|
# Hook visual styles. Each maps to box fill (RGBA, alpha 0 = no box), text
|
||||||
# color, and an optional text outline (color, px) for box-less looks.
|
# color, and an optional text outline (color, px) for box-less looks.
|
||||||
HOOK_STYLES = {
|
HOOK_STYLES = {
|
||||||
|
# Default. TikTok-native look: every line its own white rounded box,
|
||||||
|
# black bold sans (Montserrat ExtraBold).
|
||||||
|
"pill": {"box": (255, 255, 255, 250), "text": (0, 0, 0), "outline": None, "shadow": False,
|
||||||
|
"font": PILL_FONT_PATH, "pills": True},
|
||||||
# White card, black serif text (original look).
|
# White card, black serif text (original look).
|
||||||
"classic": {"box": (255, 255, 255, 240), "text": (0, 0, 0), "outline": None, "shadow": True},
|
"classic": {"box": (255, 255, 255, 240), "text": (0, 0, 0), "outline": None, "shadow": True},
|
||||||
# Dark card, white text.
|
# Dark card, white text.
|
||||||
|
|
@ -205,15 +211,45 @@ HOOK_STYLES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_hook_image(text, target_width, output_image_path="hook_overlay.png", font_scale=1.0, style="classic"):
|
def _draw_pills(lines, font, emoji_font, font_size, box_fill, text_fill, output_image_path):
|
||||||
|
"""One rounded box per line, stacked and centred (the "pill" style).
|
||||||
|
|
||||||
|
Every box has the same height (from the font's own ascent/descent plus
|
||||||
|
accents), so the stack reads as one block whatever the letters are.
|
||||||
|
"""
|
||||||
|
lines = [ln for ln in lines if ln.strip()] or [" "]
|
||||||
|
pad_x = int(font_size * 0.48)
|
||||||
|
pad_y = int(font_size * 0.24)
|
||||||
|
radius = int(font_size * 0.36)
|
||||||
|
probe = ImageDraw.Draw(Image.new('RGBA', (1, 1)))
|
||||||
|
top, bottom = probe.textbbox((0, 0), "ÁÉÍÓÚÑgjpqy", font=font)[1::2]
|
||||||
|
line_h = (bottom - top) + 2 * pad_y
|
||||||
|
widths = [int(_measure_width(probe, ln, font, emoji_font)) for ln in lines]
|
||||||
|
canvas_w = max(widths) + 2 * pad_x + 40
|
||||||
|
canvas_h = line_h * len(lines) + 40
|
||||||
|
|
||||||
|
img = Image.new('RGBA', (canvas_w, canvas_h), (0, 0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
for i, (ln, w) in enumerate(zip(lines, widths)):
|
||||||
|
box_w = w + 2 * pad_x
|
||||||
|
x0 = (canvas_w - box_w) // 2
|
||||||
|
y0 = 20 + i * line_h
|
||||||
|
draw.rounded_rectangle([x0, y0, x0 + box_w, y0 + line_h], radius=radius, fill=box_fill)
|
||||||
|
_draw_mixed(img, draw, (x0 + pad_x, y0 + pad_y - top), ln, font, emoji_font,
|
||||||
|
fill=text_fill, outline=None)
|
||||||
|
img.save(output_image_path)
|
||||||
|
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"):
|
||||||
"""
|
"""
|
||||||
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)
|
||||||
style: one of HOOK_STYLES (classic/dark/yellow/red/outline/outline_yellow)
|
style: one of HOOK_STYLES (pill/classic/dark/yellow/red/outline/outline_yellow)
|
||||||
"""
|
"""
|
||||||
download_font_if_needed()
|
download_font_if_needed()
|
||||||
|
|
||||||
look = HOOK_STYLES.get(style, HOOK_STYLES["classic"])
|
look = HOOK_STYLES.get(style, HOOK_STYLES["pill"])
|
||||||
box_fill = look["box"]
|
box_fill = look["box"]
|
||||||
text_fill = look["text"]
|
text_fill = look["text"]
|
||||||
outline = look["outline"]
|
outline = look["outline"]
|
||||||
|
|
@ -229,13 +265,17 @@ def create_hook_image(text, target_width, output_image_path="hook_overlay.png",
|
||||||
shadow_blur = 10
|
shadow_blur = 10
|
||||||
|
|
||||||
# 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)
|
||||||
base_font_size = int(target_width * 0.05)
|
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))
|
||||||
font_size = int(base_font_size * font_scale)
|
font_size = int(base_font_size * font_scale)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
font = ImageFont.truetype(FONT_PATH, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Warning: Could not load font {FONT_PATH}, using default. Error: {e}")
|
print(f"⚠️ Warning: Could not load font {font_path}, using default. Error: {e}")
|
||||||
font = ImageFont.load_default()
|
font = ImageFont.load_default()
|
||||||
|
|
||||||
# Emoji handling: render with an emoji-capable font if one exists,
|
# Emoji handling: render with an emoji-capable font if one exists,
|
||||||
|
|
@ -291,6 +331,10 @@ def create_hook_image(text, target_width, output_image_path="hook_overlay.png",
|
||||||
if current_line:
|
if current_line:
|
||||||
lines.append(' '.join(current_line))
|
lines.append(' '.join(current_line))
|
||||||
|
|
||||||
|
if pills:
|
||||||
|
return _draw_pills(lines, font, emoji_font, font_size, box_fill, text_fill,
|
||||||
|
output_image_path)
|
||||||
|
|
||||||
# Recalculate true width/height
|
# Recalculate true width/height
|
||||||
max_line_width = 0
|
max_line_width = 0
|
||||||
text_heights = []
|
text_heights = []
|
||||||
|
|
@ -370,7 +414,7 @@ def create_hook_image(text, target_width, output_image_path="hook_overlay.png",
|
||||||
img.save(output_image_path)
|
img.save(output_image_path)
|
||||||
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="classic",
|
def add_hook_to_video(video_path, text, output_path, position="top", font_scale=1.0, duration=None, style="pill",
|
||||||
also=None):
|
also=None):
|
||||||
"""
|
"""
|
||||||
Overlays text hook onto video.
|
Overlays text hook onto video.
|
||||||
|
|
|
||||||
4
main.py
4
main.py
|
|
@ -1262,7 +1262,7 @@ def auto_hook_clip(clip_path, clip, captions=None):
|
||||||
text = (clip.get('viral_hook_text') or '').strip()
|
text = (clip.get('viral_hook_text') or '').strip()
|
||||||
if not text:
|
if not text:
|
||||||
return None
|
return None
|
||||||
style = os.environ.get("AUTO_HOOK_STYLE", "classic")
|
style = os.environ.get("AUTO_HOOK_STYLE", "pill")
|
||||||
try:
|
try:
|
||||||
seconds = float(os.environ.get("AUTO_HOOK_SECONDS", "5"))
|
seconds = float(os.environ.get("AUTO_HOOK_SECONDS", "5"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
@ -1270,7 +1270,7 @@ def auto_hook_clip(clip_path, clip, captions=None):
|
||||||
try:
|
try:
|
||||||
from hooks import add_hook_to_video, HOOK_STYLES
|
from hooks import add_hook_to_video, HOOK_STYLES
|
||||||
if style not in HOOK_STYLES:
|
if style not in HOOK_STYLES:
|
||||||
style = "classic"
|
style = "pill"
|
||||||
output_dir = os.path.dirname(clip_path)
|
output_dir = os.path.dirname(clip_path)
|
||||||
out_path = os.path.join(
|
out_path = os.path.join(
|
||||||
output_dir, f"hooked_{int(time.time())}_{os.path.basename(clip_path)}")
|
output_dir, f"hooked_{int(time.time())}_{os.path.basename(clip_path)}")
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,15 @@ class TestHookStyles:
|
||||||
|
|
||||||
def test_expected_style_names(self):
|
def test_expected_style_names(self):
|
||||||
assert set(HOOK_STYLES) == {
|
assert set(HOOK_STYLES) == {
|
||||||
"classic", "dark", "yellow", "red", "outline", "outline_yellow",
|
"pill", "classic", "dark", "yellow", "red", "outline", "outline_yellow",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def test_pill_is_one_box_per_line_in_the_bundled_sans(self):
|
||||||
|
look = HOOK_STYLES["pill"]
|
||||||
|
assert look["pills"] is True
|
||||||
|
assert look["font"].endswith("Montserrat-ExtraBold.ttf")
|
||||||
|
assert os.path.exists(look["font"]), "the pill font must ship with the repo"
|
||||||
|
|
||||||
def test_boxed_styles_have_opaque_box_and_shadow(self):
|
def test_boxed_styles_have_opaque_box_and_shadow(self):
|
||||||
for name in ("classic", "dark", "yellow", "red"):
|
for name in ("classic", "dark", "yellow", "red"):
|
||||||
look = HOOK_STYLES[name]
|
look = HOOK_STYLES[name]
|
||||||
|
|
@ -124,3 +130,18 @@ class TestCreateHookImage:
|
||||||
out = str(tmp_path / "hook_fallback.png")
|
out = str(tmp_path / "hook_fallback.png")
|
||||||
path, w, h = create_hook_image("Hola", 500, out, style="nope")
|
path, w, h = create_hook_image("Hola", 500, out, style="nope")
|
||||||
assert os.path.exists(path) and w > 0 and h > 0
|
assert os.path.exists(path) and w > 0 and h > 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_pill_hook_image_stacks_one_box_per_line(tmp_path):
|
||||||
|
"""Two lines of text -> two rows of box pixels with a boxless column
|
||||||
|
beside the shorter one (it is its own pill, not one shared card)."""
|
||||||
|
from hooks import create_hook_image
|
||||||
|
from PIL import Image
|
||||||
|
out = tmp_path / "pill.png"
|
||||||
|
path, w, h = create_hook_image("una frase bastante larga para partirse en dos lineas",
|
||||||
|
600, str(out), style="pill")
|
||||||
|
img = Image.open(path).convert("RGBA")
|
||||||
|
assert (img.width, img.height) == (w, h)
|
||||||
|
alpha_rows = [any(img.getpixel((x, y))[3] > 200 for x in range(0, img.width, 4))
|
||||||
|
for y in range(img.height)]
|
||||||
|
assert sum(alpha_rows) > 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue