Resolve HLS segment and key urls against the playlist url - #3174
Open
Dev-next-gen wants to merge 1 commit into
Open
Resolve HLS segment and key urls against the playlist url#3174Dev-next-gen wants to merge 1 commit into
Dev-next-gen wants to merge 1 commit into
Conversation
hslLazy built segment and key urls by appending the entry to the parent directory of the playlist, so root-relative entries (/seg.ts) and scheme-relative entries (//host/seg.ts) produced urls such as /a/b//seg.ts that do not exist. Use the RFC 3986 resolution that HlsPlaylistParser already applies to variant urls, and trim the newline captured by TS_EXTENSION_REGEX.
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.
While reading
M3u8Helper2.hslLazyI noticed that segment and key URIs from a media playlist are joined to the playlist's parent directory as plain strings, while the variant URLs in the same flow are resolved byHlsPlaylistParser.UrlUtil.resolveToUrl(RFC 3986). Only plain relative entries survive that join.With a playlist at
https://host/a/b/index.m3u8:/seg/1.tsbecamehttps://host/a/b//seg/1.ts//cdn/seg.tsbecamehttps://host/a/b///cdn/seg.ts#EXT-X-KEY:METHOD=AES-128,URI="/keys/k.bin"was fetched fromhttps://host/a/b//keys/k.binThose URLs don't exist on the server, so downloads and preview generation of such streams fail. This change resolves non-absolute entries with the same
UrlUtil.resolveToUrlthe parser already uses. Plain relative entries likeseg0.tsresolve to the same URL as before, and absolutehttp(s)://entries are left as they are. The segment value also carried the trailing newline captured byTS_EXTENSION_REGEX, which I trim before resolving.LazyHlsDownloadData.relativeUrlis unchanged.To test it I added
library/src/jvmTest/.../M3u8HelperTest.kt. It serves playlists from a localcom.sun.net.httpserver, checks the resolved segment URLs, downloads every segment throughresolveLink, and checks that the key is requested at/keys/k.bin. On master both tests fail:With the change,
./gradlew library:jvmTestpasses (543 tests) on JDK 17 and 21, and./gradlew library:checkKotlinAbipasses on JDK 17 like in CI. I haven't tried it in the app against a real stream, only through these tests.AI tools used