mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
livestreams: add quality selector
This commit is contained in:
parent
701a9a4837
commit
f712797345
1 changed files with 32 additions and 24 deletions
|
@ -86,38 +86,48 @@ public class ResponseHelper {
|
|||
if (lbryURL != null)
|
||||
videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));
|
||||
|
||||
String hls = null;
|
||||
final String hls;
|
||||
boolean livestream = false;
|
||||
|
||||
if ((hls = info.getHlsUrl()) != null && !hls.isEmpty())
|
||||
livestream = true;
|
||||
|
||||
long minexpire = Long.MAX_VALUE;
|
||||
if (hls != null) {
|
||||
|
||||
ObjectArrayList<Stream> allStreams = new ObjectArrayList<>();
|
||||
|
||||
allStreams.addAll(info.getVideoStreams());
|
||||
allStreams.addAll(info.getAudioStreams());
|
||||
allStreams.addAll(info.getVideoOnlyStreams());
|
||||
|
||||
for (Stream stream : allStreams) {
|
||||
|
||||
long expire = Long.parseLong(StringUtils.substringBetween(stream.getUrl(), "expire=", "&"));
|
||||
|
||||
if (expire < minexpire)
|
||||
minexpire = expire;
|
||||
Stream<String> resp = Constants.h2client
|
||||
.send(HttpRequest.newBuilder(URI.create(hls)).GET().build(), BodyHandlers.ofLines()).body();
|
||||
ObjectArrayList<String> lines = new ObjectArrayList<>();
|
||||
resp.forEach(line -> lines.add(line));
|
||||
|
||||
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()),
|
||||
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)));
|
||||
if (!livestream) {
|
||||
info.getVideoOnlyStreams()
|
||||
.forEach(stream -> videoStreams
|
||||
.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()
|
||||
.forEach(stream -> audioStreams
|
||||
.add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()),
|
||||
stream.getAverageBitrate() + " kbps", stream.getFormat().getMimeType(), false)));
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||
|
|
Loading…
Reference in a new issue