Skip to content

feat(transcribe): opt-in HuntAPI backend for URL audio downloads - #5801

Open
josselinlbe wants to merge 2 commits into
Graphify-Labs:v8from
huntapi:feat/huntapi-audio-backend
Open

josselinlbe wants to merge 2 commits into
Graphify-Labs:v8from
huntapi:feat/huntapi-audio-backend

Conversation

@josselinlbe

@josselinlbe josselinlbe commented Dec 5, 2026 •

Copy link
Copy Markdown

What does this PR do?

Adds an opt-in download backend for graphify add <youtube-url> and video URL transcription, for the case described in #3049: on datacenter and VPS IPs, YouTube answers every yt-dlp request with "Sign in to confirm you're not a bot", so download_audio() cannot get the audio at all.

When HUNTAPI_API_KEY is set, download_audio() sends the URL to HuntAPI, a hosted media download API that handles that wall. It waits for the job, then streams the finished audio file into the same yt_<hash>.<ext> path yt-dlp would have used. Without the variable, nothing changes.

  • No new dependency: stdlib urllib through graphify.security._build_opener() (SSRF guard, redirect re-validation), plus validate_url() on the returned file URL.
  • The key is sent only in the x-api-key header to api.huntapi.com. It is never sent to the file host and never appears in errors.
  • The download streams to a .part file with a 500 MB cap, then an atomic rename. Nothing is left behind on failure.
  • The existing cache check now runs before the yt-dlp import. A cached file is reused with either backend, and the HuntAPI path does not need the video extra to download (Whisper still does).
  • GRAPHIFY_HUNTAPI_TIMEOUT (seconds, default 900) bounds the wait, following the module's GRAPHIFY_WHISPER_* env convention.
  • Errors (bad key, no credits, private or unavailable video, timeout) raise RuntimeError with the API's message. ingest() and transcribe_all() already report those.

This complements #3050 (cookie pass-through for yt-dlp) and does not conflict with it. Cookies help when you have a logged-in browser export; this helps on servers where you don't.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

  • Without HUNTAPI_API_KEY, the yt-dlp path is byte-for-byte the same call as before (test_without_key_yt_dlp_is_used).

  • URL validation still runs first. The file URL returned by the API goes through validate_url(), so a private or metadata address is refused (test_file_url_on_private_host_is_blocked).

  • The cache path and file naming are unchanged, so previously downloaded audio is still found.

  • No extraction output changes, so no cache schema bump.

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test (if bug fix) or isolated boundary test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

Limitations: HuntAPI is a paid service; the backend is only used when the user sets the key. The generated skill references are not touched; the README's video extra row mentions the variable.

How was this tested?

uv run pytest tests/test_transcribe_huntapi.py tests/test_transcribe.py tests/test_ingest.py tests/test_ingest_url_type.py -q
uv run pytest tests -q
uv run ruff check .
uv run pyright graphify/transcribe.py tests/test_transcribe_huntapi.py

Full suite: 12525 passed. The 20 failures (test_export.py, test_export_svg_malformed.py, test_ext_tagged_id_clash.py, test_multilang.py, test_pascal_singleton_resolution.py) and the test_serve_reload_off_loop.py collection error (no anyio without the mcp extra) are identical on a clean v8 checkout in the same environment.

tests/test_transcribe_huntapi.py (16 tests) fakes the opener, so no network is used and HUNTAPI_API_KEY / GRAPHIFY_HUNTAPI_TIMEOUT are cleared for every test. The new tests fail on v8 without the change.

Live check with a real key: graphify.ingest.ingest("https://www.youtube.com/watch?v=Z5YP8kznWZs", ...) went through one HuntAPI job (Running, then completed) and saved yt_a2690cf3f7c0.mp3 (20 MB, MP3 header checked). A second call returned the cached file without a new job.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

Refs #3049.

On datacenter and VPS IPs YouTube answers every yt-dlp request with
"Sign in to confirm you're not a bot", so download_audio() cannot fetch
audio for `graphify add <youtube-url>` there (Graphify-Labs#3049).

When HUNTAPI_API_KEY is set, download_audio() submits the URL to HuntAPI,
polls the job (GRAPHIFY_HUNTAPI_TIMEOUT, default 900s) and streams the
finished file into the same yt_<hash>.<ext> path, size-capped and through
the SSRF-guarded opener. Without the variable the yt-dlp path is unchanged.
The cache check now runs before the yt-dlp import.

Refs Graphify-Labs#3049

Co-Authored-By: Claude <noreply@anthropic.com>

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

When HUNTAPI_API_KEY is set, URL audio downloads use HuntAPI jobs and save the returned audio locally.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • 2 of 2 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 428 functions depend on this change
  • 2 functions became more coupled. download_audio() (11 callers), _huntapi_save() (3 callers).
  • 693 of 693 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 6d5e7b3 · 1 of 1 earlier findings resolved

Comment thread graphify/transcribe.py Resolved
nan or inf made the job-polling deadline never expire.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant