livestreams: add quality selector

This commit is contained in:
FireMasterK 2021-01-20 21:05:13 +05:30
parent 701a9a4837
commit f712797345
No known key found for this signature in database
GPG key ID: 8DFF5DD33E93DB58

View file

@ -86,38 +86,48 @@ public class ResponseHelper {
if (lbryURL != null) if (lbryURL != null)
videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false)); videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));
String hls = null; final String hls;
boolean livestream = false; boolean livestream = false;
if ((hls = info.getHlsUrl()) != null && !hls.isEmpty()) if ((hls = info.getHlsUrl()) != null && !hls.isEmpty())
livestream = true; livestream = true;
long minexpire = Long.MAX_VALUE; if (hls != null) {
ObjectArrayList<Stream> allStreams = new ObjectArrayList<>(); Stream<String> resp = Constants.h2client
.send(HttpRequest.newBuilder(URI.create(hls)).GET().build(), BodyHandlers.ofLines()).body();
allStreams.addAll(info.getVideoStreams()); ObjectArrayList<String> lines = new ObjectArrayList<>();
allStreams.addAll(info.getAudioStreams()); resp.forEach(line -> lines.add(line));
allStreams.addAll(info.getVideoOnlyStreams());
for (Stream stream : allStreams) {
long expire = Long.parseLong(StringUtils.substringBetween(stream.getUrl(), "expire=", "&"));
if (expire < minexpire)
minexpire = expire;
for (int i = lines.size() - 1; i > 2; i--) {
String line = lines.get(i);
if (line.startsWith("https://manifest.googlevideo.com")) {
String prevLine = lines.get(i - 1);
String height = StringUtils.substringBetween(prevLine, "RESOLUTION=", ",").split("x")[1];
int fps = Integer.parseInt(StringUtils.substringBetween(prevLine, "FRAME-RATE=", ","));
String quality = height + "p";
if (fps > 30)
quality += fps;
videoStreams.add(new PipedStream(line, "HLS", quality, "application/x-mpegURL", false));
}
}
} }
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()), if (!livestream) {
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true))); info.getVideoOnlyStreams()
info.getVideoStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()), .forEach(stream -> videoStreams
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), false))); .add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()),
stream.getResolution(), stream.getFormat().getMimeType(), true)));
info.getVideoStreams()
.forEach(stream -> videoStreams
.add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()),
stream.getResolution(), stream.getFormat().getMimeType(), false)));
info.getAudioStreams() info.getAudioStreams()
.forEach(stream -> audioStreams .forEach(stream -> audioStreams
.add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()), .add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()),
stream.getAverageBitrate() + " kbps", stream.getFormat().getMimeType(), false))); stream.getAverageBitrate() + " kbps", stream.getFormat().getMimeType(), false)));
}
final List<StreamItem> relatedStreams = new ObjectArrayList<>(); final List<StreamItem> relatedStreams = new ObjectArrayList<>();
@ -184,8 +194,6 @@ public class ResponseHelper {
} }
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
public static final byte[] trendingResponse() throws ParsingException, ExtractionException, IOException { public static final byte[] trendingResponse() throws ParsingException, ExtractionException, IOException {
final List<StreamItem> relatedStreams = new ObjectArrayList<>(); final List<StreamItem> relatedStreams = new ObjectArrayList<>();