Skip to content

OpenRouter support, chunking, cost tracking, and domain modes (curated from PR #3) - #4

Draft
UditAkhourii wants to merge 3 commits into
mainfrom
claude/pr-review-szfv12
Draft

UditAkhourii wants to merge 3 commits into
mainfrom
claude/pr-review-szfv12

Conversation

@UditAkhourii

@UditAkhourii UditAkhourii commented Aug 28, 2026 •

Copy link
Copy Markdown
Owner

This is a curated version of #3 (by @sagniKdas53). It keeps the genuinely useful features, removes the problematic material, and fixes the confirmed bugs. All 74 tests pass locally on Python 3.10 install of ./cli[test], including the repo's original suites that #3 broke.

✅ What was kept (the good parts, credited to the original author)

  • OpenRouter multi-model provider — --provider openrouter / auto-detection via OPENROUTER_API_KEY, native video upload for Gemini models, frame-sampling fallback for image-vision models (Qwen VL, Pixtral, Llama 3.2 Vision, GPT-4o), stdlib urllib fallback when requests isn't installed. Endpoints verified clean: keys go only to openrouter.ai (overridable via OPENROUTER_BASE_URL) or the Google GenAI SDK.
  • Temporal chunking & parallel processing — --chunk-duration N --parallel M for long videos, with per-chunk timestamp offsetting and section-aware merging.
  • Per-asset cost & token tracking — cost:, prompt_tokens:, output_tokens: sidecar headers.
  • Domain modes — --mode screencast|meeting|demo|presentation prompt tuning, ## Environment & Tools / ## Meeting Details / ## Action Items & Decisions sections, SPEC/SKILL updates.
  • Model alias table and cdaf models command — including the Gemini 3.7 Flash and Qwen 3.x flash aliases from the original PR (see correction below) — plus probe_duration_seconds() and the new test suite.

🗑️ What was stripped, and why

  1. Undisclosed NSFW mode. PR This PR extends CDAF with multi-model OpenRouter support, parallelized temporal chunking for long/large video assets, automated generation cost tracking, and intelligent domain modes for screencasts, meetings, and product demos. #3's description never mentioned it, but the diff added an "Adult & NSFW Curation Mode" to the README, normative adult-indexing MUSTs to SPEC.md §2.5, nsfw-* model aliases, an nsfw: header key, and an --nsfw flag that set BLOCK_NONE on all four Gemini safety categories (dangerous content, hate speech, and harassment included). Routing "uncensored" traffic through Gemini with all filters off likely violates Google's Generative AI Prohibited Use Policy and risks the user's API account. Removed entirely; if wanted, it should be its own explicitly-scoped proposal.
  2. Nonexistent model IDs ✏️ CORRECTION (retracted). The original review flagged gemini-3.7-flash, google/gemini-3.7-flash, qwen/qwen3.8-flash, and qwen/qwen3.5-flash-02-23 as nonexistent. That was wrong — the review was made against stale (pre-August-2026) model knowledge. All four are real: Gemini 3.7 Flash went GA on the Gemini API on 2026-08-13 and is live on OpenRouter, and both Qwen flash models are listed on OpenRouter. The original PR's aliases (flash-3.7, gemini-3.7, or-flash-3.7, qwen3) and pricing have been restored with published rates, and flash-3.7 is back as the top cdaf models recommendation. The one model-ID fix retained is the Qwen 2.5 VL OpenRouter slug (qwen/qwen-2.5-vl-72b-instruct → qwen/qwen2.5-vl-72b-instruct). Apologies to @sagniKdas53 for the wrong call here.
  3. Import-time .env sweep. Merely importing cdaf.generate read and injected every key from .env files in the CWD, inside site-packages, and ~/.env — so a forgotten key in an unrelated file could be silently picked up and spent. Now: CWD .env only, loaded by the CLI (not at import), and existing env vars always win.
  4. Whole-video base64 fallback. With ffmpeg absent, the frame extractor "fell back" to base64-encoding the entire raw video in memory and attaching it as an image_url — an OOM/garbage-request path that existed only to make the PR's own mocked tests pass. Replaced with a clear error, plus a 45 MB guard on inline OpenRouter uploads.
  5. .gitignore tests/ entry — unanchored, it would have silently untracked any future test file (including cli/tests/). Removed; the video-extension ignores were kept.

🐛 Bugs in #3 that are fixed here

  • CI was red on This PR extends CDAF with multi-model OpenRouter support, parallelized temporal chunking for long/large video assets, automated generation cost tracking, and intelligent domain modes for screencasts, meetings, and product demos. #3 (6 failures): the new tests needed requests, which CI never installed, and two existing test_local.py tests asserting the old provider tuple/error message were never updated. Fixed: CI installs ./cli[test], test_local.py updated, and the pytest→unittest rewrite of test_sidecar.py reverted. A further Windows-only failure (tempfile.NamedTemporaryFile keeps the file locked, breaking _video_data_url's re-open) is fixed with a TemporaryDirectory-based fixture.
  • Multi-timestamp corruption: offset_body_timestamps replaced every timestamp on a line with the first match's offset values ([00:10.0-00:20.0] A then [00:30.0-00:40.0] B → both ranges became [01:50.0-02:00.0]). Each match is now offset individually; regression tests added.
  • Invalid timestamps at minute boundaries: format_timestamp(59.96) produced 00:60.0 and never rolled into hours, so chunked videos over an hour mixed MM:SS.d and HH:MM:SS.d styles. Fixed with tenths-first rounding and a use_hours flag threaded through the chunk path; regression tests added.
  • Unhandled network errors: requests timeouts/connection failures escaped as raw tracebacks, crashing cdaf generate mid-batch. Now wrapped in GenerationError so the batch loop prints FAILED <video> and continues.
  • ffmpeg portability & quality: chunk cutting used input-side -to (ffmpeg ≥ 4.0 only) — now portable -ss/-t; Gemini chunks no longer get crushed to 640p/5fps (which destroyed the on-screen text that --mode screencast exists to capture); sub-second trailing chunks from probe rounding noise fold into the previous chunk instead of failing the whole video.
  • Removed features restored: This PR extends CDAF with multi-model OpenRouter support, parallelized temporal chunking for long/large video assets, automated generation cost tracking, and intelligent domain modes for screencasts, meetings, and product demos. #3 deleted cdaf --version (which CI's smoke check runs!) and the _iter_videos warnings for skipped/invalid paths. Both restored.
  • Cost honesty: unknown models now omit the cost: header instead of inventing a $0.20/$0.80 price; rates use published pricing, with the table documented as approximate.

⚠️ Known limitations (inherited, documented rather than fixed)

  • merge_chunk_bodies concatenates chunk summaries rather than synthesizing one (N chunks → N paragraphs under ## Summary).
  • Gemini cost estimates count candidates_token_count only (thinking tokens excluded), so cost: can underestimate.
  • MODEL_PRICING is a static table and will drift (e.g. Gemini 3.7 Flash's current rates are promotional through 2026-12-31).

Test Plan

Supersedes #3.

🤖 Generated with Claude Code

https://claude.ai/code/session_011jFGsfg58qPVdiSnwmWWXZ

claude and others added 2 commits August 28, 2026 04:01
…rated from PR #3)

Curated version of PR #3 by @sagniKdas53: keeps the OpenRouter
multi-model provider, temporal chunking with parallel workers,
per-asset cost/token tracking, and screencast/meeting/demo/presentation
domain modes.

Removed from the original PR:
- The undisclosed NSFW mode (--nsfw flag, Gemini BLOCK_NONE safety
  overrides, nsfw-* aliases, README/SPEC/SKILL adult-curation sections)
- Nonexistent model IDs (gemini-3.7-flash, qwen/qwen3.8-flash,
  qwen/qwen3.5-flash-02-23) and their invented pricing entries
- The import-time .env sweep of ~/.env and site-packages directories
  (now CWD-only, invoked by the CLI, existing env vars win)
- The no-ffmpeg fallback that base64-encoded whole videos into an
  image_url part (replaced with a clear error and a 45 MB upload guard)
- The unanchored tests/ .gitignore entry

Fixed relative to the original PR:
- offset_body_timestamps overwrote every timestamp on a line with the
  first match's values; each match is now offset individually
- format_timestamp emitted invalid values like 00:60.0 at minute
  boundaries and never rolled into hours; chunked >1h videos now use
  HH:MM:SS.d consistently
- requests network errors (timeouts, connection failures) now raise
  GenerationError instead of crashing the CLI mid-batch
- ffmpeg chunk cutting uses portable -ss/-t instead of input-side -to;
  Gemini chunks keep original resolution instead of 640p/5fps
- Sub-second trailing chunks fold into the previous chunk
- cdaf --version and _iter_videos warnings restored (the PR deleted
  both; CI's smoke check runs cdaf --version)
- test_local.py updated for the new provider tuple; test_sidecar.py
  restored to the repo's pytest style; CI installs the test extra so
  requests is available
- Unknown models now omit the cost header instead of inventing a price;
  Gemini pricing corrected to published rates

Co-authored-by: sagniKdas53 <40667155+sagniKdas53@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011jFGsfg58qPVdiSnwmWWXZ
tempfile.NamedTemporaryFile keeps the file handle exclusively locked on
Windows, so _video_data_url's re-open failed with PermissionError in the
six tests that pass a temp video to the OpenRouter path. Write the fixture
into a TemporaryDirectory instead, via a shared temp_video() helper.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011jFGsfg58qPVdiSnwmWWXZ
The earlier review flagged gemini-3.7-flash, google/gemini-3.7-flash,
qwen/qwen3.8-flash, and qwen/qwen3.5-flash-02-23 as nonexistent. That
was wrong: all four shipped in August 2026 and are live on the Gemini
API and OpenRouter (verified against both providers' listings). Restore
the flash-3.7 / gemini-3.7 / or-flash-3.7 / qwen3 aliases, add the
published pricing, and put Gemini 3.7 Flash back as the top
recommendation in cdaf models.

The only model-ID change kept from the curation pass is the Qwen 2.5 VL
OpenRouter slug fix (qwen/qwen-2.5-vl-72b-instruct ->
qwen/qwen2.5-vl-72b-instruct).

Co-authored-by: sagniKdas53 <40667155+sagniKdas53@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011jFGsfg58qPVdiSnwmWWXZ
sagniKdas53 added a commit to sagniKdas53/cdaf that referenced this pull request Aug 28, 2026
- Remove all NSFW references (--nsfw flag, nsfw-* aliases, BLOCK_NONE,
  nsfw: header, SPEC §2.5, README/SKILL adult sections) per maintainer
  request; original author may re-propose separately
- Port pricing autosync from sagniKdas53/manga-tl-worker
  (OpenRouter endpoints API, 7-day file cache ~/.cache/cdaf/pricing.json)
  via cli/cdaf/pricing.py; cdaf models --refresh
- Add user-friendly searchable DB: cdaf index ./footage -> cdaf-index.json/.db
  (FTS5) and cdaf search <query> ./footage (offline, no API key)
- Fix chunking, timestamp, dotenv, ffmpeg, cost honesty per PR UditAkhourii#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants