fix: live stream HTTP 400 and missing title/author metadata#215
Open
Wubbity wants to merge 1 commit into
Open
Conversation
Two separate bugs fixed in this commit:
1. YoutubeMpegStreamAudioTrack - HTTP 400 on live stream initialization
updateGlobalSequence() fetches the current segment to read the
sequence number. YoutubePersistentHttpStream appends a range header
(&range=0-N) to any URL that does not already contain an "rn="
parameter. Live broadcast URLs (noclen=1, live=1) reject range
requests with HTTP 400.
Fix: when trackInfo.isStream is true, append rn=0 to the URL before
passing it to YoutubePersistentHttpStream. The stream class treats
any URL that already has rn= as a segmented request and skips the
range logic entirely, so the fetch completes without a 400.
Also removes the per-segment debug log that fires every few seconds
for the duration of a live stream, replacing it with a single INFO
line when playback begins.
2. NonMusicClient - missing title/author for TVHTML5 + OAuth responses
When loading login-required content via the TV client with OAuth,
the InnerTube player response omits videoDetails.title and
videoDetails.author. The original code read these fields directly
and fell back only to logging "Unknown artist" when author was null.
Fix cascade (in order):
- videoDetails.title as plain text (existing behaviour)
- videoDetails.title.simpleText (structured text node)
- videoDetails.title.runs[0].text (rich text node)
- microformat.playerMicroformatRenderer.title.simpleText (TV client)
- microformat.microformatDataRenderer.title (web clients)
- microformat.playerMicroformatRenderer.ownerChannelName (TV author)
- microformat.microformatDataRenderer.pageOwnerDetails.name (web author)
- YouTube oEmbed endpoint as final fallback - returns title and
author_name for any public video without authentication. Only
called when at least one of the two fields is still null after
all InnerTube paths have been exhausted.
Author
|
Closing to revise before re-submitting. |
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.
EDIT: Apologies to Devoxin, I accidentally deleted the repo I was working in which subsequently closed the PR. I've addressed your concerns and reopened it.
Summary
Two bugs that surface specifically with live streams and login-required content.
1. HTTP 400 when initializing live stream playback
File:
YoutubeMpegStreamAudioTrack.javaupdateGlobalSequence()fetches the current segment on stream start to read the sequence number.YoutubePersistentHttpStreamappends a&range=0-Nquery parameter to any URL that does not already contain anrn=parameter.Live broadcast URLs carry
noclen=1andlive=1. YouTube's live segment servers reject HTTP range requests with HTTP 400, soupdateGlobalSequence()always fails for live streams and sequence tracking is broken.Fix: when
trackInfo.isStreamis true, appendrn=0to the URL before passing it toYoutubePersistentHttpStream. The stream class skips the range logic for any URL that already containsrn=, so the request goes through as a plain fetch and returns HTTP 200.A per-segment
log.debugthat fires every few seconds for the lifetime of any live stream is also removed and replaced with a singlelog.infoline when playback begins.2. Missing title and author for TVHTML5 + OAuth responses
File:
NonMusicClient.javaWhen a login-required video is loaded via the TV client with OAuth, the InnerTube player response returns a
videoDetailsobject that containsvideoIdbut omitstitleandauthor. The original code readvideoDetails.titleandvideoDetails.authordirectly, so both fields come back null for this client/content combination.Fix: two private static helper methods -
extractTitleandextractAuthor- each try a cascade of known InnerTube response locations in order:videoDetails.titleas a plain string (existing behaviour)videoDetails.title.simpleText(structured text node variant)videoDetails.title.runs[0].text(rich text node variant)microformat.playerMicroformatRendererfields (TV client microformat)microformat.microformatDataRendererfields (web client microformat)If either field is still null after all InnerTube paths,
fetchOEmbedis called as a last resort. This endpoint is public, requires no authentication, and returnstitleandauthor_namefor any publicly accessible video including login-required content and live streams. It is called at most once per load and only when needed. The method now accepts aHttpInterfaceso requests go through the pre-configured source manager interface rather than bypassing it with a raw client.Test plan
videoDetailsas before, oEmbed not calledlog.debug("Segment URL: ...")no longer fires every segment during live stream playback