Skip to content

Commit

Permalink
Distinguish between inner and outer M3U(8) playlists.
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Jun 5, 2024
1 parent 8da0444 commit 54b7641
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,15 +30,24 @@ 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) {
return segmentPlaylistUrl;
}

HttpUriRequest request = new HttpGet(streamListUrl);
List<ChannelStreamInfo> streams = loadChannelStreamsList(fetchResponseLines(httpInterface, request,
"HLS stream list"));
String[] lines = fetchResponseLines(httpInterface, request, "HLS stream list");

if (isSegmentPlaylist(lines)) {
return (segmentPlaylistUrl = streamListUrl);
}

List<ChannelStreamInfo> streams = loadChannelStreamsList(lines);

if (streams.isEmpty()) {
throw new IllegalStateException("No streams listed in HLS stream list.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected List<ChannelStreamInfo> 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;
}
}
Expand Down

0 comments on commit 54b7641

Please sign in to comment.