Repository navigation
download_audio_bounded: link-to-audio with the safety policy once - #48
Merged
Merged
Conversation
thorwhalen
force-pushed
the
audio-bounded-44
branch
from
October 27, 2026 01:10
ca3ce29 to
9cff9d5
Compare
This was referenced Oct 27, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #44 (the yb side; braidio/reelee/muvid callers are follow-ups in their repos).
yb.download.download_audio_bounded(url, *, download_dir, max_bytes=80MiB, max_duration_s=45min, validate_target=require_http_url, extra_opts=None, cookies_file=None, notice=COPYRIGHT_NOTICE) -> AudioDownload(path, title, duration_s, notice, info).Policy once: target check before any network (also on the resolved page URL); metadata preview refuses playlists, live streams and over-long sources before any media bytes; caps pinned (
max_filesize,noplaylist,playlist_items=1,match_filterduration/live, mp3 extractor);extra_optsrestricted to an allowlistDEPLOYMENT_OPT_KEYS(cookies, headers, proxy, credentials, extractor args), anything else raises, so no option can widen a cap or redirect output; extracted-size check; each call writes into its own private directory (no collisions), removed on any failure;AudioLimitErrorfor refusals.Adversarial review (Opus, two rounds). Round 1 found: playlist URL bypassing both caps, live/unknown-duration unbounded, "can't widen" only true for two keys, files left on failure, default byte cap below the duration cap's mp3 size, resolved URL not validated. All fixed (allowlist, pinned opts, preview refusal, temp dir, 80 MiB default, tests on the real options). Round 2 found a blocker my fakes could not see:
max_downloads=1makes yt-dlp raise after the first success; removed, and a test now runs real yt-dlp + ffmpeg against a local HTTP file (skipped without ffmpeg). Also fixed: silent overwrite on same-video calls (per-call dir), misleading ffmpeg-failure message. Left as documented limits: validate_target is not an egress sandbox (yt-dlp follows redirects); unknown duration is bounded by bytes only. yt-dlp added to thedevextra so the option tests run.Verified live here: duration cap against real YouTube metadata; the media fetch from this server's IP is 403-gated (cookies seam), so end-to-end is covered by the local-server test.
Mapping for braidio: keeps
creds.check()and error mapping, passescreds.optsasextra_opts(must be within the allowlist) and its SSRF check asvalidate_target, ingestsresult.paththen removespath.parent.