This commit is contained in:
parent
4bee851d5d
commit
5f1108a055
1 changed files with 165 additions and 47 deletions
212
cadence.py
212
cadence.py
|
|
@ -56,7 +56,7 @@ from typing import Literal
|
|||
|
||||
logger = logging.getLogger("cadence")
|
||||
|
||||
__version__ = "0.3.3"
|
||||
__version__ = "0.4.0"
|
||||
|
||||
# Regex to catch elongated sounds like 'aaaa', 'uhhh', 'ummm', 'mmmm', 'eeeh', etc.
|
||||
HESITATION_REGEX = re.compile(
|
||||
|
|
@ -1635,54 +1635,172 @@ def map_words_to_edited_timeline(
|
|||
|
||||
|
||||
LLM_PROMPT_LINES: tuple[str, ...] = (
|
||||
"SYSTEM PROMPT / INSTRUCTIONS:",
|
||||
"You are an elite YouTube packaging strategist and retention specialist.",
|
||||
"Your single goal: Maximize Click-Through Rate (CTR), Average Percentage Viewed (APV/Retention), and Subscriber Conversion.",
|
||||
"",
|
||||
"Analyze the provided transcript timeline (which has already been cut for pacing with dead silences and hesitations removed) and generate high-performance video assets.",
|
||||
"",
|
||||
"---",
|
||||
"",
|
||||
"### DELIVERABLES REQUIRED",
|
||||
"",
|
||||
"#### 1. PACKAGING CONCEPTS (A/B/C Test Pairs for Maximum CTR)",
|
||||
"Provide exactly 3 distinct packaging angles. Each angle MUST be an interconnected Title + Thumbnail Concept pair.",
|
||||
"- Titles must be under 55 characters, front-load high stakes, avoid disappointment, and open compelling curiosity gaps.",
|
||||
"- Thumbnail concepts must specify clear visual framing, high-contrast focal points, clean backgrounds, emotional expressions, and an optional 1-3 word punchy text overlay.",
|
||||
"",
|
||||
"Angle A (High-Stakes Challenge / Conflict / Curiosity):",
|
||||
"- Title:",
|
||||
"- Thumbnail Visual:",
|
||||
"- Text Overlay:",
|
||||
"",
|
||||
"Angle B (Transformation / Extreme Result / Value Delivery):",
|
||||
"- Title:",
|
||||
"- Thumbnail Visual:",
|
||||
"- Text Overlay:",
|
||||
"",
|
||||
"Angle C (Contrarian / Unconventional / 'I Was Wrong' Angle):",
|
||||
"- Title:",
|
||||
"- Thumbnail Visual:",
|
||||
"- Text Overlay:",
|
||||
"",
|
||||
"#### 2. HOOK-FIRST DESCRIPTION SUMMARY",
|
||||
"- Write exactly one punchy, high-retention paragraph (3-4 sentences max).",
|
||||
"- Sentence 1: The core hook stating the primary objective or premise.",
|
||||
"- Sentence 2: The tension, struggle, or key pivot point encountered.",
|
||||
"- Sentence 3: The outcome/payoff with primary search keywords naturally embedded.",
|
||||
"",
|
||||
"#### 3. RETENTION-DRIVEN VIDEO CHAPTERS",
|
||||
"- Format: `00:00 - Chapter Title`",
|
||||
"- The first chapter MUST start at `00:00`.",
|
||||
"- Space chapters every 90 seconds to 4 minutes based on key milestone transitions.",
|
||||
"- Use curiosity-driven milestone titles (e.g. 'The fatal mistake', 'Refactoring everything', 'The final run').",
|
||||
"",
|
||||
"---",
|
||||
"[EDITED VIDEO TRANSCRIPT TIMELINE STARTS BELOW]",
|
||||
"",
|
||||
"""SYSTEM PROMPT / INSTRUCTIONS:
|
||||
|
||||
You are a YouTube packaging strategist for a Minecraft survival/build series.
|
||||
|
||||
You optimise two metrics that must never be conflated:
|
||||
- CTR: does the package win the click in a cold Suggested feed?
|
||||
- APV: does the video deliver what the package promised after the click?
|
||||
|
||||
MEASURED FAILURE MODES ON THIS CHANNEL - do not repeat them:
|
||||
1. Titles promise a disaster while the video opens on base-building admin. The median viewer
|
||||
left at 0:37 on a 33-minute video.
|
||||
2. The title event fires late. One video titled "Farm Burns Itself Down" did not burn until
|
||||
32:12 of a 33:22 runtime.
|
||||
3. Thumbnails without a human face underperformed. Every better-performing thumbnail carried an
|
||||
extreme facial reaction.
|
||||
4. Hedged-question titles ("Too dangerous?", "It's broken?") converted below the channel's own
|
||||
Suggested baseline.
|
||||
5. More cuts did not fix the opening. The worst-retaining video had the most cuts in its first
|
||||
30 seconds.
|
||||
|
||||
Read the transcript timeline below before writing anything. It has already been cut for pacing:
|
||||
dead silences, filler and hesitations are removed, so every timestamp is a timestamp in the
|
||||
final edited video. Use only what appears in it.""",
|
||||
"""### STEP 0 - EVENT LEDGER
|
||||
|
||||
Before any packaging, extract the five strongest concrete events from the transcript.
|
||||
|
||||
An event is something that visibly happens or is explicitly stated: a death, a loss, a
|
||||
discovery, a bug, a reversal, a completed build, a specific number.
|
||||
|
||||
Output a table:
|
||||
|
||||
| # | Timestamp | Event | Type (failure / gain / bug / reveal / decision) | Runtime % |
|
||||
|
||||
Rules:
|
||||
- Quote the line that establishes each event.
|
||||
- Mark anything you inferred rather than heard as [INFERRED].
|
||||
- Runtime % = timestamp / total runtime. You are given the runtime in VIDEO CONTEXT.
|
||||
- If you cannot find five real events, output fewer. Do not pad.""",
|
||||
"""### STEP 1 - TITLE EVENT CHECK
|
||||
|
||||
State the single event you are building the package around, and its runtime %.
|
||||
|
||||
Hard rules:
|
||||
- The title must name an event the edited video actually delivers.
|
||||
- If that event occurs after 25% of runtime, the package must open with a COLD OPEN: show the
|
||||
event in the first 10 seconds, then return to chronological order. State the exact cold-open
|
||||
timestamp range using footage that exists.
|
||||
- If no event is strong enough to carry a title, write "NO STRONG EVENT" and recommend the video
|
||||
stay unlisted until re-cut. Never manufacture a promise the footage does not keep.
|
||||
- A title that is only true at 30:00 is a defect, not a hook.""",
|
||||
"""### STEP 2 - TITLE RULES
|
||||
|
||||
- Under 55 characters.
|
||||
- Name one concrete object and one consequence.
|
||||
- Front-load the noun a Minecraft viewer would search: farm, cave, lava, void, bedrock, diamonds,
|
||||
creeper, skeleton, tree farm, canal, chunk, obsidian, boat.
|
||||
- No hedged questions. No "Too dangerous?", "Is it broken?", "What happened?".
|
||||
- No abstract nouns standing alone: "nostalgia", "efficiency", "chaos", "brain rot". They may
|
||||
only appear attached to a concrete object.
|
||||
- The title must be true at 0:10 of the edited video.""",
|
||||
"""### STEP 2 - THUMBNAIL RULES
|
||||
|
||||
These are measured constraints, not style preferences:
|
||||
|
||||
- Exactly one human face or character, at least 25% of frame height, with an extreme readable
|
||||
expression: panic, shock, grimace, despair, disbelief. A face is the fastest-parsing element
|
||||
at 210x118 px.
|
||||
- The image must literally contain the title's subject. If the title says farm, show crops. If it
|
||||
says lava, show lava.
|
||||
- Text overlay: one to three words, maximum two lines, each line at least 12% of frame height.
|
||||
- Text must sit on the darkest or lightest area of the frame. Never white text on mid-grey stone,
|
||||
cobblestone, or dirt.
|
||||
- At least one saturated hue must be on the same side of the frame as the headline.
|
||||
- Any icon, arrow, cross or badge must be opaque and at least 15% of frame width.
|
||||
- No split where both halves show the same subject and palette. A split must carry different
|
||||
information: before/after, intact/destroyed, correct/wrong.
|
||||
- The design must survive 210x118 px.""",
|
||||
"""### STEP 2 - PACKAGING CONCEPTS
|
||||
|
||||
Produce exactly three interconnected Title + Thumbnail pairs.
|
||||
|
||||
For each angle state:
|
||||
- Title
|
||||
- Thumbnail subject and crop (where the face sits, how large, what fills the frame)
|
||||
- Text overlay (exact words)
|
||||
- The three shapes a viewer perceives at 210x118 px
|
||||
- Which promise from the title the image confirms
|
||||
|
||||
Angle A: the failure / loss angle
|
||||
Angle B: the gain / discovery angle
|
||||
Angle C: the decision / contrarian angle""",
|
||||
"""### STEP 3 - OPENING 30 SECONDS
|
||||
|
||||
This is the highest-leverage section of the whole package. Write the actual cold open, not advice.
|
||||
|
||||
- 0:00-0:03: the single strongest frame or line from the Event Ledger.
|
||||
- 0:03-0:15: the objective and the stake, in one sentence.
|
||||
- 0:15-0:30: the first sign of resistance - a cost, a risk, a failure.
|
||||
|
||||
Forbidden in the first 30 seconds: inventory admin, material lists, "let's continue from the last
|
||||
video", crafting prep, camera or menu setup, launcher problems, explaining the plan twice.
|
||||
|
||||
If the existing transcript opens with any of those, print "CURRENT OPENING VIOLATES" and give the
|
||||
replacement using a timestamp range that already exists in the footage.""",
|
||||
"""### STEP 4 - SECOND ACT (20-120s)
|
||||
|
||||
State what keeps a viewer past the hook. Name the concrete cost or constraint introduced between
|
||||
0:20 and 2:00.
|
||||
|
||||
Measured: videos whose 20-120s window contains only cosmetic work never recover; videos that
|
||||
introduce resource pressure or danger do.
|
||||
|
||||
If the transcript's 20-120s window is cosmetic, print "SECOND ACT IS COSMETIC - no reason to
|
||||
stay" and name the earliest later timestamp with real stakes.""",
|
||||
"""### STEP 5 - DESCRIPTION
|
||||
|
||||
- The first 150 characters must pay the title. Everything after that is hidden behind "...more".
|
||||
- Never open with "In this video", "Welcome back", or "Today we".
|
||||
- Sentence 1: the concrete event and its outcome.
|
||||
- Sentence 2: the obstacle that made it hard.
|
||||
- Sentence 3: what the viewer will see, with searchable nouns.
|
||||
- Then one short search-oriented paragraph, then the chapters.
|
||||
- Never describe an event that is not in the transcript.""",
|
||||
"""### STEP 6 - CHAPTERS
|
||||
|
||||
- Format: `00:00 - Title`
|
||||
- Chapter 1 must start at 00:00 and must be the hook event. Never "Intro", "Start", "Beginning".
|
||||
- Every chapter title must contain a concrete noun or a number.
|
||||
- Space chapters 90 seconds to 4 minutes at real milestone transitions.
|
||||
- The chapter containing the title event must be named after that event.""",
|
||||
"""### OUTPUT FORMAT
|
||||
|
||||
1. Event Ledger table
|
||||
2. Title Event Check: chosen event, timestamp, runtime %, cold-open required yes/no + range
|
||||
3. Three packaging angles
|
||||
4. Opening 30 seconds (include CURRENT OPENING VIOLATES if applicable)
|
||||
5. Second Act verdict
|
||||
6. Description
|
||||
7. Chapters""",
|
||||
"""---
|
||||
|
||||
[EDITED VIDEO TRANSCRIPT TIMELINE STARTS BELOW]""",
|
||||
)
|
||||
|
||||
|
||||
def _llm_prompt_lines(duration_sec: float) -> list[str]:
|
||||
"""Prompt header with the edited runtime injected before the transcript marker."""
|
||||
lines = list(LLM_PROMPT_LINES)
|
||||
marker = "[EDITED VIDEO TRANSCRIPT TIMELINE STARTS BELOW]"
|
||||
total = int(round(max(0.0, duration_sec)))
|
||||
mins, secs = divmod(total, 60)
|
||||
context = [
|
||||
"### VIDEO CONTEXT",
|
||||
f"- Total edited runtime: {mins}:{secs:02d} ({duration_sec:.1f}s)",
|
||||
"- Use this runtime for every percentage-of-runtime check.",
|
||||
"",
|
||||
]
|
||||
for i, block in enumerate(lines):
|
||||
if marker in block:
|
||||
head, sep, tail = block.partition(marker)
|
||||
lines[i] = head + "\n".join(context) + "\n" + sep + tail
|
||||
break
|
||||
return lines
|
||||
|
||||
|
||||
_TERMINAL_PUNCT = frozenset({".", "?", "!"})
|
||||
_CLAUSE_PUNCT = frozenset({",", ";", ":", "—", "-"})
|
||||
|
||||
|
|
@ -1813,7 +1931,7 @@ def generate_combined_transcripts(
|
|||
logger.info(f"[*] YouTube Captions generated -> {srt_path.name}")
|
||||
|
||||
llm_transcript_path = output_path.with_name(f"{output_path.stem}_llm_transcript.txt")
|
||||
llm_lines: list[str] = list(LLM_PROMPT_LINES)
|
||||
llm_lines: list[str] = _llm_prompt_lines(_edited_duration(track_data_list))
|
||||
|
||||
current_para: list[str] = []
|
||||
para_start = mapped_words[0][0]
|
||||
|
|
|
|||
Loading…
Reference in a new issue