🐛 Fix YouTube streaming black screen by passing HTTP headers to VLC#251
Open
WilliamTahar wants to merge 2 commits intojeffshee:masterfrom
Open
🐛 Fix YouTube streaming black screen by passing HTTP headers to VLC#251WilliamTahar wants to merge 2 commits intojeffshee:masterfrom
WilliamTahar wants to merge 2 commits intojeffshee:masterfrom
Conversation
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.
Summary
YouTube streaming mode (
MODE_STREAM) currently results in a black screen because VLC does not send the HTTP headers required by YouTube (notablyUser-AgentandReferer). This PR extracts HTTP headers from yt-dlp and forwards them to VLC using its native media options, restoring YouTube stream playback.This addresses the issues reported in #196, #166, and #214 where users experience black screens or broken streaming when using YouTube URLs.
Problem
When a user sets a YouTube URL in streaming mode, the following happens:
yt-dlpcorrectly extracts the direct video/audio stream URLs along with HTTP headersyt_utils.pydiscards these headers and only returns the raw URLsvideo_player.pypasses the bare URLs to VLC without any HTTP headersUser-Agent/Referer), resulting in a black screenThis issue has become more prominent as YouTube has tightened its request validation in recent months.
Changes
src/yt_utils.pyyt-dlpinfo dict and individual format entriesUser-Agentis always present (YouTube blocks requests without one)Refereris set to the source URL (YouTube validates this)get_best_audio()(now returns(url, headers)) andget_optimal_video()(now returns(url, width, height, headers))ValueErrorwhen no audio or video format is found, instead of failing silentlysrc/player/video_player.pymedia_new(): PassUser-AgentandRefererto VLC via native options (:http-user-agent,:http-referrer)add_audio_track(): Apply headers to the player's media for the audio slave track. Also fixes passing a URL string (not aMediaobject) toadd_slave(), which previously caused actypes.ArgumentErrorMODE_STREAMblock: Receive and forward headers fromyt_utils, add:network-caching=3000for smoother streaming, add info/debug logging for stream URLs and headers, wrap in try/except with detailed error loggingBackward compatibility
MODE_VIDEO) is completely unaffected —http_headersdefaults toNoneand all existing code paths remain unchangedMODE_WEBPAGE) is untouchedyt_utils.pyonly affect callers insidevideo_player.py'sMODE_STREAMblock, which is updated accordinglyTesting
Tested manually on Kubuntu (KDE, Wayland via XWayland, Intel GPU):
Note on yt-dlp version
Users running an older yt-dlp (< 2025.10) may still experience issues due to YouTube's SABR streaming protocol changes (see yt-dlp#12482). Updating yt-dlp to the latest version is recommended. This is independent of this PR but worth noting in documentation or release notes.