Don't parse manifest and add proxyUrl for clientside rewrites.

This commit is contained in:
FireMasterK 2021-06-10 02:50:53 +05:30
parent d53459171f
commit f00153205e
No known key found for this signature in database
GPG key ID: 8DFF5DD33E93DB58
2 changed files with 4 additions and 22 deletions

View file

@ -11,7 +11,6 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONObject;
import org.schabi.newpipe.extractor.InfoItem;
@ -103,27 +102,6 @@ public class ResponseHelper {
if ((hls = info.getHlsUrl()) != null && !hls.isEmpty())
livestream = true;
if (hls != null) {
java.util.stream.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));
}
}
}
if (!livestream) {
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()),
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true,

View file

@ -2,6 +2,8 @@ package me.kavin.piped.utils.obj;
import java.util.List;
import me.kavin.piped.consts.Constants;
public class Streams {
public String title, description, uploadDate, uploader, uploaderUrl, uploaderAvatar, thumbnailUrl, hls;
@ -16,6 +18,8 @@ public class Streams {
public boolean livestream;
public final String proxyUrl = Constants.PROXY_PART;
public Streams(String title, String description, String uploadDate, String uploader, String uploaderUrl,
String uploaderAvatar, String thumbnailUrl, long duration, long views, long likes, long dislikes,
List<PipedStream> audioStreams, List<PipedStream> videoStreams, List<StreamItem> relatedStreams,