Skip to content

fix: YouTube 403 — retry on soft block + skip removed progressive formats - #196

Merged
firsttris merged 3 commits into
firsttris:masterfrom
zibaone:master
Oct 20, 2026
Merged

firsttris merged 3 commits into
firsttris:masterfrom
zibaone:master

Conversation

@zibaone

@zibaone zibaone commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

YouTube playback in SendToKodi failed intermittently with HTTP 403. Two
contributing causes were identified:

  1. Removed progressive formats: YouTube has removed progressive (muxed)
    formats (itag 18/22) for many videos. SendToKodi fell back to
    raw format 18, whose URL no longer exists → immediate 403.

  2. CDN soft block on fresh URLs: YouTube applies a short soft block
    (HTTP 403, ~5-8 s) on freshly generated googlevideo.com/videoplayback
    URLs. The DASH builder probes URLs immediately after extraction, landing
    inside that window → manifest build fails. A Kodi restart added enough delay
    for the URL to warm up, which is why the issue appeared intermittent.

Both are addressed by this PR.

Changes

  1. core/dash_builder.py — _fetch_range now retries on HTTP 403 with
    backoff (3 s, 6 s, 9 s, 3 attempts). Other HTTP errors are re-raised
    immediately. This absorbs the soft block for both the init/index range probe
    and subsequent segment fetches.

  2. core/playback_selection.py — evaluate_raw_format_candidate skips
    progressive (muxed) formats (itag 18/22) when DASH streams are available,
    since YouTube has removed those formats for many videos.

  3. Tests — added coverage for the retry-on-403 path (success after retry,
    immediate propagation of non-403 errors) and for the progressive-format skip.

Test plan

  • pytest — 344 passed, 1 skipped (no regressions)
  • Manual: 6 consecutive YouTube playbacks over ~18 h (including cold URLs after expiry) — 0 errors 403 in log. Patch active and working.
  • Manual: replay after URL expiry (~6 h) — cold-URL case passed (playback at 02:11, ~18 h after deploy, no 403).

YouTube applies a short soft block (~5-8s, HTTP 403) on freshly generated
googlevideo URLs. The DASH builder probes URLs immediately after extraction,
landing inside that window and failing the whole manifest build.

_fetch_range now retries up to 3 times with backoff (3s, 6s, 9s) on 403,
while other HTTP errors are re-raised immediately.
YouTube has removed progressive (muxed) formats for many videos, so falling
back to raw format 18/22 often hits a dead URL. When DASH streams are
available, skip those progressive formats in the raw-format fallback.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.45%. Comparing base (4aa2a6e) to head (1e61f82).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
core/dash_builder.py 87.09% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #196      +/-   ##
==========================================
- Coverage   84.48%   84.45%   -0.03%     
==========================================
  Files          14       14              
  Lines        2591     2612      +21     
==========================================
+ Hits         2189     2206      +17     
- Misses        402      406       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@firsttris
firsttris merged commit 480c7db into firsttris:master Oct 20, 2026
2 checks passed

Copy link
Copy Markdown
Owner

Thanks a lot for tracking this down, @zibaone, and for the detailed analysis and the long-running manual test! 🙏

Merged. I added a small follow-up on top in #197:

  • 403 retry: _fetch_range now retries only on HTTP 403 and waits 3 s, then 6 s (the third delay was never reached). The other error paths stay as they were. Note: the retry covers the init/index range probe when the manifest is built. The media segments themselves are fetched by inputstream.adaptive directly from googlevideo, not through our server.
  • Skipping itag 18/22: now limited to YouTube results, and only when the DASH builder can actually play the video (DASH builder enabled and ISA supports mpd). Users without the DASH builder or inputstream.adaptive keep the muxed fallback, and other sites that use numeric format ids like "18"/"22" are no longer affected.
  • Added tests for a persistent 403 and for the narrower 18/22 skip.

Thanks again for the contribution!


Generated by Claude Code

@zibaone

zibaone commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging our PR so quick, and for your SponsorBlock feature — great addition! 🙏

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.

3 participants