From dd8d1ae5d51602d88324ee68f54aa048245d9dd8 Mon Sep 17 00:00:00 2001 From: devoxin <15076404+devoxin@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:33:07 +0100 Subject: [PATCH] Distinguish between inner and outer M3U(8) playlists. (#131) --- .../playlists/HlsStreamSegmentUrlProvider.java | 14 ++++++++++++-- .../source/stream/M3uStreamSegmentUrlProvider.java | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main/src/main/java/com/sedmelluq/discord/lavaplayer/container/playlists/HlsStreamSegmentUrlProvider.java b/main/src/main/java/com/sedmelluq/discord/lavaplayer/container/playlists/HlsStreamSegmentUrlProvider.java index 950dbfe3..8d00f67b 100644 --- a/main/src/main/java/com/sedmelluq/discord/lavaplayer/container/playlists/HlsStreamSegmentUrlProvider.java +++ b/main/src/main/java/com/sedmelluq/discord/lavaplayer/container/playlists/HlsStreamSegmentUrlProvider.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.Arrays; import java.util.List; import static com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools.fetchResponseLines; @@ -29,6 +30,10 @@ protected String getQualityFromM3uDirective(ExtendedM3uParser.Line directiveLine return "default"; } + protected boolean isSegmentPlaylist(String[] lines) { + return Arrays.stream(lines).noneMatch(line -> line.startsWith("#EXT-X-STREAM-INF")); + } + @Override protected String fetchSegmentPlaylistUrl(HttpInterface httpInterface) throws IOException { if (segmentPlaylistUrl != null) { @@ -36,8 +41,13 @@ protected String fetchSegmentPlaylistUrl(HttpInterface httpInterface) throws IOE } HttpUriRequest request = new HttpGet(streamListUrl); - List streams = loadChannelStreamsList(fetchResponseLines(httpInterface, request, - "HLS stream list")); + String[] lines = fetchResponseLines(httpInterface, request, "HLS stream list"); + + if (isSegmentPlaylist(lines)) { + return (segmentPlaylistUrl = streamListUrl); + } + + List streams = loadChannelStreamsList(lines); if (streams.isEmpty()) { throw new IllegalStateException("No streams listed in HLS stream list."); diff --git a/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/stream/M3uStreamSegmentUrlProvider.java b/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/stream/M3uStreamSegmentUrlProvider.java index 5ed000df..82b5a07f 100644 --- a/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/stream/M3uStreamSegmentUrlProvider.java +++ b/main/src/main/java/com/sedmelluq/discord/lavaplayer/source/stream/M3uStreamSegmentUrlProvider.java @@ -170,7 +170,7 @@ protected List loadChannelStreamsList(String[] lines) { } streamInfoLine = null; - } else if (line.isDirective() && "EXT-X-STREAM-INF".equals(line.directiveName)) { + } else if (line.isDirective() && ("EXT-X-STREAM-INF".equals(line.directiveName) || "EXTINF".equals(line.directiveName))) { streamInfoLine = line; } }