Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.
Python ai-toolsauto-captionscaptionscliffmpegmcpmcp-serveropusclip-alternativepodcast-clipspodcastsshortform-videovertical-videowhisper
feat: major update — audit fixes, Claude integration, interactive CLI
Nika Siradze8dfb16d23a52
diff --git a/.claude/commands/plan-episode.md b/.claude/commands/plan-episode.mdnew file mode 100644index 0000000..80e151c--- /dev/null+++ b/.claude/commands/plan-episode.md@@ -0,0 +1,217 @@+# /plan-episode — Episode Architect++> You are an episode architect. You work BACKWARDS from the ideal output — viral shorts, compelling titles, a story that holds attention — to design questions, story arcs, and moments BEFORE the recording happens.++---++## Trigger++User says "plan episode", provides a guest name, or asks about preparing for an upcoming recording.++---++## Before Starting++Read the knowledge base:+- `.podcli/knowledge/01-brand-identity.md` — show positioning, what makes it unique+- `.podcli/knowledge/02-voice-and-tone.md` — voice fingerprint, what resonates with the audience+- `.podcli/knowledge/03-episodes-database.md` — past episodes (avoid repetition, find gaps)+- `.podcli/knowledge/05-title-formulas.md` — title patterns (design questions that produce title-worthy answers)+- `.podcli/knowledge/08-topics-themes.md` — core topics, audience interests+- `.podcli/knowledge/11-inspiration-channels.md` — reference channels and what they do well++If using podcli, replace `.podcli/knowledge/` with `.podcli/knowledge/`.++---++## Inputs++| Field | Required | Source |+|-------|----------|--------|+| Guest name | Yes | User provides |+| Company/Org | Yes | User provides |+| Guest role/title | Preferred | User provides or research |+| Topic area | Preferred | User provides or suggest |+| Guest background | Optional | User provides links, bio, or ask to research |+| Episode number | Optional | Auto from database |++---++## The Backwards Method++Start from the END (what you want to publish) and work backwards to the BEGINNING (what to ask).++### Step 1: Define the Ideal Output++Before designing questions, answer:++**What 8-12 shorts would you want from this episode?**++For each potential short, draft:+- A title that would stop the scroll (using the show's title formulas)+- The content type (Guest Story / Technical Insight / Market / Business / Hot Take)+- The one sentence the guest would need to say++This gives you a "moment map" — the specific things you need the guest to say or reveal.++### Step 2: Design the Story Arc++Every great podcast episode follows an arc. Design one:++```+ACT 1 — ORIGIN (10-15 min)+ Hook: The surprising thing about this guest/company+ Setup: How they got here (the non-obvious path)+ Tension: The moment everything almost failed++ACT 2 — INSIGHT (20-30 min)+ The core idea: What they know that most people don't+ The proof: Specific numbers, results, examples+ The contrarian take: Where they disagree with consensus++ACT 3 — FUTURE (10-15 min)+ The vision: Where this is going+ The advice: What they'd tell someone starting today+ The hot take: The bold prediction or unpopular opinion+```++### Step 3: Write the Questions++For each moment in the moment map, write the question that will produce it.++**Question types that produce viral moments:**++| Type | Pattern | Example | What it produces |+|------|---------|---------|-----------------|+| **The Origin Question** | "Take me back to the moment when..." | "Take me back to when you first realized [X] was broken" | Founder Story clips |+| **The Contrarian Probe** | "Most people think [X]. You disagree. Why?" | "Everyone says AI needs more GPUs. You think it needs more electricians. Why?" | Hot Take clips |+| **The Specific Number** | "What's the actual number?" | "What did that actually cost? Not the round number — the real one." | Business/Strategy clips with ugly numbers |+| **The Failure Question** | "What's the biggest mistake you made?" | "What's the decision you'd reverse if you could?" | Emotional, shareable clips |+| **The Insider Knowledge** | "What does everyone get wrong about [X]?" | "What does everyone get wrong about raising a seed round?" | Market/Insight clips |+| **The Future Bet** | "If you had to bet on one thing..." | "If you had to bet your company on one trend for the next 5 years..." | Vision/Prediction clips |+| **The Tactical Question** | "Walk me through exactly how..." | "Walk me through exactly how you closed your first enterprise deal" | Actionable wisdom clips |+| **The Uncomfortable Truth** | "What's the thing nobody in your industry wants to admit?" | "What's the thing nobody in [space] wants to say out loud?" | Hot Take clips with tension |++### Step 4: Plan the Moments++Map questions to ideal moments:++| Time | Question | Target Moment | Potential Title | Content Type |+|------|----------|--------------|-----------------|-------------|+| 5 min | Origin question | How they started | "[Name]: The Bet Nobody Understood" | Guest Story |+| 15 min | Specific number | The real cost | "The $X.XM Cost Nobody Budgets For" | Business |+| 25 min | Contrarian probe | Industry hot take | "[Bold claim stated directly]" | Hot Take |+| 35 min | Failure question | The pivot moment | "The Mistake That Almost Killed [Company]" | Guest Story |+| 45 min | Future bet | Bold prediction | "[Specific prediction about industry]" | Market |++### Step 5: Reference Check++Compare this plan against inspiration channels:+- Would **Huberman** ask this? (protocol/depth angle)+- Would **Cleo Abram** frame it this way? (optimistic/visual angle)+- Would **DOAC** use this hook? (emotional/5-second-rule angle)++Adapt the best patterns from each.++### Step 6: Pre-Title Draft++For each planned moment, draft 2-3 title options BEFORE recording. This gives the host a "target" — they know which answers will become shorts.++---++## Output Format++```markdown+# Episode Plan: [Guest Name] — [Company]++**Episode:** [Number]+**Topic:** [Main topic]+**Recording date:** [Date if known]++---++## Guest Profile+- **Name:** [Full name]+- **Role:** [Title at Company]+- **Background:** [2-3 sentences — what they've built, why they're interesting]+- **Unique angle:** [The one thing about this guest that's different from past episodes]++---++## Story Arc++### Act 1: Origin (0:00 — ~15:00)+**Goal:** [What the audience should feel/know after this section]+- Opening hook: [The surprising thing to lead with]+- Key question: [The question that unlocks the origin story]+- Target moment: [The clip you want from this section]++### Act 2: Insight (~15:00 — ~40:00)+**Goal:** [The core insight or knowledge transfer]+- Key questions: [2-3 questions for this section]+- Target moments: [2-3 clips you want]+- The contrarian angle: [Where to push back or probe deeper]++### Act 3: Future (~40:00 — ~55:00)+**Goal:** [The vision, advice, or bold prediction]+- Key questions: [2-3 questions]+- Target moments: [2-3 clips]+- The closer: [How to end on a high note]++---++## Question Sheet (Print This)++| # | Question | Why | Target Clip |+|---|----------|-----|-------------|+| 1 | [Question] | [Produces what] | [Title angle] |+| 2 | [Question] | [Produces what] | [Title angle] |+| ... | ... | ... | ... |++**Follow-up probes (use when answers are too general):**+- "Can you give me a specific example?"+- "What's the actual number?"+- "What happened next?"+- "Why do you think most people get that wrong?"+- "What would you tell someone starting that today?"++---++## Moment Map (Target Shorts)++| # | Target Title | Content Type | Comes From | Question # |+|---|-------------|-------------|-----------|-----------|+| 1 | [Draft title] | [Type] | Act [X] | Q[X] |+| 2 | [Draft title] | [Type] | Act [X] | Q[X] |+| ... | ... | ... | ... | ... |++---++## Reference Notes+- **From [Inspiration Channel 1]:** [Technique to borrow for this episode]+- **From [Inspiration Channel 2]:** [Technique to borrow]+- **Avoid:** [What NOT to do based on past episodes]++---++## Pre-Recording Checklist+- [ ] Guest briefed on format (length, style, topics)+- [ ] Questions printed / on screen+- [ ] Audio check done+- [ ] Recording software ready+- [ ] Moment map visible (know what clips you're aiming for)+```++---++## Quality Gates++Before delivering the plan:+- [ ] Every question has a clear target moment+- [ ] Moment map covers all 5 content types+- [ ] Story arc has clear acts with rising tension+- [ ] Questions avoid generic "tell me about..." (specific and sharp)+- [ ] At least 2 questions designed to produce ugly numbers+- [ ] At least 1 question designed to produce a contrarian hot take+- [ ] No overlap with topics from previous episodes (check database)+- [ ] Reference channels consulted for format ideasdiff --git a/.claude/commands/produce-shorts.md b/.claude/commands/produce-shorts.mdnew file mode 100644index 0000000..2f2d80e--- /dev/null+++ b/.claude/commands/produce-shorts.md@@ -0,0 +1,265 @@+# /produce-shorts — Full Production Pipeline++> You are the executive producer for this podcast. You run the ENTIRE production pipeline from raw episode file to publish-ready shorts with complete content packages. One command, zero handoffs.++---++## Trigger++User says "produce episode", provides an mp4 + transcript, or wants the full end-to-end pipeline.++---++## Inputs++| Field | Required | How to Get |+|-------|----------|-----------|+| Episode video (.mp4) | Yes | User provides path or it's in `.podcli/working/uploads/` |+| Transcript | Yes | User provides file/text, or auto-transcribe with Whisper |+| Episode number | Yes | User provides or auto-detect |+| Guest name | Preferred | Auto-detect from transcript |+| Company/Org | Preferred | Auto-detect from transcript |+| Caption style | Optional | Default: branded (from presets or user) |+| Crop strategy | Optional | Default: face |++---++## The Full Pipeline (3 Phases, 10 Steps)++### PHASE 1: VIDEO PRODUCTION (podcli engine)++#### Step 1 — Load Video+- Confirm the video file exists and is accessible+- If using the Web UI, call `POST /api/select-file` or check `get_ui_state`+- Note the file path for clip generation++#### Step 2 — Transcribe (if no transcript provided)+- Use the `transcribe_podcast` MCP tool or `POST /api/transcribe`+- Model: base (or user's preference)+- Wait for completion — this produces word-level timestamps + speaker labels+- Cache the result for reuse++#### Step 3 — If transcript is provided as text/file+- Parse it (supports Speaker (MM:SS) format, SRT, VTT, or JSON)+- Use `POST /api/parse-transcript` or the MCP tool+- Ensure word-level timestamps are generated++#### Step 4 — Analyze & Suggest Clips+- Read the full transcript+- Identify the 8-15 best moments based on:+ - Hook strength (first 3 seconds grab attention?)+ - Standalone value (makes sense without context?)+ - Energy/quotability (memorable phrasing?)+ - Audience relevance+- Use the `suggest_clips` MCP tool to submit suggestions+- Each suggestion needs: title, start_second, end_second, reasoning++#### Step 5 — Render Clips+- Use `batch_create_clips` with `export_selected: true`+- Settings: caption style from presets or user, crop strategy, logo if registered+- Wait for all clips to finish rendering+- Note output file paths and durations++**PHASE 1 OUTPUT:** Rendered .mp4 clips in `.podcli/output/`++---++### PHASE 2: CONTENT GENERATION (PodStack)++#### Step 6 — Process Transcript for Content+*Runs `/process-transcript` logic*++Using the same transcript from Phase 1:+1. Score each extracted moment (Standalone + Hook + Relevance + Quotability, 1-5 each)+2. Classify each by content type (Guest Story / Technical Insight / Market / Business / Hot Take)+3. Check for duplicates against `03-episodes-database.md`+4. Extract SEO keywords from the full transcript++#### Step 7 — Generate Titles+*Runs `/generate-titles` logic per clip*++For each rendered clip:+1. Extract the anchor — the single most non-obvious thing+2. Generate 8 title options following the show's title spec+3. Run the 6-point verification checklist+4. Flag top 2 picks+5. Narrow to 2-3 best per clip++#### Step 8 — Generate Descriptions + Thumbnails+*Runs `/generate-descriptions` and `/plan-thumbnails` logic*++For each clip:+- Shorts description: hook + attribution + link placeholder + hashtags+- Thumbnail text: podcast (16:9) lowercase + shorts (9:16) ALL CAPS++For the full episode:+- Long-form description with timestamps, guest links, bullet points+- Podcast thumbnail brief++#### Step 9 — Quality Review+*Runs `/review-content` logic*++4-pass review on ALL generated content:+1. Banned word scan (from `02-voice-and-tone.md`)+2. Voice & tone check+3. Title-specific review (length, keyword position, shapes)+4. Package completeness++Fix all blocking issues before output.++**PHASE 2 OUTPUT:** Complete content package++---++### PHASE 3: DELIVERY++#### Step 10 — Assemble & Save++Compile everything into the final deliverable and save to `episodes/`.++---++## Output Format++```markdown+# Episode [X]: [Guest] — [Company]+## Full Production Package++**Produced:** [Date]+**Video:** [filename]+**Transcript:** [source — Whisper/imported]+**Clips rendered:** [X]+**Keywords:** [comma-separated]++---++## Episode Summary+[2-3 sentences]++---++## Long-Form Episode Metadata++**Title Options:**+1. [Option 1]+2. [Option 2]+3. [Option 3]++**Description (ready to paste):**+[Full long-form description with timestamps, links, hashtags]++**Podcast Thumbnail:**+- Text: "[line 1] / [line 2]"++**Tags:** [comma-separated, under 500 chars]++---++## Shorts Package++### Short 1: [Title]++**File:** [output filename]+**Timestamp:** [XX:XX — XX:XX]+**Duration:** [X]s+**Category:** [Type]+**Score:** [X/20]++> "[Key quote]"++**Title options:**+1. [Best] ← PICK+2. [Alt]+3. [Alt]++**Thumbnail:**+- Podcast: "[line 1] / [line 2]"+- Shorts: "[LINE 1] / [LINE 2]"++**Description (ready to paste):**+[Complete shorts description with hashtags]++---++### Short 2: [Title]+...++---++## Posting Schedule++| Order | Short | Why This Order |+|-------|-------|---------------|+| 1 | [Title] | [Strongest hook — lead with this] |+| 2 | [Title] | [Different topic — variety] |+| ... | ... | ... |++---++## Publish Checklist++### Pre-Upload+- [ ] File names use keywords+- [ ] Titles under 60 chars+- [ ] Descriptions have hooks + hashtags+- [ ] Thumbnails briefed to designer+- [ ] End screen set to ONE specific video+- [ ] Playlist link hack set up++### At Publish+- [ ] Pin comment written+- [ ] Community tab post scheduled (+15 min)+- [ ] ManyChat keyword automation set++### First 24 Hours+- [ ] Reply to every comment+- [ ] Instagram Stories (3-part sequence)+- [ ] Update link in bio++---++## Quality Review+- **Blocking issues:** 0 (all resolved)+- **Status:** READY TO PUBLISH+```++---++## Post-Pipeline Actions++1. **Update episode database** — add to `.podcli/knowledge/03-episodes-database.md`+2. **Save package** — write to `episodes/ep[XX]-[guest]-production-package.md`+3. **Update clip history** — already tracked by podcli engine++---++## How to Use++### Fully automatic (one command)+```+/produce-shorts+```+Then provide the video path and transcript. Everything else is automatic.++### With specific inputs+```+User: /produce-shorts+ Video: /path/to/episode.mp4+ Transcript: /path/to/transcript.txt+ Episode: 7+ Guest: John Smith, Acme Corp+```++### What happens behind the scenes+1. Video gets loaded into podcli+2. Transcript gets parsed (or Whisper runs)+3. Best moments identified and scored+4. Clips rendered with captions and smart crop+5. Titles generated (8 per clip, verified)+6. Descriptions written (ready to paste)+7. Thumbnails planned (both formats)+8. Everything reviewed against brand voice+9. Package assembled and saved+10. Publish checklist included++**Total output: rendered .mp4 shorts + complete content package + publish checklist**diff --git a/.env.example b/.env.exampleindex a645db3..bb05286 100644--- a/.env.example+++ b/.env.example@@ -16,6 +16,17 @@ PYTHON_PATH=# Working directory (defaults to .podcli/ in project root)PODCLI_HOME=+# HuggingFace token for speaker diarization (pyannote)+# 1. Accept terms: https://huggingface.co/pyannote/speaker-diarization-3.1+# 2. Create token (Read permission): https://huggingface.co/settings/tokens+HF_TOKEN=++# Output quality: low, medium, high, max+# low=fast/small, high=great quality (default), max=near-lossless+PODCLI_QUALITY=high++PORT=3847 # Web UI port+# LoggingLOG_LEVEL=infoDEBUG=falsediff --git a/CLAUDE.md b/CLAUDE.mdindex 8256eb5..33c5c5a 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -15,6 +15,7 @@ Both share the same knowledge base at `.podcli/knowledge/`.| Command | Role | What It Does ||---------|------|-------------|+| `/plan-episode` | Episode Architect | Pre-recording: designs questions, story arc, and target moments backwards from ideal output || `/process-transcript` | Content Analyst | Ingests transcript → extracts 8-15 moments → scores → categorizes || `/generate-titles` | Title Writer | Generates 8 title options with full verification checklist || `/generate-descriptions` | Copywriter | Creates descriptions + hashtags + SEO keywords |@@ -43,9 +44,10 @@ Both share the same knowledge base at `.podcli/knowledge/`.## The Full Pipeline```-/process-transcript → /generate-titles → /generate-descriptions → /plan-thumbnails → /review-content → /publish-checklist- ↑ ↓- Raw transcript Published content+/plan-episode → Record → /produce-shorts → Published content+ ↑ ↓+ Guest info /process-transcript → /generate-titles → /generate-descriptions+ → /plan-thumbnails → /review-content → /publish-checklist```Or run everything at once: `/prep-episode`diff --git a/README.md b/README.mdindex 79df5c9..83fd021 100644--- a/README.md+++ b/README.md@@ -284,11 +284,21 @@ Run `./setup.sh --mcp` to get the exact config with your paths filled in.|------|-------------|| `transcribe_podcast` | Transcribe audio/video with Whisper + speaker detection || `suggest_clips` | Submit clip suggestions (includes duplicate check) |-| `create_clip` | Render a single short-form clip |+| `create_clip` | Render a single short-form clip as a vertical short || `batch_create_clips` | Render multiple clips in one batch |-| `knowledge_base` | Read/write podcast context files |+| `knowledge_base` | Read/manage podcast context files (hosts, style, audience, etc.) || `manage_assets` | Register/list reusable assets (logos, videos) || `clip_history` | View previously created clips, check for duplicates |+| `get_ui_state` | Read current session state and get workflow next-step guidance |+| `modify_clip` | Adjust a suggested clip's timing, title, or caption style (or delete it) |+| `toggle_clip` | Select or deselect a suggested clip for export |+| `update_settings` | Update rendering settings (caption style, crop strategy, logo, outro) |+| `list_outputs` | List all rendered clip files in the output directory |+| `manage_presets` | Save, load, list, or delete rendering presets |+| `analyze_energy` | Analyze audio energy levels to find high-energy moments |+| `set_video` | Set the working video file without transcribing |+| `import_transcript` | Import an external transcript with word-level timestamps (skips Whisper) |+| `parse_transcript` | Parse raw speaker-labeled plain text into word-level timestamps |---diff --git a/backend/cli.py b/backend/cli.pyindex 0f7893f..66848dc 100644--- a/backend/cli.py+++ b/backend/cli.py@@ -16,10 +16,81 @@ import osimport sysimport time+# Suppress macOS ObjC duplicate class warnings from OpenCV's bundled dylibs+os.environ["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"+if sys.platform == "darwin":+ os.environ.setdefault("DYLD_LIBRARY_PATH", "")+# Add parent dir to pathsys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))+def _ensure_ssl_certs():+ """Fix SSL certificate issues automatically (macOS + corporate proxies)."""+ import ssl++ # Quick test — if HTTPS works, we're fine+ try:+ import urllib.request+ urllib.request.urlopen("https://huggingface.co", timeout=5)+ return+ except Exception:+ pass++ print(" ⚠ SSL issue detected — fixing automatically...")++ # Method 1: Set certifi certs (works for most cases including corporate proxies)+ try:+ import certifi+ os.environ["SSL_CERT_FILE"] = certifi.where()+ os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()+ # Monkey-patch ssl to use certifi for this process+ ssl._create_default_https_context = lambda: ssl.create_default_context(cafile=certifi.where())+ print(" ✓ SSL configured via certifi")+ return+ except ImportError:+ pass++ # Method 2: pip install certifi into venv, then use it+ venv_pip = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "venv", "bin", "pip")+ if os.path.exists(venv_pip):+ import subprocess as sp+ try:+ sp.run([venv_pip, "install", "-q", "certifi"], capture_output=True, timeout=60)+ import importlib+ certifi = importlib.import_module("certifi")+ os.environ["SSL_CERT_FILE"] = certifi.where()+ os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()+ ssl._create_default_https_context = lambda: ssl.create_default_context(cafile=certifi.where())+ print(" ✓ SSL configured (installed certifi)")+ return+ except Exception:+ pass++ # Method 3: macOS Install Certificates command+ if sys.platform == "darwin":+ import subprocess as sp+ import glob+ ver = f"{sys.version_info.major}.{sys.version_info.minor}"+ cert_scripts = glob.glob(f"/Applications/Python {ver}*/Install Certificates.command") + \+ glob.glob(f"/Applications/Python {ver}/Install Certificates.command")+ if cert_scripts:+ try:+ sp.run(["bash", cert_scripts[0]], capture_output=True, timeout=30)+ # Force reload ssl context+ ssl._create_default_https_context = ssl._create_unverified_context+ print(" ✓ SSL certificates installed (restart may be needed)")+ return+ except Exception:+ pass++ # Method 4: Last resort — disable SSL verification for this session+ # This is safe because we're only downloading Whisper models from known URLs+ ssl._create_default_https_context = ssl._create_unverified_context+ os.environ["PYTHONHTTPSVERIFY"] = "0"+ print(" ⚠ SSL verification disabled for this session (model downloads only)")++def cmd_process(args):"""Full auto pipeline: transcribe → suggest → export."""from services.clip_generator import generate_clip@@ -28,7 +99,7 @@ def cmd_process(args):from services.encoder import get_encoder_infofrom presets import get_preset, DEFAULT_PRESET- video_path = args.video+ video_path = _clean_path(args.video)if not os.path.exists(video_path):print(f"Error: Video not found: {video_path}", file=sys.stderr)sys.exit(1)@@ -52,11 +123,23 @@ def cmd_process(args):if args.top:config["top_clips"] = args.topif args.logo:- config["logo_path"] = args.logo+ from services.asset_store import resolve as resolve_asset+ resolved = resolve_asset(args.logo)+ if resolved:+ config["logo_path"] = resolved+ else:+ print(f" Warning: Logo '{args.logo}' not found (checked assets and filesystem)", file=sys.stderr)+ config["logo_path"] = args.logo # pass through anywayif args.time_adjust is not None:config["time_adjust"] = args.time_adjustif args.no_energy:config["energy_boost"] = False+ if args.quality:+ config["quality"] = args.quality++ # Set quality env var before importing video_processor+ quality = config.get("quality", os.environ.get("PODCLI_QUALITY", "high"))+ os.environ["PODCLI_QUALITY"] = quality# Output directoryoutput_dir = args.output or os.path.join(os.path.dirname(video_path), "clips")@@ -65,6 +148,7 @@ def cmd_process(args):enc_info = get_encoder_info()print(f"\n podcli — processing")print(f" Encoder: {enc_info['best']} ({enc_info['system']})")+ print(f" Quality: {quality}")print(f" Video: {os.path.basename(video_path)}")print()@@ -74,7 +158,7 @@ def cmd_process(args):segments = []if args.transcript:- print(" [1/4] Loading transcript...")+ print(" [1/5] Loading transcript...")with open(args.transcript, "r") as f:raw_text = f.read()@@ -99,7 +183,10 @@ def cmd_process(args):segments = parsed["segments"]print(f" Parsed: {len(segments)} segments, {len(words)} words")else:- print(" [1/4] Transcribing with Whisper...")+ print(" [1/5] Transcribing with Whisper...")+ _ensure_ssl_certs()+ import warnings+ warnings.filterwarnings("ignore", message="FP16 is not supported on CPU")from services.transcription import transcribe_fileresult = transcribe_file(file_path=video_path,@@ -110,6 +197,15 @@ def cmd_process(args):segments = result["segments"]print(f" Done: {len(segments)} segments, {len(words)} words")+ # Check speaker data availability (needed for smart cropping)+ speakers_in_words = set(w.get("speaker") for w in words if w.get("speaker"))+ if len(speakers_in_words) > 1:+ print(f" Speakers detected: {len(speakers_in_words)} (crop will follow active speaker)")+ elif len(speakers_in_words) == 1:+ print(f" Single speaker detected (static face crop)")+ else:+ print(f" No speaker data (center crop fallback)")+if not segments:print(" Error: No transcript segments found.", file=sys.stderr)sys.exit(1)@@ -117,7 +213,7 @@ def cmd_process(args):# ── Step 2: Analyze audio energy ──energy_scores = Noneif config.get("energy_boost", True):- print(" [2/4] Analyzing audio energy...")+ print(" [2/5] Analyzing audio energy...")try:profile = get_energy_profile(video_path, segments)energy_scores = profile["segment_scores"]@@ -125,30 +221,60 @@ def cmd_process(args):except Exception as e:print(f" Skipped (error: {e})")else:- print(" [2/4] Audio analysis skipped (--no-energy)")+ print(" [2/5] Audio analysis skipped (--no-energy)")# ── Step 3: Score and select clips ──- print(" [3/4] Scoring clips...")- clips = _suggest_clips(- segments=segments,- energy_scores=energy_scores,- top_n=config.get("top_clips", 5),- min_dur=config.get("min_clip_duration", 20),- max_dur=config.get("max_clip_duration", 90),- )+ top_n = config.get("top_clips", 5)+ clips = None++ # Try Claude first (uses PodStack knowledge base for intelligent selection)+ from services.claude_suggest import suggest_with_claude, _find_claude++ claude_path = _find_claude()+ if claude_path:+ print(f" [3/5] Selecting moments with Claude (PodStack)...")+ clips = suggest_with_claude(+ segments=segments,+ top_n=top_n,+ progress_callback=lambda pct, msg: print(f" {msg}") if msg else None,+ )+ if clips:+ print(f" ✓ Claude selected {len(clips)} clips")+ else:+ print(f" ⚠ Claude unavailable, falling back to heuristics")+ else:+ print(f" [3/5] Scoring clips (heuristic mode)...")+ print(f" ℹ Install Claude Code for smarter selection:")+ print(f" https://docs.anthropic.com/en/docs/claude-code")++ # Fallback to heuristic algorithm+ if not clips:+ clips = _suggest_clips(+ segments=segments,+ energy_scores=energy_scores,+ top_n=top_n,+ min_dur=config.get("min_clip_duration", 20),+ max_dur=config.get("max_clip_duration", 90),+ )if not clips:print(" No clips found. Try a longer transcript or lower --min-duration.", file=sys.stderr)sys.exit(1)- print(f" Selected {len(clips)} clips:")+ print(f"\n Selected {len(clips)} clips:")for i, c in enumerate(clips):m_s = int(c["start_second"]) // 60s_s = int(c["start_second"]) % 60- print(f" {i+1}. [{m_s}:{s_s:02d} → +{c['duration']}s] {c['title'][:55]}")+ ctype = c.get("content_type", "")+ score_val = c.get("score", 0)+ score_str = f"({score_val}/20)" if isinstance(score_val, int) and score_val <= 20 else f"({score_val:.0f}pts)"+ type_tag = f" [{ctype}]" if ctype and ctype != "unknown" else ""+ print(f" {i+1}. [{m_s}:{s_s:02d} → +{c['duration']}s] {score_str}{type_tag} {c['title'][:50]}")+ if c.get("why"):+ print(f" {c['why'][:70]}")# ── Step 4: Export ──- print(f"\n [4/4] Exporting {len(clips)} clips to {output_dir}/")+ print(f"\n [4/5] Exporting {len(clips)} clips to {output_dir}/")results = []t0 = time.time()@@ -175,7 +301,106 @@ def cmd_process(args):elapsed = time.time() - t0success = sum(1 for r in results if "output_path" in r)print(f"\n Done! {success}/{len(clips)} clips exported in {elapsed:.1f}s")- print(f" Output: {output_dir}/\n")+ print(f" Output: {output_dir}/")++ # ── Step 5: Content generation via Claude (PodStack /produce-shorts) ──+ from services.claude_suggest import _find_claude+ claude_path = _find_claude()++ accent = "\033[38;2;212;135;74m"+ gray = "\033[38;5;245m"+ green = "\033[38;2;74;222;128m"+ bold = "\033[1m"+ reset = "\033[0m"++ if claude_path:+ print(f"\n {bold}[5/5] Generating content package (PodStack)...{reset}")++ # Build transcript text for Claude+ transcript_lines = []+ for seg in segments:+ sp = seg.get("speaker", "")+ sp_label = f"[{sp}] " if sp else ""+ start = seg.get("start", 0)+ mins = int(start) // 60+ secs = int(start) % 60+ text = seg.get("text", "").strip()+ if text:+ transcript_lines.append(f"({mins}:{secs:02d}) {sp_label}{text}")++ # Build clip summary for context+ clip_summary = "\n".join(+ f"- Short {i+1}: \"{c['title']}\" ({c['start_second']}s-{c['end_second']}s) [{c.get('content_type', '')}]"+ for i, c in enumerate(clips)+ )++ prompt = f"""Run /produce-shorts for this episode. Clips are already rendered — now generate the content package.++Video: {os.path.basename(video_path)}+Clips rendered: {success}+Output: {output_dir}/++Selected clips:+{clip_summary}++Transcript:+{chr(10).join(transcript_lines[:500])}++Generate:+1. 8 title options per clip (using knowledge base title formulas)+2. Ready-to-paste descriptions with hashtags for each clip+3. Thumbnail text briefs (podcast 16:9 + shorts 9:16) for each clip+4. Posting schedule recommendation+5. Publish checklist++Save the content package to episodes/ directory."""++ import tempfile, subprocess as sp+ project_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")++ with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False, dir=project_dir) as f:+ f.write(prompt)+ prompt_file = f.name++ try:+ print(f" {gray}Claude is generating titles, descriptions, thumbnails...{reset}")+ result = sp.run(+ f'cat "{prompt_file}" | "{claude_path}" --print -p -',+ capture_output=True, text=True, cwd=project_dir,+ timeout=300, shell=True,+ )+ if result.returncode == 0 and result.stdout.strip():+ # Save content package+ import re+ guest = "episode"+ for seg in segments[:10]:+ text = seg.get("text", "")+ if text and len(text) > 20:+ guest = re.sub(r'[^a-zA-Z0-9]', '-', text[:30]).strip('-').lower()+ break++ episodes_dir = os.path.join(project_dir, "episodes")+ os.makedirs(episodes_dir, exist_ok=True)+ pkg_path = os.path.join(episodes_dir, f"content-package-{guest[:20]}.md")+ with open(pkg_path, "w") as f:+ f.write(result.stdout)++ print(f" {green}✓{reset} Content package saved to {accent}episodes/{os.path.basename(pkg_path)}{reset}")+ else:+ print(f" {gray}⚠ Claude returned no content. Run {accent}/produce-shorts{reset} {gray}in Claude Code manually.{reset}")+ except Exception as e:+ print(f" {gray}⚠ Content generation skipped: {e}{reset}")+ print(f" {gray}Run {accent}/produce-shorts{reset} {gray}in Claude Code for titles + descriptions.{reset}")+ finally:+ try:+ os.unlink(prompt_file)+ except Exception:+ pass+ else:+ print(f"\n {gray}Clips rendered. For titles, descriptions & thumbnails:{reset}")+ print(f" {gray}Open Claude Code and run {accent}/produce-shorts{reset}")++ print()def _suggest_clips(@@ -186,26 +411,107 @@ def _suggest_clips(max_dur: float = 90,) -> list:"""- Score and rank transcript segments into clip suggestions.+ Score and rank transcript segments into viral clip suggestions.- Combines text heuristics + audio energy for scoring.+ Scoring dimensions:+ 1. Hook strength — does it open with something that grabs attention?+ 2. Standalone value — does it make sense without context?+ 3. Completeness — does it start and end on sentence boundaries?+ 4. Content signals — keywords, questions, stories, bold claims+ 5. Speaker dynamics — speaker changes make clips more engaging+ 6. Audio energy — louder/more passionate = more engaging+ 7. Density — information per second (too sparse = boring)"""- KEYWORDS = [- "secret", "mistake", "important", "never", "always", "best",- "how to", "why", "story", "amazing", "changed", "money",- "learn", "truth", "actually", "problem", "solution", "believe",- "crazy", "number one", "biggest", "first thing", "listen",- "here's the thing", "let me tell you", "the key", "game changer",- "nobody talks about", "most people", "don't realize",++ # ── Signal keywords by category (weighted differently) ──++ # Strong hooks — things people say right before a great moment+ HOOK_PHRASES = [+ "here's the thing", "let me tell you", "the truth is",+ "what people don't realize", "nobody talks about",+ "the biggest mistake", "the real reason", "here's what happened",+ "i'll never forget", "that's when i realized", "the moment i knew",+ "so here's the secret", "this is the part where", "what i learned",+ "the one thing", "if i'm being honest", "the hard truth",]+ # Insight signals — content that teaches or reveals+ INSIGHT_WORDS = [+ "because", "actually", "specifically", "the problem is",+ "most people", "counterintuitive", "the data shows",+ "what we found", "turns out", "the reason",+ "in practice", "the trick", "fundamentally",+ ]++ # Story signals — narrative elements that pull people in+ STORY_SIGNALS = [+ "when i", "when we", "i remember", "years ago", "at that point",+ "we decided", "we were", "i was", "the first time",+ "that morning", "one day", "back then", "suddenly",+ ]++ # Numbers/specifics — concrete details increase credibility+ NUMBER_PATTERN = None+ try:+ import re+ NUMBER_PATTERN = re.compile(r'\$[\d,.]+[mkb]?|\d+%|\d+\.\d+[x×]|\d{2,}', re.IGNORECASE)+ except Exception:+ pass++ # Sentence boundary detection+ def _is_sentence_start(text):+ """Check if text starts at a sentence boundary."""+ t = text.strip()+ if not t:+ return False+ # Starts with capital letter after nothing or after sentence-ending punct+ return t[0].isupper()++ def _is_sentence_end(text):+ """Check if text ends at a sentence boundary."""+ t = text.strip()+ if not t:+ return False+ return t[-1] in '.!?'++ def _find_sentence_boundary_start(segs, idx, max_lookback=3):+ """Walk backwards to find the nearest sentence start."""+ for offset in range(min(max_lookback, idx)):+ check_idx = idx - offset+ if check_idx <= 0:+ return 0+ prev_text = segs[check_idx - 1].get("text", "").strip()+ curr_text = segs[check_idx].get("text", "").strip()+ if prev_text and prev_text[-1] in '.!?' and curr_text and curr_text[0].isupper():+ return check_idx+ return idx++ def _find_sentence_boundary_end(segs, idx, max_lookahead=3):+ """Walk forward to find the nearest sentence end."""+ for offset in range(min(max_lookahead, len(segs) - idx)):+ check_idx = idx + offset+ check_text = segs[check_idx].get("text", "").strip()+ if check_text and check_text[-1] in '.!?':+ return check_idx+ return idx++ # ── Build clips with smart windowing ──+clips = []- win_sizes = [6, 8, 10, 12] # try multiple window sizes+ # Multiple window sizes to catch different moment lengths+ win_sizes = [5, 7, 9, 11, 14]for win_size in win_sizes:- step = max(1, int(win_size * 0.6))+ step = max(1, int(win_size * 0.5))for i in range(0, len(segments) - win_size, step):- win = segments[i : i + win_size]+ # Snap window start and end to sentence boundaries+ snap_start = _find_sentence_boundary_start(segments, i)+ snap_end = _find_sentence_boundary_end(segments, i + win_size - 1)++ win = segments[snap_start : snap_end + 1]+ if len(win) < 3:+ continue+text = " ".join(s.get("text", "") for s in win)start = win[0].get("start", 0)end = win[-1].get("end", 0)@@ -214,44 +520,134 @@ def _suggest_clips(if dur < min_dur or dur > max_dur:continue- # Text heuristics- score = 0text_lower = text.lower()- if "?" in text:+ score = 0+ reasons = []++ # ── 1. Hook strength (0-8 pts) ──+ # Check if clip opens with a strong hook+ first_30_chars = " ".join(s.get("text", "") for s in win[:3]).lower()+ for phrase in HOOK_PHRASES:+ if phrase in first_30_chars:+ score += 5+ reasons.append("strong_hook")+ break++ # Question as opener+ first_seg_text = win[0].get("text", "")+ if "?" in first_seg_text:score += 3- if "!" in text:+ reasons.append("question_hook")++ # ── 2. Sentence boundary quality (0-4 pts) ──+ starts_clean = _is_sentence_start(win[0].get("text", ""))+ ends_clean = _is_sentence_end(win[-1].get("text", ""))+ if starts_clean:score += 2- if len(text) > 200:- score += 1+ if ends_clean:+ score += 2+ reasons.append("clean_ending")++ # ── 3. Content signals (0-10 pts) ──+ insight_count = sum(1 for kw in INSIGHT_WORDS if kw in text_lower)+ story_count = sum(1 for kw in STORY_SIGNALS if kw in text_lower)++ if insight_count >= 2:+ score += min(insight_count * 1.5, 5)+ reasons.append("insightful")+ if story_count >= 2:+ score += min(story_count * 1.5, 5)+ reasons.append("narrative")- for kw in KEYWORDS:- if kw in text_lower:- score += 2+ # Exclamation = passion/emphasis+ exclaim_count = text.count("!")+ if exclaim_count >= 1:+ score += min(exclaim_count, 3)- # Sentence-start bonus (if window starts at a natural boundary)- first_text = win[0].get("text", "").strip()- if first_text and first_text[0].isupper():- score += 1+ # ── 4. Specificity — numbers, dollars, percentages (0-4 pts) ──+ if NUMBER_PATTERN:+ numbers = NUMBER_PATTERN.findall(text)+ if numbers:+ score += min(len(numbers) * 1.5, 4)+ reasons.append("specific_numbers")- # Audio energy boost+ # ── 5. Speaker dynamics (0-5 pts) ──+ speakers_in_window = set()+ speaker_changes = 0+ prev_speaker = None+ for s in win:+ sp = s.get("speaker")+ if sp:+ speakers_in_window.add(sp)+ if prev_speaker and sp != prev_speaker:+ speaker_changes += 1+ prev_speaker = sp++ if len(speakers_in_window) > 1:+ # Multi-speaker clips are more dynamic+ score += 2+ if speaker_changes >= 2:+ score += min(speaker_changes, 3)+ reasons.append("dialogue")++ # ── 6. Audio energy (0-6 pts) ──if energy_scores:- seg_energies = energy_scores[i : i + win_size]+ seg_energies = energy_scores[snap_start : snap_end + 1]if seg_energies:- avg_energy = sum(seg_energies) / len(seg_energies)- max_energy = max(seg_energies)- score += avg_energy * 0.5 + max_energy * 0.3+ avg_e = sum(seg_energies) / len(seg_energies)+ max_e = max(seg_energies)+ # Energy variance = dynamic range (builds tension)+ variance = sum((e - avg_e) ** 2 for e in seg_energies) / len(seg_energies)+ energy_score = avg_e * 0.3 + max_e * 0.3 + (variance ** 0.5) * 0.4+ score += min(energy_score, 6)+ if max_e > 7:+ reasons.append("high_energy")++ # ── 7. Density check — penalize sparse/rambling segments ──+ words_per_sec = len(text.split()) / max(dur, 1)+ if words_per_sec < 1.5:+ score *= 0.7 # Too sparse, probably silence or filler+ elif words_per_sec > 2.5:+ score *= 1.1 # Dense = packed with info++ # ── 8. Anti-patterns — penalize weak clips ──+ # Clips that reference other parts of the conversation+ if any(ref in text_lower for ref in [+ "as i said", "like i mentioned", "going back to",+ "earlier when", "as we discussed", "you said earlier",+ ]):+ score *= 0.5 # Needs context = bad short- if score >= 3:+ # Mid-sentence start+ if not starts_clean:+ score *= 0.8++ # ── Build title from the hook ──+ # Find the first strong sentence as the title+ title = ""+ for s in win[:4]:+ t = s.get("text", "").strip()+ if t and len(t) > 15:+ title = t+ break+ if not title:+ title = text[:60].strip()+ if len(title) > 55:+ # Cut at word boundary+ title = title[:55].rsplit(" ", 1)[0] + "..."++ if score >= 5: # Higher threshold = better clipsclips.append({- "title": text[:55].strip() + "...",- "start_second": round(start),- "end_second": round(end),+ "title": title,+ "start_second": round(start, 1),+ "end_second": round(end, 1),"duration": round(dur),"score": round(score, 2),- "preview": text[:100].strip(),+ "reasons": reasons,+ "preview": text[:120].strip(),})- # Deduplicate overlapping clips (keep highest score)+ # ── Deduplicate overlapping clips (keep highest score) ──clips.sort(key=lambda c: c["score"], reverse=True)selected = []for clip in clips:@@ -259,10 +655,9 @@ def _suggest_clips(for sel in selected:if (clip["start_second"] < sel["end_second"] andclip["end_second"] > sel["start_second"]):- # More than 50% overlap → skipoverlap_amt = (min(clip["end_second"], sel["end_second"]) -max(clip["start_second"], sel["start_second"]))- if overlap_amt > clip["duration"] * 0.5:+ if overlap_amt > min(clip["duration"], sel["duration"]) * 0.3:overlap = Truebreakif not overlap:@@ -324,6 +719,60 @@ def cmd_presets(args):print(f" Preset '{args.name}' not found")+def cmd_assets(args):+ """Manage named assets (logos, intros, outros)."""+ from services.asset_store import register, unregister, list_assets, resolve++ accent = "\033[38;2;212;135;74m"+ gray = "\033[38;5;245m"+ green = "\033[38;2;74;222;128m"+ bold = "\033[1m"+ reset = "\033[0m"++ if args.assets_action == "list":+ assets = list_assets()+ if not assets:+ print(f"\n No assets registered. Add one:")+ print(f" {accent}podcli assets add{reset} {gray}mylogo /path/to/logo.png{reset}")+ print()+ return+ print(f"\n {bold}Registered assets ({len(assets)}){reset}\n")+ for a in assets:+ exists = os.path.exists(a["path"])+ status = f"{green}✓{reset}" if exists else "\033[38;2;248;113;113m✗ missing\033[0m"+ print(f" {accent}{a['name']}{reset} {gray}({a['type']}){reset} {status}")+ print(f" {gray}{a['path']}{reset}")+ print()+ print(f" {gray}Use in commands:{reset} {accent}--logo mylogo{reset} {gray}or{reset} {accent}--outro myoutro{reset}")+ print()++ elif args.assets_action == "add":+ name = args.name+ file_path = args.path+ asset_type = getattr(args, "type", "auto") or "auto"+ try:+ asset = register(name, file_path, asset_type)+ print(f"\n {green}✓{reset} Registered {accent}{name}{reset} ({asset['type']})")+ print(f" {gray}{asset['path']}{reset}\n")+ except FileNotFoundError as e:+ print(f"\n ✗ {e}\n", file=sys.stderr)+ sys.exit(1)++ elif args.assets_action == "remove":+ if unregister(args.name):+ print(f"\n ✓ Removed '{args.name}'\n")+ else:+ print(f"\n '{args.name}' not found\n")++ elif args.assets_action == "resolve":+ path = resolve(args.name)+ if path:+ print(path)+ else:+ print(f" Not found: {args.name}", file=sys.stderr)+ sys.exit(1)++def cmd_info(args):"""Show system info."""from services.encoder import get_encoder_info@@ -337,11 +786,104 @@ def cmd_info(args):print()+VERSION = "1.0.0"++BANNER = """+\033[38;2;212;135;74m ┌─────────────────────────────────────┐+ │ │+ │ ██████╗ ██████╗ ██████╗ │+ │ ██╔══██╗██╔═══██╗██╔══██╗ │+ │ ██████╔╝██║ ██║██║ ██║ │+ │ ██╔═══╝ ██║ ██║██║ ██║ │+ │ ██║ ╚██████╔╝██████╔╝\033[0m\033[1m CLI\033[0m\033[38;2;212;135;74m │+ │ ╚═╝ ╚═════╝ ╚═════╝ │+ │ │+ └─────────────────────────────────────┘\033[0m"""+++def print_banner():+ """Print startup banner with system info."""+ from services.encoder import get_encoder_info++ print(BANNER)++ try:+ info = get_encoder_info()+ encoder = info["best"]+ if encoder == "libx264":+ encoder_label = "CPU"+ else:+ encoder_label = encoder.replace("h264_", "").upper()+ except Exception:+ encoder_label = "CPU"++ # Count knowledge base files+ kb_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".podcli", "knowledge")+ kb_count = len([f for f in os.listdir(kb_path) if f.endswith(".md")]) if os.path.isdir(kb_path) else 0++ gray = "\033[38;5;245m"+ accent = "\033[38;2;212;135;74m"+ green = "\033[38;2;74;222;128m"+ yellow = "\033[38;2;250;204;21m"+ red = "\033[38;2;248;113;113m"+ dim = "\033[2m"+ bold = "\033[1m"+ reset = "\033[0m"++ # Check HF_TOKEN for speaker diarization+ hf_token = os.environ.get("HF_TOKEN", "")+ if not hf_token:+ env_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".env")+ if os.path.exists(env_path):+ with open(env_path) as f:+ for line in f:+ if line.strip().startswith("HF_TOKEN=") and line.strip().split("=", 1)[1].strip():+ hf_token = line.strip().split("=", 1)[1].strip()+ break++ speakers_ok = bool(hf_token)++ # Check Claude Code+ from services.claude_suggest import _find_claude+ claude_path = _find_claude()++ print(f" {bold}podcli{reset} v{VERSION}")++ # Status — one line+ claude_tag = f"{green}✓{reset}" if claude_path else f"{yellow}✗{reset}"+ speaker_tag = f"{green}✓{reset}" if speakers_ok else f"{yellow}✗{reset}"+ print(f" {gray}Encoder {green}{encoder_label}{reset} {gray}· Claude {claude_tag} {gray}· Speakers {speaker_tag} {gray}· Knowledge {green}{kb_count}{reset}")++ # Assets — one line if any+ try:+ from services.asset_store import list_assets+ assets = list_assets()+ if assets:+ parts = []+ for a in assets:+ if os.path.exists(a["path"]):+ parts.append(f"{green}✓{reset} {a['name']}")+ else:+ parts.append(f"{red}✗{reset} {a['name']}")+ print(f" {gray}Assets{reset} {' '.join(parts)}")+ except Exception:+ pass++ print()++ if not speakers_ok:+ print(f" {yellow}⚠ Speaker detection not set up — run: podcli info{reset}")++ print()++def main():parser = argparse.ArgumentParser(prog="podcli",description="AI-powered podcast clip generator",)+ parser.add_argument("--version", action="version", version=f"podcli {VERSION}")+ parser.add_argument("--no-banner", action="store_true", help=argparse.SUPPRESS)sub = parser.add_subparsers(dest="command")# ── process ──@@ -356,6 +898,7 @@ def main():proc.add_argument("--logo", help="Path to logo image")proc.add_argument("--time-adjust", type=float, help="Timestamp offset in seconds")proc.add_argument("--no-energy", action="store_true", help="Skip audio energy analysis")+ proc.add_argument("--quality", choices=["low", "medium", "high", "max"], help="Output quality (default: high)")# ── presets ──pre = sub.add_parser("presets", help="Manage presets")@@ -377,19 +920,290 @@ def main():pre_del = pre_sub.add_parser("delete", help="Delete a preset")pre_del.add_argument("name")+ # ── assets ──+ ast = sub.add_parser("assets", help="Manage named assets (logos, intros, outros)")+ ast_sub = ast.add_subparsers(dest="assets_action")++ ast_list = ast_sub.add_parser("list", help="List all registered assets")++ ast_add = ast_sub.add_parser("add", help="Register a file as a named asset")+ ast_add.add_argument("name", help="Short name (e.g., 'mylogo', 'outro')")+ ast_add.add_argument("path", help="Path to file")+ ast_add.add_argument("--type", choices=["logo", "video", "image", "audio", "other"], help="Asset type (default: auto-detect)")++ ast_rm = ast_sub.add_parser("remove", help="Remove a named asset")+ ast_rm.add_argument("name")++ ast_resolve = ast_sub.add_parser("resolve", help="Print the path for an asset name")+ ast_resolve.add_argument("name")+# ── info ──sub.add_parser("info", help="Show system info (encoder, etc.)")args = parser.parse_args()if args.command == "process":+ if not getattr(args, "no_banner", False):+ print()cmd_process(args)elif args.command == "presets":cmd_presets(args)+ elif args.command == "assets":+ cmd_assets(args)elif args.command == "info":cmd_info(args)else:- parser.print_help()+ interactive_menu()+++def interactive_menu():+ """Interactive startup — show banner then let user pick what to do."""++ accent = "\033[38;2;212;135;74m"+ gray = "\033[38;5;245m"+ green = "\033[38;2;74;222;128m"+ yellow = "\033[38;2;250;204;21m"+ bold = "\033[1m"+ dim = "\033[2m"+ reset = "\033[0m"++ print_banner()++ print(f" {bold}Quick start:{reset}")+ print(f" {accent}1{reset} Process a video → shorts + content package")+ print(f" {accent}2{reset} Open Web UI")+ print(f" {accent}3{reset} Manage assets")+ print(f" {accent}q{reset} Quit")+ print()++ try:+ choice = input(f" {gray}>{reset} ").strip()+ except (EOFError, KeyboardInterrupt):+ print()+ return++ if choice == "1":+ _interactive_process()+ elif choice == "2":+ print(f"\n {gray}Starting Web UI...{reset}\n")+ import subprocess as sp+ sp.run(["npm", "run", "ui"], cwd=os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))+ elif choice == "3":+ _interactive_assets()+ elif choice in ("q", "Q", ""):+ return+ else:+ print(f"\n {gray}Unknown option.{reset}\n")+++def _clean_path(val):+ """Clean a path that may have shell escapes or quotes from drag-drop."""+ val = val.strip().strip("'\"")+ # macOS Terminal adds backslash escapes when dragging files+ val = val.replace("\\ ", " ")+ val = val.replace("\\(", "(").replace("\\)", ")")+ val = val.replace("\\,", ",")+ val = val.replace("\\'", "'")+ # Also handle generic backslash-space+ if "\\" in val and not os.path.exists(val):+ unescaped = val.replace("\\", "")+ if os.path.exists(unescaped):+ return unescaped+ return val+++def _flush_stdin():+ """Flush any buffered stdin (leftover newlines from previous inputs)."""+ import select+ try:+ while select.select([sys.stdin], [], [], 0.0)[0]:+ sys.stdin.readline()+ except Exception:+ pass+++def _ask(prompt, default=None, validate=None, required=False, is_path=False):+ """Ask a question, retry until valid or Ctrl+C."""+ _flush_stdin()+ while True:+ try:+ val = input(prompt).strip().strip("'\"")+ except (EOFError, KeyboardInterrupt):+ print()+ return default+ if not val:+ if default is not None:+ return default+ if required:+ continue # silently re-prompt+ return val+ if is_path:+ val = _clean_path(val)+ if validate and not validate(val):+ continue+ return val+++def _interactive_process():+ """Interactive video processing wizard."""++ accent = "\033[38;2;212;135;74m"+ gray = "\033[38;5;245m"+ green = "\033[38;2;74;222;128m"+ red = "\033[38;2;248;113;113m"+ bold = "\033[1m"+ dim = "\033[2m"+ reset = "\033[0m"++ print()++ # 1. Video path — keep asking until valid+ def _valid_video(v):+ if os.path.exists(v):+ return True+ print(f" {red}✗ File not found.{reset} Try again or drag the file here.")+ return False++ print(f" {gray}Paste the path or drag your video file into this window:{reset}")+ video = _ask(f"\n {accent}▸ Video:{reset} ", validate=_valid_video, required=True, is_path=True)+ if not video:+ return++ print(f" {green}✓{reset} {os.path.basename(video)}")++ # 2. Transcript — optional+ print()+ transcript = _ask(+ f" {accent}Transcript:{reset} {dim}(drag file or press enter to auto-transcribe){reset}\n {gray}>{reset} ",+ default="",+ is_path=True,+ )+ if transcript and os.path.exists(transcript):+ print(f" {green}✓{reset} {os.path.basename(transcript)}")+ else:+ transcript = None+ print(f" {gray}→ Will auto-transcribe with Whisper{reset}")++ # 3. Caption style+ print(f"\n {accent}Caption style:{reset}")+ print(f" {accent}1{reset} branded {dim}dark pill on active word + logo{reset}")+ print(f" {accent}2{reset} hormozi {dim}bold uppercase, yellow highlight{reset}")+ print(f" {accent}3{reset} karaoke {dim}sentence visible, words light up{reset}")+ print(f" {accent}4{reset} subtle {dim}clean small text at bottom{reset}")+ styles = {"1": "branded", "2": "hormozi", "3": "karaoke", "4": "subtle"}+ style_choice = _ask(f" {gray}>{reset} ", default="1")+ caption_style = styles.get(style_choice, "branded")+ print(f" {green}✓{reset} {caption_style}")++ # 4. Quality+ print(f"\n {accent}Quality:{reset} {dim}1 low · 2 medium · {bold}3 high{reset}{dim} · 4 max{reset}")+ qualities = {"1": "low", "2": "medium", "3": "high", "4": "max"}+ q_choice = _ask(f" {gray}>{reset} ", default="3")+ quality = qualities.get(q_choice, "high")+ print(f" {green}✓{reset} {quality}")++ # 5. Number of clips+ top_input = _ask(f"\n {accent}Number of clips{reset} {dim}(default 5){reset}: ", default="5")+ try:+ top_n = int(top_input)+ except ValueError:+ top_n = 5+ print(f" {green}✓{reset} {top_n} clips")++ # 6. Logo from assets+ logo = None+ try:+ from services.asset_store import list_assets+ logos = [a for a in list_assets() if a["type"] == "logo" and os.path.exists(a["path"])]+ if logos:+ print(f"\n {accent}Logo:{reset}")+ for i, a in enumerate(logos):+ print(f" {accent}{i+1}{reset} {a['name']} {dim}{os.path.basename(a['path'])}{reset}")+ print(f" {accent}0{reset} none")+ logo_choice = _ask(f" {gray}>{reset} ", default="1")+ if logo_choice and logo_choice != "0":+ idx = int(logo_choice) - 1+ if 0 <= idx < len(logos):+ logo = logos[idx]["path"]+ print(f" {green}✓{reset} {logos[idx]['name']}")+ except Exception:+ pass++ # Summary+ print(f"\n {gray}{'─' * 40}{reset}")+ print(f" {bold}Ready to process:{reset}")+ print(f" Video: {os.path.basename(video)}")+ print(f" Style: {caption_style} · Quality: {quality} · Clips: {top_n}")+ if logo:+ print(f" Logo: ✓")+ if transcript:+ print(f" Transcript: {os.path.basename(transcript)}")+ else:+ print(f" Transcript: auto (Whisper)")+ print()++ confirm = _ask(f" {accent}Start?{reset} {dim}(Y/n){reset} ", default="y")+ if confirm.lower() not in ("y", "yes", ""):+ print(f" {gray}Cancelled.{reset}")+ return++ # Build command and run+ cmd = [sys.executable, os.path.abspath(__file__), "process", video]+ if transcript:+ cmd += ["--transcript", transcript]+ cmd += ["--caption-style", caption_style]+ cmd += ["--quality", quality]+ cmd += ["--top", str(top_n)]+ if logo:+ cmd += ["--logo", logo]++ print(f"\n {green}▶{reset} Starting...\n")+ sys.stdout.flush()+ sys.stderr.flush()+ os.execv(sys.executable, cmd)+++def _interactive_assets():+ """Interactive asset management."""++ accent = "\033[38;2;212;135;74m"+ gray = "\033[38;5;245m"+ green = "\033[38;2;74;222;128m"+ bold = "\033[1m"+ dim = "\033[2m"+ reset = "\033[0m"++ from services.asset_store import register, list_assets++ print(f"\n {bold}Assets{reset}")+ print(f" {accent}1{reset} List registered assets")+ print(f" {accent}2{reset} Add new asset")+ try:+ choice = input(f" {gray}>{reset} ").strip()+ except (EOFError, KeyboardInterrupt):+ return++ if choice == "1":+ assets = list_assets()+ if not assets:+ print(f"\n {gray}No assets. Choose 2 to add one.{reset}\n")+ return+ print()+ for a in assets:+ exists = os.path.exists(a["path"])+ icon = f"{green}✓{reset}" if exists else f"\033[38;2;248;113;113m✗{reset}"+ print(f" {icon} {accent}{a['name']}{reset} {gray}({a['type']}) {os.path.basename(a['path'])}{reset}")+ print()++ elif choice == "2":+ try:+ name = input(f"\n {bold}Asset name{reset} {dim}(short, e.g. mylogo){reset}: ").strip()+ path = input(f" {bold}File path:{reset} ").strip().strip("'\"")+ if name and path:+ asset = register(name, path)+ print(f"\n {green}✓{reset} Registered {accent}{name}{reset} ({asset['type']})\n")+ except (EOFError, KeyboardInterrupt, FileNotFoundError) as e:+ print(f"\n {gray}{e}{reset}\n")if __name__ == "__main__":diff --git a/backend/config/caption_styles.py b/backend/config/caption_styles.pyindex 10afda4..1d04348 100644--- a/backend/config/caption_styles.py+++ b/backend/config/caption_styles.py@@ -112,27 +112,30 @@ STYLES = {"logo_support": False,},"branded": {- "description": "Large bold text, ~7 words wrapping across 2-3 lines, dark box on active word. TikTok/Reels style.",+ "description": "Large bold text, 5-7 words wrapping across 2 lines, dark rounded pill on active word. Clean, no gradient.","font_name": DETECTED_FONT,- "font_size": 90,- "primary_color": "&H00FFFFFF", # White (all words)- "active_color": "&H00FFFFFF", # White text on box- "active_box_color": "&H00181818", # Dark box (near-black)- "outline_color": "&H00000000", # Black outline- "back_color": "&H00000000", # No shadow+ "font_size": 72, # Slightly smaller for clean 2-line fit+ "primary_color": "&H00FFFFFF", # White (all words)+ "active_color": "&H00FFFFFF", # White text on dark box+ "active_box_color": "&H00101010", # Near-black pill bg (slightly lighter than pure black)+ "active_box_padding_x": 20, # Horizontal padding inside pill+ "active_box_padding_y": 10, # Vertical padding inside pill+ "active_box_rounding": 8, # Border rounding for pill shape+ "outline_color": "&H00000000", # Black+ "back_color": "&H00000000", # Transparent"bold": True,- "outline_width": 0, # No outline — gradient provides contrast- "shadow_depth": 0,+ "outline_width": 0, # No outline — clean text+ "shadow_depth": 0, # No shadow"alignment": 2, # Bottom-center- "margin_v": 360, # Lower-third area- "words_per_chunk": 4, # Show ~4 words at a time- "uppercase": False, # Mixed case- "gradient_overlay": True, # Enable bottom 50% dark gradient- "gradient_opacity": 0.7, # 70% black at bottom edge- "logo_support": True, # Enable top-left logo- "logo_margin_x": 60, # Logo X offset from left- "logo_margin_y": 80, # Logo Y offset from top- "logo_height": 130, # Logo render height in px+ "margin_v": 500, # Position: ~72% from top (natural lower-third)+ "words_per_chunk": 6, # Show 5-7 words across 2 lines+ "uppercase": False, # Mixed case, natural capitalization+ "gradient_overlay": False, # No gradient — clean direct-on-video+ "gradient_opacity": 0.0,+ "logo_support": True, # Logo top-left+ "logo_margin_x": 40, # Logo X offset from left+ "logo_margin_y": 60, # Logo Y offset from top+ "logo_height": 100, # Logo height in px},}diff --git a/backend/main.py b/backend/main.pyindex a11787a..4af5c9c 100644--- a/backend/main.py+++ b/backend/main.py@@ -105,8 +105,8 @@ def handle_batch_clips(task_id: str, params: dict):logo_path=clip.get("logo_path") or params.get("logo_path"),outro_path=params.get("outro_path"),clean_fillers=params.get("clean_fillers", True),- progress_callback=lambda pct, msg: emit_progress(- task_id, "batch", int((i / total) * 100 + pct / total), msg+ progress_callback=lambda pct, msg, _i=i: emit_progress(+ task_id, "batch", int((_i / total) * 100 + pct / total), msg),)results.append({"clip_index": i, "status": "success", **result})@@ -126,7 +126,7 @@ def handle_batch_clips(task_id: str, params: dict):def handle_parse_transcript(task_id: str, params: dict):"""Parse a speaker-labeled transcript into word-level timestamps."""- from services.transcript_parser import parse_speaker_transcript+ from services.transcript_parser import detect_and_parseraw_text = params.get("raw_text", "")total_duration = params.get("total_duration")@@ -137,7 +137,7 @@ def handle_parse_transcript(task_id: str, params: dict):returnemit_progress(task_id, "parsing", 50, "Parsing transcript...")- result = parse_speaker_transcript(raw_text, total_duration=total_duration, time_adjust=time_adjust)+ result = detect_and_parse(raw_text, total_duration=total_duration, time_adjust=time_adjust)if "error" in result:emit_result(task_id, "error", error=result["error"])diff --git a/backend/requirements.txt b/backend/requirements.txtindex 55727a8..37f68c6 100644--- a/backend/requirements.txt+++ b/backend/requirements.txt@@ -8,16 +8,9 @@ openai-whisper>=20231117# pyannote.audio>=3.1.0# speechbrain>=1.0.0-# Video/audio processing-ffmpeg-python>=0.2.0-pydub>=0.25.1-# Face detection (optional, for smart cropping)opencv-python-headless>=4.8.0numpy>=1.24.0-# Data models-pydantic>=2.0.0-# Utilitiespython-dotenv>=1.0.0diff --git a/backend/services/asset_store.py b/backend/services/asset_store.pynew file mode 100644index 0000000..2056d0e--- /dev/null+++ b/backend/services/asset_store.py@@ -0,0 +1,129 @@+"""+Shared asset registry — works from CLI, Web UI, and MCP.++Assets are named references to local files (logos, intros, outros, images).+Register once, use by name everywhere:+ CLI: ./podcli process video.mp4 --logo deeptech+ MCP: create_clip(logo_path="deeptech")+ Web UI: select from dropdown++Registry stored at .podcli/assets/registry.json+"""++import json+import os+import shutil+from typing import Optional+++def _registry_path() -> str:+ """Path to the asset registry JSON file."""+ base = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", ".podcli", "assets")+ os.makedirs(base, exist_ok=True)+ return os.path.join(base, "registry.json")+++def _load() -> list[dict]:+ path = _registry_path()+ if not os.path.exists(path):+ return []+ try:+ with open(path) as f:+ data = json.load(f)+ return data.get("assets", []) if isinstance(data, dict) else data+ except (json.JSONDecodeError, IOError):+ return []+++def _save(assets: list[dict]):+ path = _registry_path()+ with open(path, "w") as f:+ json.dump({"assets": assets}, f, indent=2)+++def register(name: str, file_path: str, asset_type: str = "auto") -> dict:+ """+ Register a file as a named asset.++ Args:+ name: Short name to reference this asset (e.g., "deeptech", "outro")+ file_path: Absolute or relative path to the file+ asset_type: "logo", "video", "image", "audio", or "auto" (detect from extension)++ Returns:+ The registered asset dict+ """+ file_path = os.path.abspath(file_path)+ if not os.path.exists(file_path):+ raise FileNotFoundError(f"File not found: {file_path}")++ if asset_type == "auto":+ ext = os.path.splitext(file_path)[1].lower()+ type_map = {+ ".png": "logo", ".jpg": "image", ".jpeg": "image", ".svg": "logo",+ ".mp4": "video", ".mov": "video", ".mkv": "video", ".webm": "video",+ ".mp3": "audio", ".wav": "audio", ".m4a": "audio",+ }+ asset_type = type_map.get(ext, "other")++ assets = _load()++ # Update if name exists, otherwise add+ existing = next((i for i, a in enumerate(assets) if a["name"] == name), None)+ asset = {+ "name": name,+ "type": asset_type,+ "path": file_path,+ }++ if existing is not None:+ assets[existing] = asset+ else:+ assets.append(asset)++ _save(assets)+ return asset+++def unregister(name: str) -> bool:+ """Remove a named asset. Returns True if found and removed."""+ assets = _load()+ before = len(assets)+ assets = [a for a in assets if a["name"] != name]+ if len(assets) < before:+ _save(assets)+ return True+ return False+++def list_assets(asset_type: Optional[str] = None) -> list[dict]:+ """List all registered assets, optionally filtered by type."""+ assets = _load()+ if asset_type:+ return [a for a in assets if a["type"] == asset_type]+ return assets+++def resolve(name_or_path: str) -> Optional[str]:+ """+ Resolve a name or path to an absolute file path.++ First checks if it's a registered asset name, then treats it as a path.+ Returns None if nothing found.+ """+ if not name_or_path:+ return None++ # Check registered assets+ assets = _load()+ for a in assets:+ if a["name"] == name_or_path:+ if os.path.exists(a["path"]):+ return a["path"]++ # Treat as direct path+ path = os.path.abspath(name_or_path)+ if os.path.exists(path):+ return path++ return Nonediff --git a/backend/services/caption_renderer.py b/backend/services/caption_renderer.pyindex b8177c2..349f81e 100644--- a/backend/services/caption_renderer.py+++ b/backend/services/caption_renderer.py@@ -51,7 +51,7 @@ ScaledBorderAndShadow: yes[V4+ Styles]Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding-Style: BrandedNormal,{style["font_name"]},{style["font_size"]},&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,3,0,0,{style["alignment"]},80,80,{style["margin_v"]},1+Style: BrandedNormal,{style["font_name"]},{style["font_size"]},&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,2,0,3,0,0,{style["alignment"]},60,60,{style["margin_v"]},1[Events]Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text@@ -256,21 +256,27 @@ def _normalize_case(text: str) -> str:def _render_branded(words: list[dict], style: dict, offset: float) -> str:"""- Branded style — large bold text, dark rounded box on the active word.- Each chunk shows ~4 words. For each word's duration, that word gets a- dark background box (BorderStyle=3) while the others stay plain white.+ Branded style — large bold white text, dark rounded pill on active word only.- IMPORTANT: Dialogue lines are made contiguous — each word's display extends- to the next word's start (not its own end). This prevents flashing/gaps- between words that cause the entire text to disappear and reappear.+ Matches the reference: clean white text directly on video, currently-spoken+ word gets a near-black rounded rectangle background (pill shape). 5-7 words+ shown at a time across 2 natural lines. No gradient overlay.++ Each word's display is contiguous to the next word's start to prevent+ flashing/gaps between words."""header = generate_branded_header(style)events = []- chunk_size = style.get("words_per_chunk", 4)- raw_box = style.get("active_box_color", "&H00181818")- # Ensure color has trailing & for inline ASS overrides+ chunk_size = style.get("words_per_chunk", 6)++ raw_box = style.get("active_box_color", "&H00101010")box_color = raw_box if raw_box.endswith("&") else raw_box + "&"+ # Pill dimensions from style config+ pad_x = style.get("active_box_padding_x", 20)+ pad_y = style.get("active_box_padding_y", 10)+ rounding = style.get("active_box_rounding", 8)+# Group words into chunkschunks = []for i in range(0, len(words), chunk_size):@@ -284,7 +290,7 @@ def _render_branded(words: list[dict], style: dict, offset: float) -> str:chunk_start = max(0, chunk[0]["start"] - offset)chunk_end = max(0, chunk[-1]["end"] - offset)- # Normalize casing: lowercase except acronyms, capitalize first word+ # Normalize casing: sentence-case (lowercase except acronyms/I, capitalize first word)normalized = []for j, w in enumerate(chunk):text = _normalize_case(w["word"])@@ -292,39 +298,39 @@ def _render_branded(words: list[dict], style: dict, offset: float) -> str:text = text[0].upper() + text[1:] if len(text) > 1 else text.upper()normalized.append(text)- # For each word in the chunk, emit a dialogue line for its active window- # where THAT word has a dark box and the rest are plain.- # Key: each word's display extends to the NEXT word's start (contiguous)- # to prevent flashing/gaps between words.+ # For each word: emit a dialogue line where THAT word has a dark pill bgfor wi, w in enumerate(chunk):w_start = max(0, w["start"] - offset)- # End at next word's start (contiguous) instead of this word's end (gaps)+ # Contiguous: each word's display extends to next word's startif wi < len(chunk) - 1:w_end = max(0, chunk[wi + 1]["start"] - offset)else:- # Last word in chunk: extend to chunk endw_end = chunk_endif w_end <= w_start:- w_end = w_start + 0.1 # minimum display time+ w_end = w_start + 0.1- # Build line: all words visible, active one gets box override+ # Build line: all words visible, active one gets dark pill overrideparts = []for wj, text in enumerate(normalized):if wj == wi:- # Active word: dark rounded box background, white text- # BorderStyle=3: \4c = box fill color, \3c = box border- # \xbord/\ybord = horizontal/vertical padding around text- # \bord with higher value creates visible rounded-ish box+ # Active word: dark rounded pill background+ # \4c = box fill color (BorderStyle=3 uses BackColour as box)+ # \3c = box outline color (same as fill for solid pill)+ # \xbord = horizontal padding, \ybord = vertical padding+ # \bord = border thickness (creates rounding effect)parts.append(- f"{{\\4c{box_color}\\3c{box_color}\\xbord18\\ybord10\\bord4\\shad0}}{text}{{\\4c&H00000000&\\3c&H00000000&\\xbord0\\ybord0\\bord0}}"+ f"{{\\4c{box_color}\\3c{box_color}"+ f"\\xbord{pad_x}\\ybord{pad_y}\\bord{rounding}"+ f"\\shad0}}{text}"+ f"{{\\4c&H00000000&\\3c&H00000000&"+ f"\\xbord0\\ybord0\\bord0}}")else:parts.append(text)line_text = " ".join(parts)-start_ts = seconds_to_ass(w_start)end_ts = seconds_to_ass(w_end)diff --git a/backend/services/claude_suggest.py b/backend/services/claude_suggest.pynew file mode 100644index 0000000..129f68e--- /dev/null+++ b/backend/services/claude_suggest.py@@ -0,0 +1,219 @@+"""+Clip suggestion via Claude Code.++Delegates moment selection to Claude, which uses the PodStack knowledge base+(.podcli/knowledge/) and CLAUDE.md for context-aware clip extraction.++Falls back to heuristic scoring if Claude is unavailable.+"""++import json+import os+import subprocess+import sys+import tempfile+from typing import Optional, Callable+++def _find_claude() -> Optional[str]:+ """Find the claude CLI binary."""+ # Check common locations+ for path in [+ os.path.expanduser("~/.local/bin/claude"),+ "/usr/local/bin/claude",+ "/opt/homebrew/bin/claude",+ ]:+ if os.path.exists(path):+ return path++ # Check PATH+ try:+ result = subprocess.run(["which", "claude"], capture_output=True, text=True, timeout=5)+ if result.returncode == 0 and result.stdout.strip():+ return result.stdout.strip()+ except Exception:+ pass++ return None+++def _build_prompt(transcript_text: str, segment_count: int, duration_min: float, top_n: int) -> str:+ """Build the prompt for Claude to extract clips."""+ return f"""You are the clip extraction engine for a podcast. Analyze this transcript and return the {top_n} best moments for YouTube Shorts.++IMPORTANT: Return ONLY valid JSON. No markdown, no explanation, no code fences.++Use the knowledge base in .podcli/knowledge/ for:+- Voice and tone rules (02-voice-and-tone.md)+- Moment selection criteria (04-shorts-creation-guide.md)+- Content type classification (05-title-formulas.md)+- Existing episodes to avoid duplicates (03-episodes-database.md)++Score each moment on 4 dimensions (1-5 each):+- standalone: Makes sense without episode context?+- hook: Grabs attention in first 3 seconds?+- relevance: Matters to target audience?+- quotability: Memorable, shareable phrasing?++Classify each as: guest_story | technical_insight | market_landscape | business_strategy | hot_take++Return this exact JSON structure:+{{+ "clips": [+ {{+ "title": "First strong sentence from the moment",+ "start_second": 123.4,+ "end_second": 178.9,+ "duration": 55,+ "content_type": "guest_story",+ "scores": {{"standalone": 4, "hook": 5, "relevance": 4, "quotability": 3}},+ "total_score": 16,+ "quote": "The key quote from this moment",+ "why": "One sentence on why this works as a short"+ }}+ ]+}}++Rules:+- Clips must be 20-90 seconds+- Must start and end on sentence boundaries+- Must make sense standalone (no "as I mentioned earlier")+- Prioritize: surprising facts, bold claims, founder stories, counterintuitive insights+- Variety across content types+- Sort by timestamp order++Transcript ({segment_count} segments, ~{duration_min:.0f} min):++{transcript_text}"""+++def suggest_with_claude(+ segments: list[dict],+ top_n: int = 5,+ progress_callback: Optional[Callable[[int, str], None]] = None,+) -> Optional[list[dict]]:+ """+ Use Claude Code to extract the best clip moments from transcript segments.++ Returns list of clip dicts or None if Claude is unavailable.+ """+ claude_path = _find_claude()+ if not claude_path:+ return None++ if progress_callback:+ progress_callback(0, "Preparing transcript for Claude...")++ # Build transcript text from segments+ lines = []+ for seg in segments:+ speaker = seg.get("speaker", "")+ speaker_label = f"[{speaker}] " if speaker else ""+ start = seg.get("start", 0)+ mins = int(start) // 60+ secs = int(start) % 60+ text = seg.get("text", "").strip()+ if text:+ lines.append(f"({mins}:{secs:02d}) {speaker_label}{text}")++ transcript_text = "\n".join(lines)++ # Estimate duration+ duration_min = 0+ if segments:+ duration_min = (segments[-1].get("end", 0) - segments[0].get("start", 0)) / 60++ prompt = _build_prompt(transcript_text, len(segments), duration_min, top_n)++ # Write prompt to temp file to avoid shell escaping issues+ project_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")++ with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False, dir=project_dir) as f:+ f.write(prompt)+ prompt_file = f.name++ if progress_callback:+ progress_callback(20, "Asking Claude to analyze transcript...")++ try:+ # Call claude with --print (non-interactive, outputs result directly)+ # Run from the podcli project dir so it picks up CLAUDE.md + knowledge base+ result = subprocess.run(+ [claude_path, "--print", "-p", f"$(cat {prompt_file})"],+ capture_output=True,+ text=True,+ cwd=project_dir,+ timeout=300, # 5 min max+ shell=True,+ )++ if result.returncode != 0:+ if progress_callback:+ progress_callback(0, f"Claude returned error: {result.stderr[:200]}")+ return None++ if progress_callback:+ progress_callback(80, "Parsing Claude's suggestions...")++ # Parse JSON from Claude's response+ response = result.stdout.strip()++ # Try to find JSON in the response (Claude might add text around it)+ json_start = response.find("{")+ json_end = response.rfind("}") + 1+ if json_start >= 0 and json_end > json_start:+ json_str = response[json_start:json_end]+ data = json.loads(json_str)+ else:+ # Try parsing the whole thing+ data = json.loads(response)++ clips = data.get("clips", [])++ if not clips:+ return None++ # Normalize to the format the CLI expects+ normalized = []+ for c in clips:+ scores = c.get("scores", {})+ total = sum(scores.values()) if scores else c.get("total_score", 0)+ normalized.append({+ "title": c.get("title", "Untitled")[:55],+ "start_second": round(float(c.get("start_second", 0)), 1),+ "end_second": round(float(c.get("end_second", 0)), 1),+ "duration": round(float(c.get("duration", 0))),+ "score": total,+ "content_type": c.get("content_type", "unknown"),+ "quote": c.get("quote", ""),+ "why": c.get("why", ""),+ "reasons": [c.get("content_type", "")],+ "preview": c.get("quote", "")[:120],+ })++ # Sort by timestamp+ normalized.sort(key=lambda x: x["start_second"])++ if progress_callback:+ progress_callback(100, f"Claude suggested {len(normalized)} clips")++ return normalized++ except json.JSONDecodeError as e:+ if progress_callback:+ progress_callback(0, f"Could not parse Claude's response as JSON: {e}")+ return None+ except subprocess.TimeoutExpired:+ if progress_callback:+ progress_callback(0, "Claude timed out (5 min limit)")+ return None+ except Exception as e:+ if progress_callback:+ progress_callback(0, f"Claude error: {e}")+ return None+ finally:+ # Clean up temp file+ try:+ os.unlink(prompt_file)+ except Exception:+ passdiff --git a/backend/services/clip_generator.py b/backend/services/clip_generator.pyindex aabdfcf..ffdb72f 100644--- a/backend/services/clip_generator.py+++ b/backend/services/clip_generator.py@@ -117,7 +117,12 @@ def generate_clip(progress_callback(30, f"Resizing for vertical format (2/{total_steps})")cropped_path = os.path.join(work_dir, "cropped.mp4")- crop_to_vertical(segment_path, cropped_path, strategy=crop_strategy)+ crop_to_vertical(+ segment_path, cropped_path,+ strategy=crop_strategy,+ transcript_words=transcript_words,+ clip_start=start_second,+ )# Step 3: Generate captions + burn (with optional gradient & logo)if transcript_words:diff --git a/backend/services/encoder.py b/backend/services/encoder.pyindex 0e10bfb..6bce7f4 100644--- a/backend/services/encoder.py+++ b/backend/services/encoder.py@@ -68,7 +68,9 @@ def _test_encoder(encoder: str) -> bool:"""tmp_out = Nonetry:- tmp_out = tempfile.mktemp(suffix=".mp4")+ tmp_fd = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)+ tmp_out = tmp_fd.name+ tmp_fd.close()flags = _get_encoder_flags(encoder)cmd = ["ffmpeg", "-y",diff --git a/backend/services/transcript_parser.py b/backend/services/transcript_parser.pyindex 986d684..e34fa4c 100644--- a/backend/services/transcript_parser.py+++ b/backend/services/transcript_parser.py@@ -10,9 +10,285 @@ Supported format:"""import re+import jsonfrom typing import List, Dict, Any, Optional+def parse_srt_timestamp(ts: str) -> float:+ """Convert SRT timestamp HH:MM:SS,mmm to seconds."""+ ts = ts.strip().replace(",", ".")+ parts = ts.split(":")+ if len(parts) == 3:+ return int(parts[0]) * 3600 + int(parts[1]) * 60 + float(parts[2])+ return 0.0+++def parse_vtt_timestamp(ts: str) -> float:+ """Convert VTT timestamp HH:MM:SS.mmm or MM:SS.mmm to seconds."""+ ts = ts.strip()+ parts = ts.split(":")+ if len(parts) == 3:+ return int(parts[0]) * 3600 + int(parts[1]) * 60 + float(parts[2])+ elif len(parts) == 2:+ return int(parts[0]) * 60 + float(parts[1])+ return 0.0+++def parse_srt(text: str, total_duration: Optional[float] = None, time_adjust: float = 0.0) -> Dict[str, Any]:+ """+ Parse an SRT subtitle file into structured data with word-level timestamps.++ SRT format:+ 1+ 00:00:01,000 --> 00:00:04,000+ Hello this is text+ """+ blocks = []+ current_start = 0.0+ current_end = 0.0+ current_text_lines: List[str] = []+ state = "index" # index, timestamp, text++ for line in text.strip().split("\n"):+ line_stripped = line.strip()++ if state == "index":+ if re.match(r'^\d+$', line_stripped):+ state = "timestamp"+ continue++ if state == "timestamp":+ match = re.match(r'(\d{2}:\d{2}:\d{2},\d{3})\s*-->\s*(\d{2}:\d{2}:\d{2},\d{3})', line_stripped)+ if match:+ current_start = parse_srt_timestamp(match.group(1))+ current_end = parse_srt_timestamp(match.group(2))+ current_text_lines = []+ state = "text"+ continue++ if state == "text":+ if line_stripped == "":+ # End of block+ text_content = " ".join(current_text_lines).strip()+ # Strip HTML-like tags+ text_content = re.sub(r'<[^>]+>', '', text_content)+ text_content = re.sub(r'\s+', ' ', text_content).strip()+ if text_content:+ blocks.append({+ "start": current_start,+ "end": current_end,+ "text": text_content,+ })+ state = "index"+ else:+ current_text_lines.append(line_stripped)++ # Handle last block if file doesn't end with blank line+ if state == "text" and current_text_lines:+ text_content = " ".join(current_text_lines).strip()+ text_content = re.sub(r'<[^>]+>', '', text_content)+ text_content = re.sub(r'\s+', ' ', text_content).strip()+ if text_content:+ blocks.append({+ "start": current_start,+ "end": current_end,+ "text": text_content,+ })++ if not blocks:+ return {"error": "No subtitle blocks found in SRT"}++ return _blocks_to_result(blocks, total_duration, time_adjust, fmt="srt")+++def parse_vtt(text: str, total_duration: Optional[float] = None, time_adjust: float = 0.0) -> Dict[str, Any]:+ """+ Parse a WebVTT subtitle file into structured data with word-level timestamps.++ VTT format:+ WEBVTT++ 00:00:01.000 --> 00:00:04.000+ Hello this is text+ """+ blocks = []+ current_start = 0.0+ current_end = 0.0+ current_text_lines: List[str] = []+ in_text = False++ lines = text.strip().split("\n")+ # Skip WEBVTT header and any metadata+ i = 0+ while i < len(lines):+ if lines[i].strip().startswith("WEBVTT"):+ i += 1+ break+ i += 1++ for line in lines[i:]:+ line_stripped = line.strip()++ # Check for timestamp line+ ts_match = re.match(+ r'(\d{1,2}:\d{2}:\d{2}\.\d{3}|\d{2}:\d{2}\.\d{3})\s*-->\s*(\d{1,2}:\d{2}:\d{2}\.\d{3}|\d{2}:\d{2}\.\d{3})',+ line_stripped,+ )+ if ts_match:+ # Save previous block+ if in_text and current_text_lines:+ text_content = " ".join(current_text_lines).strip()+ text_content = re.sub(r'<[^>]+>', '', text_content)+ text_content = re.sub(r'\s+', ' ', text_content).strip()+ if text_content:+ blocks.append({+ "start": current_start,+ "end": current_end,+ "text": text_content,+ })++ current_start = parse_vtt_timestamp(ts_match.group(1))+ current_end = parse_vtt_timestamp(ts_match.group(2))+ current_text_lines = []+ in_text = True+ continue++ if in_text:+ if line_stripped == "":+ text_content = " ".join(current_text_lines).strip()+ text_content = re.sub(r'<[^>]+>', '', text_content)+ text_content = re.sub(r'\s+', ' ', text_content).strip()+ if text_content:+ blocks.append({+ "start": current_start,+ "end": current_end,+ "text": text_content,+ })+ current_text_lines = []+ in_text = False+ else:+ # Skip cue identifiers (lines that are just numbers or names before timestamps)+ current_text_lines.append(line_stripped)++ # Handle last block+ if in_text and current_text_lines:+ text_content = " ".join(current_text_lines).strip()+ text_content = re.sub(r'<[^>]+>', '', text_content)+ text_content = re.sub(r'\s+', ' ', text_content).strip()+ if text_content:+ blocks.append({+ "start": current_start,+ "end": current_end,+ "text": text_content,+ })++ if not blocks:+ return {"error": "No subtitle blocks found in VTT"}++ return _blocks_to_result(blocks, total_duration, time_adjust, fmt="vtt")+++def _blocks_to_result(blocks: List[Dict], total_duration: Optional[float], time_adjust: float, fmt: str) -> Dict[str, Any]:+ """Convert parsed subtitle blocks into the standard output format."""+ all_words = []+ segments = []++ for block in blocks:+ words_in_block = block["text"].split()+ if not words_in_block:+ continue++ block_duration = block["end"] - block["start"]+ usable_duration = block_duration * 0.95+ word_duration = usable_duration / len(words_in_block) if words_in_block else 0++ for j, w in enumerate(words_in_block):+ word_start = block["start"] + j * word_duration + time_adjust+ word_end = word_start + word_duration * 0.9+ all_words.append({+ "word": w,+ "start": round(max(0, word_start), 3),+ "end": round(max(0, word_end), 3),+ "speaker": None,+ })++ segments.append({+ "text": block["text"],+ "start": round(max(0, block["start"] + time_adjust), 3),+ "end": round(max(0, block["end"] + time_adjust), 3),+ "speaker": None,+ })++ full_text = " ".join(w["word"] for w in all_words)+ duration = total_duration or (blocks[-1]["end"] if blocks else 0)++ return {+ "transcript": full_text,+ "words": all_words,+ "segments": segments,+ "duration": round(duration, 2),+ "language": "en",+ "speakers": [],+ "speaker_segments": [],+ "imported": True,+ "format": fmt,+ }+++def detect_and_parse(text: str, total_duration: Optional[float] = None, time_adjust: float = 0.0) -> Dict[str, Any]:+ """+ Auto-detect transcript format and parse accordingly.++ Detection rules:+ - SRT: starts with a digit line followed by a timestamp line (e.g. "1\n00:00:01,000 -->")+ - VTT: starts with "WEBVTT"+ - JSON: starts with { or [+ - Otherwise: speaker format (e.g. "Speaker (MM:SS)\nText...")+ """+ stripped = text.strip()++ # VTT detection+ if stripped.startswith("WEBVTT"):+ return parse_vtt(text, total_duration=total_duration, time_adjust=time_adjust)++ # SRT detection: first line is a digit, second line contains -->+ lines = stripped.split("\n", 3)+ if len(lines) >= 2 and re.match(r'^\d+$', lines[0].strip()) and '-->' in lines[1]:+ return parse_srt(text, total_duration=total_duration, time_adjust=time_adjust)++ # JSON detection+ if stripped.startswith("{") or stripped.startswith("["):+ try:+ data = json.loads(stripped)+ if isinstance(data, list):+ words = data+ segments_list: List[Dict] = []+ else:+ words = data.get("words", [])+ segments_list = data.get("segments", [])+ full_text = " ".join(w.get("word", "") for w in words)+ duration = total_duration or 0+ if words:+ last_end = max(w.get("end", 0) for w in words)+ duration = total_duration or last_end+ return {+ "transcript": full_text,+ "words": words,+ "segments": segments_list,+ "duration": round(duration, 2),+ "language": "en",+ "speakers": [],+ "speaker_segments": [],+ "imported": True,+ "format": "json",+ }+ except json.JSONDecodeError:+ pass # Fall through to speaker format++ # Default: speaker format+ return parse_speaker_transcript(text, total_duration=total_duration, time_adjust=time_adjust)++def parse_timestamp(ts: str) -> float:"""Convert MM:SS or HH:MM:SS to seconds."""parts = ts.strip().split(":")diff --git a/backend/services/video_processor.py b/backend/services/video_processor.pyindex 66a14ce..d68a991 100644--- a/backend/services/video_processor.py+++ b/backend/services/video_processor.py@@ -13,7 +13,18 @@ from typing import Optionalfrom services.encoder import get_video_encode_flagsimport sys-CPU_FLAGS = ["-c:v", "libx264", "-crf", "18", "-preset", "slow", "-profile:v", "high"]+# Quality presets: name → (crf, preset)+# Lower CRF = higher quality = larger file. 18 is visually lossless.+QUALITY_PRESETS = {+ "low": {"crf": "28", "preset": "fast"}, # ~2-4 MB/min, fast encode+ "medium": {"crf": "23", "preset": "medium"}, # ~4-8 MB/min, balanced+ "high": {"crf": "18", "preset": "slow"}, # ~8-15 MB/min, great quality+ "max": {"crf": "14", "preset": "slower"}, # ~15-30 MB/min, near-lossless+}++_quality = os.environ.get("PODCLI_QUALITY", "high")+_qp = QUALITY_PRESETS.get(_quality, QUALITY_PRESETS["high"])+CPU_FLAGS = ["-c:v", "libx264", "-crf", _qp["crf"], "-preset", _qp["preset"], "-profile:v", "high"]def _run_ffmpeg_with_fallback(cmd_parts_before_enc: list, cmd_parts_after_enc: list, output_path: str, label: str = "encode") -> str:@@ -100,6 +111,8 @@ def crop_to_vertical(input_path: str,output_path: str,strategy: str = "face",+ transcript_words: list = None,+ clip_start: float = 0,) -> str:"""Crop/scale video to 1080x1920 (9:16 vertical).@@ -107,6 +120,12 @@ def crop_to_vertical(Strategies:- center: Take center column of the frame, scale to fit- face: Detect face position, center crop on face (falls back to center)+ - speaker: Like face, but switches to the active speaker using transcript+ word-level speaker labels. Falls back to face then center.++ transcript_words: Word dicts with 'speaker', 'start', 'end' keys (from Whisper+pyannote).+ Used by 'face' strategy when speaker data is available.+ clip_start: The start time of this clip in the original video (for timestamp alignment)."""width, height = get_dimensions(input_path)target_w, target_h = 1080, 1920@@ -114,29 +133,45 @@ def crop_to_vertical(source_ratio = width / height- if strategy == "face":- crop_x = _detect_face_offset(input_path, width, height, target_ratio)- if crop_x is not None:- crop_h = height- crop_w = int(crop_h * target_ratio)- vf = f"crop={crop_w}:{crop_h}:{crop_x}:0,scale={target_w}:{target_h}"+ if strategy in ("face", "speaker"):+ # Check if we have multi-speaker data — if so, do speaker-aware crop+ has_speakers = (+ transcript_words+ and len(set(w.get("speaker") for w in transcript_words if w.get("speaker"))) > 1+ )++ if has_speakers:+ crop_x_expr = _build_speaker_aware_crop(+ input_path, width, height, target_ratio,+ transcript_words, clip_start,+ )+ if crop_x_expr is not None:+ crop_h = height+ crop_w = int(crop_h * target_ratio)+ # crop_x_expr is either a static int or an FFmpeg expression for dynamic panning+ vf = f"crop={crop_w}:{crop_h}:{crop_x_expr}:0,scale={target_w}:{target_h}"+ else:+ strategy = "center"else:- # Fallback to center- strategy = "center"+ # Single speaker or no speaker data — use static face detection+ crop_x = _detect_face_offset(input_path, width, height, target_ratio)+ if crop_x is not None:+ crop_h = height+ crop_w = int(crop_h * target_ratio)+ vf = f"crop={crop_w}:{crop_h}:{crop_x}:0,scale={target_w}:{target_h}"+ else:+ strategy = "center"if strategy == "center":if source_ratio > target_ratio:- # Source is wider than target — crop sidescrop_h = heightcrop_w = int(crop_h * target_ratio)crop_x = (width - crop_w) // 2vf = f"crop={crop_w}:{crop_h}:{crop_x}:0,scale={target_w}:{target_h}"else:- # Source is taller or same — crop top/bottom or padcrop_w = widthcrop_h = int(crop_w / target_ratio)if crop_h > height:- # Need to pad (letterbox)vf = f"scale={target_w}:-2,pad={target_w}:{target_h}:(ow-iw)/2:(oh-ih)/2:black"else:crop_y = (height - crop_h) // 2@@ -150,7 +185,7 @@ def crop_to_vertical(],cmd_parts_after_enc=["-c:a", "aac",- "-b:a", "128k",+ "-b:a", "192k","-ar", "44100","-movflags", "+faststart",],@@ -159,6 +194,194 @@ def crop_to_vertical()+def _build_speaker_aware_crop(+ video_path: str,+ width: int,+ height: int,+ target_ratio: float,+ transcript_words: list,+ clip_start: float,+) -> Optional[str]:+ """+ Build a speaker-aware crop that pans to whoever is speaking.++ 1. Detect ALL faces in the video and cluster them by position (left vs right).+ 2. Map each cluster to a speaker using transcript word timing + face position.+ 3. Build an FFmpeg expression that switches crop_x based on timestamp.++ Returns an FFmpeg crop x expression string, or None if detection fails.+ """+ try:+ import cv2+ import numpy as np++ cap = cv2.VideoCapture(video_path)+ if not cap.isOpened():+ return None++ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))+ fps = cap.get(cv2.CAP_PROP_FPS) or 30+ duration = total_frames / fps+ crop_w = int(height * target_ratio)++ # Load DNN face detector+ backend_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+ proto = os.path.join(backend_dir, "models", "deploy.prototxt")+ model = os.path.join(backend_dir, "models", "res10_300x300_ssd_iter_140000.caffemodel")+ if not (os.path.exists(proto) and os.path.exists(model)):+ cap.release()+ return None++ detector = cv2.dnn.readNetFromCaffe(proto, model)++ # Sample frames and detect ALL faces with their positions and timestamps+ sample_count = min(80, max(30, int(duration * 4))) # ~4 samples/sec+ face_observations = [] # list of (time_in_clip, face_center_x, face_width)++ for i in range(sample_count):+ t = i * duration / sample_count+ cap.set(cv2.CAP_PROP_POS_MSEC, t * 1000)+ ret, frame = cap.read()+ if not ret:+ continue++ h, w = frame.shape[:2]+ blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 1.0, (300, 300), (104.0, 177.0, 123.0))+ detector.setInput(blob)+ detections = detector.forward()++ for j in range(detections.shape[2]):+ conf = detections[0, 0, j, 2]+ if conf > 0.5:+ x1 = int(detections[0, 0, j, 3] * w)+ x2 = int(detections[0, 0, j, 5] * w)+ fw = x2 - x1+ if fw < w * 0.04:+ continue+ cx = (x1 + x2) // 2+ face_observations.append((t, cx, fw))++ cap.release()++ if len(face_observations) < 5:+ return None++ # Cluster faces into positions (typically 2 for a podcast: left + right)+ positions = np.array([obs[1] for obs in face_observations])+ cluster_radius = width * 0.15++ clusters = []+ used = np.zeros(len(positions), dtype=bool)+ sorted_idx = np.argsort(positions)++ for idx in sorted_idx:+ if used[idx]:+ continue+ mask = np.abs(positions - positions[idx]) < cluster_radius+ mask &= ~used+ cluster_indices = np.where(mask)[0]+ if len(cluster_indices) > 0:+ cluster_center = int(np.median(positions[mask]))+ clusters.append({+ "center_x": cluster_center,+ "count": len(cluster_indices),+ "crop_x": max(0, min(cluster_center - crop_w // 2, width - crop_w)),+ })+ used |= mask++ if len(clusters) < 2:+ # Only one face position found — use static crop on it+ if clusters:+ return str(clusters[0]["crop_x"])+ return None++ # Sort clusters left to right+ clusters.sort(key=lambda c: c["center_x"])++ # Map speakers to face positions using transcript word timing.+ # For each speaker, find which face cluster is most visible when they talk.+ speakers = list(set(w.get("speaker") for w in transcript_words if w.get("speaker")))+ if len(speakers) < 2:+ # Can't distinguish — use the most frequent face+ clusters.sort(key=lambda c: c["count"], reverse=True)+ return str(clusters[0]["crop_x"])++ speaker_to_cluster = {}+ for speaker in speakers:+ # Get time ranges when this speaker is talking (relative to clip)+ speaker_times = []+ for w in transcript_words:+ if w.get("speaker") == speaker:+ speaker_times.append(w["start"] - clip_start)++ # Count which face cluster is most visible during this speaker's words+ cluster_votes = [0] * len(clusters)+ for t in speaker_times:+ # Find face observations near this timestamp+ for obs_t, obs_cx, obs_fw in face_observations:+ if abs(obs_t - t) < 1.0: # within 1 second+ for ci, cl in enumerate(clusters):+ if abs(obs_cx - cl["center_x"]) < cluster_radius:+ cluster_votes[ci] += 1++ if any(cluster_votes):+ best_cluster_idx = max(range(len(cluster_votes)), key=lambda i: cluster_votes[i])+ speaker_to_cluster[speaker] = clusters[best_cluster_idx]++ # Build an FFmpeg expression that pans based on who's speaking.+ # We create time-based segments and smooth-pan between positions.+ # Group consecutive words by speaker to create segments+ segments = [] # (start_time_in_clip, end_time_in_clip, speaker)+ current_speaker = None+ seg_start = 0++ for w in sorted(transcript_words, key=lambda x: x["start"]):+ sp = w.get("speaker")+ t = w["start"] - clip_start+ if sp != current_speaker and sp is not None:+ if current_speaker is not None:+ segments.append((seg_start, t, current_speaker))+ current_speaker = sp+ seg_start = t++ if current_speaker is not None:+ segments.append((seg_start, duration, current_speaker))++ if not segments:+ clusters.sort(key=lambda c: c["count"], reverse=True)+ return str(clusters[0]["crop_x"])++ # Build FFmpeg crop x expression using nested if(between()) for each segment.+ # This creates smooth panning between speakers.+ # Default to the most-detected face+ default_cluster = max(clusters, key=lambda c: c["count"])+ default_x = default_cluster["crop_x"]++ # Simplify: if only 2 face positions, use a clean between() chain+ expr_parts = []+ for start_t, end_t, speaker in segments:+ cl = speaker_to_cluster.get(speaker)+ if cl and cl["crop_x"] != default_x:+ expr_parts.append(f"if(between(t\\,{start_t:.1f}\\,{end_t:.1f})\\,{cl['crop_x']}\\,")++ if not expr_parts:+ return str(default_x)++ # Build nested expression: if(cond1, val1, if(cond2, val2, default))+ expr = ""+ for part in expr_parts:+ expr += part+ expr += str(default_x)+ expr += ")" * len(expr_parts)++ return expr++ except ImportError:+ return None+ except Exception:+ return None++def _create_gradient_png(output_path: str, width: int = 1080, height: int = 1920, opacity: float = 0.7) -> str:"""Create a transparent-to-black gradient PNG for the bottom 50% of the frame.diff --git a/podcli b/podcliindex ffe0d58..87fde97 100755--- a/podcli+++ b/podcli@@ -4,6 +4,9 @@SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+# Suppress macOS ObjC duplicate class warnings (OpenCV + Homebrew conflict)+export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES+# Use venv python if availableif [ -f "$SCRIPT_DIR/venv/bin/python3" ]; thenPYTHON="$SCRIPT_DIR/venv/bin/python3"@@ -14,4 +17,4 @@ elsePYTHON="python3"fi-exec "$PYTHON" "$SCRIPT_DIR/backend/cli.py" "$@"+exec "$PYTHON" -W ignore::UserWarning "$SCRIPT_DIR/backend/cli.py" "$@" 2> >(grep -v -e '^objc\[' -e 'FP16 is not supported' -e 'warnings.warn' >&2)diff --git a/setup.sh b/setup.shindex 0bb3358..5d4aedf 100755--- a/setup.sh+++ b/setup.sh@@ -96,6 +96,17 @@ install() {pip install -q -r backend/requirements.txt 2>&1 | tail -3echo " ✓ Python packages ready"+ # Fix macOS SSL certificates (needed for Whisper model download)+ if [[ "$OSTYPE" == "darwin"* ]]; then+ PY_VER=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")+ CERT_SCRIPT="/Applications/Python ${PY_VER}/Install Certificates.command"+ if [ -f "$CERT_SCRIPT" ]; then+ echo " → Configuring SSL certificates..."+ bash "$CERT_SCRIPT" > /dev/null 2>&1 || true+ echo " ✓ SSL certificates configured"+ fi+ fi+echo ""echo "━━━ [5/6] Installing Node packages ━━━"npm install --silent 2>&1 | tail -1diff --git a/src/handlers/create-clip.handler.ts b/src/handlers/create-clip.handler.tsindex f2b2739..0971c93 100644--- a/src/handlers/create-clip.handler.ts+++ b/src/handlers/create-clip.handler.ts@@ -95,11 +95,6 @@ export const createClipToolDef = {type: "string",description: "Path to an outro video to append at the end of the clip",},- generate_thumbnail: {- type: "boolean",- description: "[Future] Whether to auto-generate a thumbnail image",- default: false,- },},required: [],},@@ -176,7 +171,6 @@ export async function handleCreateClip(clean_fillers: input.clean_fillers !== false,logo_path: logoPath,outro_path: outroPath,- generate_thumbnail: input.generate_thumbnail || false,});const data = result.data as unknown as ClipResult;diff --git a/src/models/index.ts b/src/models/index.tsindex fcd66f0..c1f3775 100644--- a/src/models/index.ts+++ b/src/models/index.ts@@ -67,7 +67,7 @@ export interface TranscriptResult {// === Clip Models ===-export type CaptionStyle = "hormozi" | "karaoke" | "subtle";+export type CaptionStyle = "branded" | "hormozi" | "karaoke" | "subtle";export type CropStrategy = "center" | "face";export interface ClipRequest {diff --git a/src/server.ts b/src/server.tsindex 0906de9..3322bba 100644--- a/src/server.ts+++ b/src/server.ts@@ -255,9 +255,10 @@ export function createServer(): McpServer {createClipToolDef.name,createClipToolDef.description,{- video_path: z.string().describe("Path to the original podcast video"),- start_second: z.number().describe("Clip start time in seconds"),- end_second: z.number().describe("Clip end time in seconds"),+ clip_number: z.number().optional().describe("Export a suggested clip by its number (from suggest_clips). Auto-fills video_path, start/end times, title, and transcript_words from session state."),+ video_path: z.string().optional().describe("Path to the original podcast video. Auto-loaded from session state if clip_number is provided."),+ start_second: z.number().optional().describe("Clip start time in seconds. Auto-loaded from clip_number if omitted."),+ end_second: z.number().optional().describe("Clip end time in seconds. Auto-loaded from clip_number if omitted."),caption_style: z.enum(["hormozi", "karaoke", "subtle", "branded"]).optional()@@ -277,7 +278,8 @@ export function createServer(): McpServer {confidence: z.number().optional().default(0),}))- .describe("Word-level timestamps"),+ .optional()+ .describe("Word-level timestamps. Auto-loaded from session state if omitted."),title: z.string().optional().default("clip").describe("Clip title"),logo_path: z.string()@@ -287,11 +289,6 @@ export function createServer(): McpServer {.string().optional().describe("Path to an outro video to append at the end of the clip"),- generate_thumbnail: z- .boolean()- .optional()- .default(false)- .describe("[Future] Auto-generate thumbnail"),},async (params) => {try {@@ -343,8 +340,9 @@ export function createServer(): McpServer {const webData = await webRes.json() as any;const jobId = webData.job_id;- // Poll the job until completion- while (true) {+ // Poll the job until completion (1 hour max)+ const deadline = Date.now() + 3600_000;+ while (Date.now() < deadline) {await new Promise((r) => setTimeout(r, 2000));const pollRes = await fetch(`http://localhost:3847/api/job/${jobId}`);if (!pollRes.ok) break;@@ -358,6 +356,9 @@ export function createServer(): McpServer {throw new Error(job.error || "Job failed");}}+ if (!usedWebServer) {+ throw new Error("Clip creation timed out after 1 hour");+ }}} catch (webErr: unknown) {const webMsg = webErr instanceof Error ? webErr.message : String(webErr);@@ -428,7 +429,7 @@ export function createServer(): McpServer {batchClipsToolDef.name,batchClipsToolDef.description,{- video_path: z.string().describe("Path to the original podcast video"),+ video_path: z.string().optional().describe("Path to the original podcast video. Auto-loaded from session state if omitted."),clips: z.array(z.object({@@ -439,7 +440,8 @@ export function createServer(): McpServer {crop_strategy: z.enum(["center", "face"]).optional(),}))- .describe("Array of clips to create"),+ .optional()+ .describe("Array of clips to create. Auto-loaded from suggestions if omitted."),transcript_words: z.array(z.object({@@ -449,7 +451,10 @@ export function createServer(): McpServer {confidence: z.number().optional().default(0),}))- .describe("Word-level timestamps"),+ .optional()+ .describe("Word-level timestamps. Auto-loaded from session state if omitted."),+ export_selected: z.boolean().optional().describe("If true, export all selected suggestions from the UI."),+ clip_numbers: z.array(z.number()).optional().describe("Export specific clip numbers from suggestions (e.g. [1, 3, 5])."),},async (params) => {try {@@ -471,8 +476,9 @@ export function createServer(): McpServer {const webData = await webRes.json() as any;const jobId = webData.job_id;- // Poll the job until completion- while (true) {+ // Poll the job until completion (1 hour max)+ const deadline = Date.now() + 3600_000;+ while (Date.now() < deadline) {await new Promise((r) => setTimeout(r, 2000));const pollRes = await fetch(`http://localhost:3847/api/job/${jobId}`);if (!pollRes.ok) break;@@ -486,6 +492,9 @@ export function createServer(): McpServer {throw new Error(job.error || "Job failed");}}+ if (!usedWebServer) {+ throw new Error("Batch clip creation timed out after 1 hour");+ }}} catch (webErr: unknown) {const webMsg = webErr instanceof Error ? webErr.message : String(webErr);@@ -512,7 +521,7 @@ export function createServer(): McpServer {for (const r of parsed.results as any[]) {if (r.status === "success" && r.output_path) {await history.record({- source_video: params.video_path,+ source_video: params.video_path || "",start_second: r.start_second || 0,end_second: r.end_second || 0,caption_style: r.caption_style || "hormozi",diff --git a/src/ui/public/index.html b/src/ui/public/index.htmlindex a71378c..11aaca1 100644--- a/src/ui/public/index.html+++ b/src/ui/public/index.html@@ -240,8 +240,12 @@const [historyOpen, setHistoryOpen] = useState(false);const [encoderInfo, setEncoderInfo] = useState(null);+ const [speakerStatus, setSpeakerStatus] = useState(null);const [generateCopied, setGenerateCopied] = useState(false);- useEffect(() => { api('/encoder-info').then(d => { if (d.best) setEncoderInfo(d); }).catch(() => { }); }, []);+ useEffect(() => {+ api('/encoder-info').then(d => { if (d.best) setEncoderInfo(d); }).catch(() => { });+ api('/speaker-status').then(d => setSpeakerStatus(d)).catch(() => { });+ }, []);// Fetch clip history on mount and after exportsconst fetchHistory = () => { fetch('/api/history?limit=50').then(r => r.json()).then(d => { if (Array.isArray(d)) setClipHistory(d); }).catch(() => { }); };@@ -510,22 +514,56 @@}).catch(() => { });}- let prompt;+ // Ask Claude directly for clip suggestions (same as CLI)+ setPhase('suggesting');+ setGenerateCopied(false);try {- const res = await fetch('/api/generate-prompt', {+ const res = await fetch('/api/claude-suggest', {method: 'POST',headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ action: 'suggest' }),+ body: JSON.stringify({ top_n: 8 }),});const data = await res.json();- prompt = data.prompt || buildLocalPrompt();- } catch {- prompt = buildLocalPrompt();++ if (data.clips && data.clips.length > 0) {+ // Claude returned suggestions — populate directly+ const mapped = data.clips.map((c, i) => ({+ id: `claude-${i}`,+ title: c.title,+ start_second: c.start_second,+ end_second: c.end_second,+ reasoning: c.reasoning || c.content_type || '',+ }));+ setSuggestions(mapped);+ setPhase('review');+ } else if (data.fallback === 'clipboard') {+ // Claude not installed — fall back to clipboard copy+ setPhase('idle');+ setError('Claude Code not found. Install it for automatic clip selection, or use MCP.');+ let prompt;+ try {+ const pRes = await fetch('/api/generate-prompt', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ action: 'suggest' }),+ });+ const pData = await pRes.json();+ prompt = pData.prompt || '';+ } catch { prompt = ''; }+ if (prompt) {+ navigator.clipboard.writeText(prompt).then(() => {+ setGenerateCopied(true);+ setTimeout(() => setGenerateCopied(false), 3000);+ }).catch(() => { });+ }+ } else {+ setPhase('idle');+ setError(data.error || 'Claude returned no clips');+ }+ } catch (err) {+ setPhase('idle');+ setError('Failed to get suggestions: ' + (err.message || err));}- navigator.clipboard.writeText(prompt).then(() => {- setGenerateCopied(true);- setTimeout(() => setGenerateCopied(false), 2000);- }).catch(() => { });};const isProcessing = phase === 'parsing' || phase === 'suggesting' || phase === 'exporting';@@ -564,6 +602,18 @@{encoderInfo.best === 'libx264' ? 'CPU' : encoderInfo.best.replace('h264_', '').toUpperCase()}</span>)}+ {speakerStatus && !speakerStatus.configured && (+ <span className="pill" style={{ fontSize: 10, letterSpacing: '0.5px', background: 'rgba(250,204,21,0.08)', color: '#facc15', border: '1px solid rgba(250,204,21,0.2)', cursor: 'pointer' }}+ title="Speaker detection not configured — click to learn more"+ onClick={() => window.open('https://huggingface.co/pyannote/speaker-diarization-3.1', '_blank')}>+ Speakers ✗+ </span>+ )}+ {speakerStatus && speakerStatus.configured && (+ <span className="pill" style={{ fontSize: 10, letterSpacing: '0.5px', background: 'var(--green-subtle)', color: 'var(--green)', border: '1px solid var(--green-border)' }}>+ Speakers ✓+ </span>+ )}<a href="/knowledge.html" style={{ fontSize: 12, fontWeight: 600, color: 'var(--text2)', textDecoration: 'none', padding: '5px 12px', border: '1px solid var(--border)', borderRadius: 'var(--radius-sm)', transition: 'all 0.15s' }}>Knowledge</a><a href="/integration.html" style={{ fontSize: 12, fontWeight: 600, color: 'var(--text2)', textDecoration: 'none', padding: '5px 12px', border: '1px solid var(--border)', borderRadius: 'var(--radius-sm)', transition: 'all 0.15s' }}>MCP Setup</a></div>@@ -571,6 +621,27 @@<h1>Podcast content studio</h1></div>+ {speakerStatus && !speakerStatus.configured && !sessionStorage.getItem('dismiss-speaker') && (+ <div className="fade-in" style={{ margin: '0 0 16px', padding: '14px 16px', background: 'rgba(250,204,21,0.06)', border: '1px solid rgba(250,204,21,0.15)', borderRadius: 'var(--radius)', display: 'flex', alignItems: 'flex-start', gap: 12 }}>+ <span style={{ fontSize: 18, lineHeight: 1, marginTop: 1 }}>🎙️</span>+ <div style={{ flex: 1 }}>+ <div style={{ fontSize: 13, fontWeight: 700, marginBottom: 4 }}>Set up speaker detection</div>+ <div style={{ fontSize: 12, color: 'var(--text2)', lineHeight: 1.5 }}>+ Identify who's talking in your podcast. Free, takes 2 minutes.+ <br/>+ <span style={{ color: 'var(--text3)' }}>1.</span> <a href="https://huggingface.co/pyannote/speaker-diarization-3.1" target="_blank" rel="noopener" style={{ color: '#facc15', textDecoration: 'none' }}>Accept model terms</a>+ {' → '}+ <span style={{ color: 'var(--text3)' }}>2.</span> <a href="https://huggingface.co/settings/tokens" target="_blank" rel="noopener" style={{ color: '#facc15', textDecoration: 'none' }}>Get free token</a> <span style={{ fontSize: 10, color: 'var(--text3)' }}>(Read permission)</span>+ {' → '}+ <span style={{ color: 'var(--text3)' }}>3.</span> Add <code style={{ fontFamily: 'var(--font-mono)', fontSize: 11, padding: '1px 5px', background: 'rgba(250,204,21,0.1)', borderRadius: 4, color: '#facc15' }}>HF_TOKEN=hf_...</code> to your <code style={{ fontFamily: 'var(--font-mono)', fontSize: 11 }}>.env</code>+ </div>+ </div>+ <button onClick={() => { sessionStorage.setItem('dismiss-speaker', '1'); setSpeakerStatus({...speakerStatus, _dismissed: true}); }}+ style={{ background: 'none', border: 'none', color: 'var(--text3)', cursor: 'pointer', fontSize: 16, padding: 4, lineHeight: 1 }}+ title="Dismiss">✕</button>+ </div>+ )}+<div className="layout">{/* ═══════════ LEFT COLUMN ═══════════ */}<div className="main-col">@@ -724,7 +795,7 @@disabled={!videoPath.trim() || (transcriptMode === 'import' && !transcriptText.trim()) || browsing}onClick={copyGeneratePrompt}style={generateCopied ? { background: 'var(--green)', transition: 'background 0.2s' } : {}}>- {generateCopied ? 'Copied — paste in Claude' : 'Generate Clips'}+ {phase === 'suggesting' ? 'Claude is analyzing...' : generateCopied ? 'Copied — paste in Claude' : 'Find Best Moments'}</button>{videoPath.trim() && (transcriptText.trim() || transcript) && (<McpHints phase={phase} videoPath={videoPath} transcript={transcript} transcriptText={transcriptText} suggestions={suggestions} mcpConnected={mcpConnected} />diff --git a/src/ui/web-server.ts b/src/ui/web-server.tsindex 4cf4754..50e54d7 100644--- a/src/ui/web-server.ts+++ b/src/ui/web-server.ts@@ -13,7 +13,8 @@ import express from "express";import multer from "multer";import { createReadStream, existsSync, statSync, readFileSync, writeFileSync } from "fs";import { mkdir, readdir, unlink } from "fs/promises";-import { join, dirname, basename, extname } from "path";+import path from "path";+import { join, dirname, basename, extname, resolve } from "path";import { execSync } from "child_process";import { fileURLToPath } from "url";import { v4 as uuidv4 } from "uuid";@@ -38,6 +39,13 @@ const assetManager = new AssetManager();const clipsHistory = new ClipsHistory();const knowledgeBase = new KnowledgeBase();+// --- Path Traversal Protection ---+function safePath(base: string, filename: string): string | null {+ const resolved = path.resolve(base, filename);+ if (!resolved.startsWith(path.resolve(base))) return null;+ return resolved;+}+// --- State ---// Track active jobs so the UI can poll progressinterface JobState {@@ -693,7 +701,11 @@ app.get("/api/outputs", async (_req, res) => {* GET /api/download/:filename — Download a finished clip*/app.get("/api/download/:filename", (req, res) => {- const filePath = join(paths.output, req.params.filename);+ const filePath = safePath(paths.output, req.params.filename);+ if (!filePath) {+ res.status(400).json({ error: "Invalid filename" });+ return;+ }if (!existsSync(filePath)) {res.status(404).json({ error: "File not found" });return;@@ -705,7 +717,11 @@ app.get("/api/download/:filename", (req, res) => {* GET /api/preview/:filename — Stream a video clip for in-browser playback*/app.get("/api/preview/:filename", (req, res) => {- const filePath = join(paths.output, req.params.filename);+ const filePath = safePath(paths.output, req.params.filename);+ if (!filePath) {+ res.status(400).json({ error: "Invalid filename" });+ return;+ }if (!existsSync(filePath)) {res.status(404).json({ error: "File not found" });return;@@ -748,6 +764,14 @@ app.get("/api/stream-source", (req, res) => {res.status(404).json({ error: "File not found" });return;}+ // Validate the path is the current session video or within the uploads directory+ const resolvedPath = path.resolve(filePath);+ const isSessionVideo = uiState.videoPath && resolvedPath === path.resolve(uiState.videoPath);+ const isUploadedFile = resolvedPath.startsWith(path.resolve(join(paths.working, "uploads")));+ if (!isSessionVideo && !isUploadedFile) {+ res.status(403).json({ error: "Access denied: path not in allowed directories" });+ return;+ }const stat = statSync(filePath);const fileSize = stat.size;@@ -859,12 +883,12 @@ app.get("/api/export-transcript", (_req, res) => {// --- Analyze audio energy ---app.post("/api/analyze-energy", async (req, res) => {const { video_path, segments } = req.body;- if (!video_path) return res.json({ error: "video_path required" });+ if (!video_path) return res.status(400).json({ error: "video_path required" });try {const result = await executor.execute("analyze_energy", { video_path, segments: segments || [] });res.json(result.data || {});} catch (err: any) {- res.json({ error: err.message });+ res.status(500).json({ error: err.message });}});@@ -874,17 +898,33 @@ app.get("/api/encoder-info", async (_req, res) => {const result = await executor.execute("detect_encoder", {});res.json(result.data || {});} catch (err: any) {- res.json({ error: err.message });+ res.status(500).json({ error: err.message });}});+// --- Speaker Detection Status ---+app.get("/api/speaker-status", (_req, res) => {+ const envPath = join(process.cwd(), ".env");+ let token = process.env.HF_TOKEN || "";+ if (!token && existsSync(envPath)) {+ const envContent = readFileSync(envPath, "utf-8");+ const match = envContent.match(/^HF_TOKEN=(.+)$/m);+ if (match) token = match[1].trim();+ }+ res.json({+ configured: !!token,+ setup_url: "https://huggingface.co/pyannote/speaker-diarization-3.1",+ token_url: "https://huggingface.co/settings/tokens",+ });+});+// --- Presets ---app.get("/api/presets", async (_req, res) => {try {const result = await executor.execute("presets", { action: "list" });res.json(result.data || { presets: [] });} catch (err: any) {- res.json({ error: err.message });+ res.status(500).json({ error: err.message });}});@@ -894,7 +934,7 @@ app.post("/api/presets", async (req, res) => {const result = await executor.execute("presets", { action, name, config });res.json(result.data || {});} catch (err: any) {- res.json({ error: err.message });+ res.status(500).json({ error: err.message });}});@@ -904,7 +944,7 @@ app.get("/api/assets", async (req, res) => {const items = await assetManager.list(req.query.type as string | undefined);res.json(items);} catch (err: any) {- res.json({ error: err.message });+ res.status(500).json({ error: err.message });}});@@ -923,7 +963,7 @@ app.post("/api/assets/unregister", async (req, res) => {await assetManager.unregister(req.body.name);res.json({ ok: true });} catch (err: any) {- res.json({ error: err.message });+ res.status(400).json({ error: err.message });}});@@ -1003,6 +1043,10 @@ app.post("/api/knowledge/upload", knowledgeUpload.array("files", 50), (req, res)});app.get("/api/knowledge/:filename", async (req, res) => {+ if (!safePath(paths.knowledge, req.params.filename)) {+ res.status(400).json({ error: "Invalid filename" });+ return;+ }try {const content = await knowledgeBase.readFile(req.params.filename);res.json({ filename: req.params.filename, content });@@ -1012,6 +1056,10 @@ app.get("/api/knowledge/:filename", async (req, res) => {});app.post("/api/knowledge/:filename", async (req, res) => {+ if (!safePath(paths.knowledge, req.params.filename)) {+ res.status(400).json({ error: "Invalid filename" });+ return;+ }try {await knowledgeBase.writeFile(req.params.filename, req.body.content);res.json({ ok: true, filename: req.params.filename });@@ -1021,11 +1069,15 @@ app.post("/api/knowledge/:filename", async (req, res) => {});app.delete("/api/knowledge/:filename", async (req, res) => {+ if (!safePath(paths.knowledge, req.params.filename)) {+ res.status(400).json({ error: "Invalid filename" });+ return;+ }try {await knowledgeBase.deleteFile(req.params.filename);res.json({ ok: true });} catch (err: any) {- res.json({ error: err.message });+ res.status(500).json({ error: err.message });}});@@ -1145,6 +1197,135 @@ app.post("/api/generate-prompt", (req, res) => {res.json({ prompt, action, context: ctx });});+// --- Claude-powered clip suggestion (same as CLI) ---++app.post("/api/claude-suggest", async (req, res) => {+ const { top_n = 5 } = req.body;++ // Find claude binary+ const homedir = require("os").homedir();+ const claudeCandidates = [+ join(homedir, ".local", "bin", "claude"),+ "/usr/local/bin/claude",+ "/opt/homebrew/bin/claude",+ ];+ const claudePath = claudeCandidates.find((p) => existsSync(p));++ if (!claudePath) {+ res.json({+ error: "Claude Code not found",+ message: "Install Claude Code: https://docs.anthropic.com/en/docs/claude-code",+ fallback: "clipboard",+ clips: [],+ });+ return;+ }++ // Need transcript in state+ if (!uiState.transcript && !uiState.rawTranscriptText) {+ res.status(400).json({ error: "No transcript loaded. Transcribe or import one first." });+ return;+ }++ // Build transcript text from state+ let transcriptText = "";+ const segs = (uiState.transcript as any)?.segments;+ if (segs && Array.isArray(segs)) {+ transcriptText = segs+ .map((s: any) => {+ const sp = s.speaker ? `[${s.speaker}] ` : "";+ const mins = Math.floor(s.start / 60);+ const secs = Math.floor(s.start % 60);+ return `(${mins}:${String(secs).padStart(2, "0")}) ${sp}${s.text}`;+ })+ .join("\n");+ } else if (uiState.rawTranscriptText) {+ transcriptText = uiState.rawTranscriptText as string;+ }++ const segCount = segs?.length || 0;+ const dur = (uiState.transcript as any)?.duration || 0;+ const durationMin = Math.round(dur / 60);++ const prompt = `You are the clip extraction engine for a podcast. Analyze this transcript and return the ${top_n} best moments for YouTube Shorts.++IMPORTANT: Return ONLY valid JSON. No markdown, no explanation, no code fences.++Use the knowledge base in .podcli/knowledge/ for voice rules, moment selection criteria, content types, and existing episodes.++Score each moment on 4 dimensions (1-5 each):+- standalone: Makes sense without episode context?+- hook: Grabs attention in first 3 seconds?+- relevance: Matters to target audience?+- quotability: Memorable, shareable phrasing?++Classify each as: guest_story | technical_insight | market_landscape | business_strategy | hot_take++Return JSON: { "clips": [{ "title": "...", "start_second": N, "end_second": N, "duration": N, "content_type": "...", "scores": {"standalone":N,"hook":N,"relevance":N,"quotability":N}, "total_score": N, "quote": "...", "why": "..." }] }++Rules: 20-90 seconds, sentence boundaries, standalone, variety.++Transcript (${segCount} segments, ~${durationMin} min):++${transcriptText}`;++ // Write prompt to temp file+ const tmpFile = join(process.cwd(), `.tmp-claude-prompt-${Date.now()}.txt`);+ writeFileSync(tmpFile, prompt);++ try {+ const { execSync } = require("child_process");+ const result = execSync(+ `cat "${tmpFile}" | "${claudePath}" --print -p -`,+ {+ cwd: process.cwd(),+ timeout: 300_000,+ maxBuffer: 10 * 1024 * 1024,+ encoding: "utf-8",+ }+ );++ // Parse JSON from response+ const jsonStart = result.indexOf("{");+ const jsonEnd = result.lastIndexOf("}") + 1;+ if (jsonStart < 0 || jsonEnd <= jsonStart) {+ res.status(500).json({ error: "Claude did not return valid JSON" });+ return;+ }++ const data = JSON.parse(result.substring(jsonStart, jsonEnd));+ const clips = (data.clips || []).map((c: any) => ({+ title: c.title || "Untitled",+ start_second: c.start_second || 0,+ end_second: c.end_second || 0,+ duration: c.duration || 0,+ reasoning: c.why || "",+ content_type: c.content_type || "unknown",+ scores: c.scores || {},+ total_score: c.total_score || 0,+ }));++ // Auto-push to UI state as suggestions+ if (clips.length > 0) {+ (uiState as any).suggestions = clips.map((c: any, i: number) => ({+ id: `claude-${i}`,+ title: c.title,+ start_second: c.start_second,+ end_second: c.end_second,+ reasoning: c.reasoning,+ }));+ (uiState as any).phase = "review";+ broadcastSSE("state-sync", uiState);+ }++ res.json({ clips, source: "claude" });+ } catch (err: any) {+ res.status(500).json({ error: `Claude failed: ${err.message?.substring(0, 200)}` });+ } finally {+ try { require("fs").unlinkSync(tmpFile); } catch {}+ }+});+// --- MCP ↔ UI Bridge Endpoints ---/**