Add support for UMP.

This commit is contained in:
Kavin 2023-11-27 23:49:52 +00:00
parent 221cf79014
commit 9fb16d4384
No known key found for this signature in database
GPG key ID: 6E4598CA5C92C41F
2 changed files with 20 additions and 13 deletions

View file

@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.stream.StreamType;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import static me.kavin.piped.utils.URLUtils.*;
@ -42,18 +43,23 @@ public class CollectionUtils {
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
final var extraParams = Map.of(
"ump", "1",
"srfvp", "1"
);
if (!livestream) {
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(stream.getItag(), rewriteVideoURL(stream.getContent()),
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(stream.getItag(), rewriteVideoURL(stream.getContent(), extraParams),
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true,
stream.getBitrate(), stream.getInitStart(), stream.getInitEnd(), stream.getIndexStart(),
stream.getIndexEnd(), stream.getCodec(), stream.getWidth(), stream.getHeight(), stream.getFps(), stream.getItagItem().getContentLength())));
info.getVideoStreams()
.forEach(stream -> videoStreams
.add(new PipedStream(stream.getItag(), rewriteVideoURL(stream.getContent()), String.valueOf(stream.getFormat()),
.add(new PipedStream(stream.getItag(), rewriteVideoURL(stream.getContent(), Map.of()), String.valueOf(stream.getFormat()),
stream.getResolution(), stream.getFormat().getMimeType(), false, stream.getItagItem().getContentLength())));
info.getAudioStreams()
.forEach(stream -> audioStreams.add(new PipedStream(stream.getItag(), rewriteVideoURL(stream.getContent()),
.forEach(stream -> audioStreams.add(new PipedStream(stream.getItag(), rewriteVideoURL(stream.getContent(), extraParams),
String.valueOf(stream.getFormat()), stream.getAverageBitrate() + " kbps",
stream.getFormat().getMimeType(), false, stream.getBitrate(), stream.getInitStart(),
stream.getInitEnd(), stream.getIndexStart(), stream.getIndexEnd(), stream.getItagItem().getContentLength(), stream.getCodec(), stream.getAudioTrackId(),
@ -73,8 +79,8 @@ public class CollectionUtils {
info.getTextualUploadDate(), info.getUploaderName(), substringYouTube(info.getUploaderUrl()),
getLastThumbnail(info.getUploaderAvatars()), getLastThumbnail(info.getThumbnails()), info.getDuration(),
info.getViewCount(), info.getLikeCount(), info.getDislikeCount(), info.getUploaderSubscriberCount(), info.isUploaderVerified(),
audioStreams, videoStreams, relatedStreams, subtitles, livestream, rewriteVideoURL(info.getHlsUrl()),
rewriteVideoURL(info.getDashMpdUrl()), null, info.getCategory(), info.getLicence(),
audioStreams, videoStreams, relatedStreams, subtitles, livestream, rewriteVideoURL(info.getHlsUrl(), Map.of()),
rewriteVideoURL(info.getDashMpdUrl(), Map.of()), null, info.getCategory(), info.getLicence(),
info.getPrivacy().name().toLowerCase(), info.getTags(), metaInfo, chapters, previewFrames);
}

View file

@ -12,10 +12,7 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;
import static me.kavin.piped.consts.Constants.PROXY_HASH_SECRET;
@ -44,18 +41,18 @@ public class URLUtils {
}
public static String rewriteURL(final String old) {
return rewriteURL(old, Constants.IMAGE_PROXY_PART);
return rewriteURL(old, Constants.IMAGE_PROXY_PART, Map.of());
}
public static String getLastThumbnail(final List<Image> thumbnails) {
return thumbnails.isEmpty() ? null : rewriteURL(thumbnails.getLast().getUrl());
}
public static String rewriteVideoURL(final String old) {
return rewriteURL(old, Constants.PROXY_PART);
public static String rewriteVideoURL(final String old, final Map<String, String> extraParams) {
return rewriteURL(old, Constants.PROXY_PART, extraParams);
}
public static String rewriteURL(final String old, final String proxy) {
public static String rewriteURL(final String old, final String proxy, final Map<String, String> extraParams) {
if (StringUtils.isEmpty(old)) return null;
@ -109,6 +106,10 @@ public class URLUtils {
queryPairs.add(List.of("host", host));
}
for (var entry : extraParams.entrySet()) {
queryPairs.add(List.of(entry.getKey(), entry.getValue()));
}
String path = url.getPath();
if (path.contains("=")) {