mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-15 14:50:29 +05:30
Add support for UMP.
This commit is contained in:
parent
221cf79014
commit
9fb16d4384
@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.stream.StreamType;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static me.kavin.piped.utils.URLUtils.*;
|
import static me.kavin.piped.utils.URLUtils.*;
|
||||||
@ -42,18 +43,23 @@ public class CollectionUtils {
|
|||||||
|
|
||||||
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
|
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
|
||||||
|
|
||||||
|
final var extraParams = Map.of(
|
||||||
|
"ump", "1",
|
||||||
|
"srfvp", "1"
|
||||||
|
);
|
||||||
|
|
||||||
if (!livestream) {
|
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,
|
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true,
|
||||||
stream.getBitrate(), stream.getInitStart(), stream.getInitEnd(), stream.getIndexStart(),
|
stream.getBitrate(), stream.getInitStart(), stream.getInitEnd(), stream.getIndexStart(),
|
||||||
stream.getIndexEnd(), stream.getCodec(), stream.getWidth(), stream.getHeight(), stream.getFps(), stream.getItagItem().getContentLength())));
|
stream.getIndexEnd(), stream.getCodec(), stream.getWidth(), stream.getHeight(), stream.getFps(), stream.getItagItem().getContentLength())));
|
||||||
info.getVideoStreams()
|
info.getVideoStreams()
|
||||||
.forEach(stream -> videoStreams
|
.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())));
|
stream.getResolution(), stream.getFormat().getMimeType(), false, stream.getItagItem().getContentLength())));
|
||||||
|
|
||||||
info.getAudioStreams()
|
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",
|
String.valueOf(stream.getFormat()), stream.getAverageBitrate() + " kbps",
|
||||||
stream.getFormat().getMimeType(), false, stream.getBitrate(), stream.getInitStart(),
|
stream.getFormat().getMimeType(), false, stream.getBitrate(), stream.getInitStart(),
|
||||||
stream.getInitEnd(), stream.getIndexStart(), stream.getIndexEnd(), stream.getItagItem().getContentLength(), stream.getCodec(), stream.getAudioTrackId(),
|
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()),
|
info.getTextualUploadDate(), info.getUploaderName(), substringYouTube(info.getUploaderUrl()),
|
||||||
getLastThumbnail(info.getUploaderAvatars()), getLastThumbnail(info.getThumbnails()), info.getDuration(),
|
getLastThumbnail(info.getUploaderAvatars()), getLastThumbnail(info.getThumbnails()), info.getDuration(),
|
||||||
info.getViewCount(), info.getLikeCount(), info.getDislikeCount(), info.getUploaderSubscriberCount(), info.isUploaderVerified(),
|
info.getViewCount(), info.getLikeCount(), info.getDislikeCount(), info.getUploaderSubscriberCount(), info.isUploaderVerified(),
|
||||||
audioStreams, videoStreams, relatedStreams, subtitles, livestream, rewriteVideoURL(info.getHlsUrl()),
|
audioStreams, videoStreams, relatedStreams, subtitles, livestream, rewriteVideoURL(info.getHlsUrl(), Map.of()),
|
||||||
rewriteVideoURL(info.getDashMpdUrl()), null, info.getCategory(), info.getLicence(),
|
rewriteVideoURL(info.getDashMpdUrl(), Map.of()), null, info.getCategory(), info.getLicence(),
|
||||||
info.getPrivacy().name().toLowerCase(), info.getTags(), metaInfo, chapters, previewFrames);
|
info.getPrivacy().name().toLowerCase(), info.getTags(), metaInfo, chapters, previewFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,10 +12,7 @@ import java.net.URLEncoder;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import static me.kavin.piped.consts.Constants.PROXY_HASH_SECRET;
|
import static me.kavin.piped.consts.Constants.PROXY_HASH_SECRET;
|
||||||
|
|
||||||
@ -44,18 +41,18 @@ public class URLUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String rewriteURL(final String old) {
|
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) {
|
public static String getLastThumbnail(final List<Image> thumbnails) {
|
||||||
return thumbnails.isEmpty() ? null : rewriteURL(thumbnails.getLast().getUrl());
|
return thumbnails.isEmpty() ? null : rewriteURL(thumbnails.getLast().getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String rewriteVideoURL(final String old) {
|
public static String rewriteVideoURL(final String old, final Map<String, String> extraParams) {
|
||||||
return rewriteURL(old, Constants.PROXY_PART);
|
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;
|
if (StringUtils.isEmpty(old)) return null;
|
||||||
|
|
||||||
@ -109,6 +106,10 @@ public class URLUtils {
|
|||||||
queryPairs.add(List.of("host", host));
|
queryPairs.add(List.of("host", host));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var entry : extraParams.entrySet()) {
|
||||||
|
queryPairs.add(List.of(entry.getKey(), entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
String path = url.getPath();
|
String path = url.getPath();
|
||||||
|
|
||||||
if (path.contains("=")) {
|
if (path.contains("=")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user