Skip to content

Commit

Permalink
Merge pull request #740 from TeamPiped/ump-support
Browse files Browse the repository at this point in the history
Add support for UMP
  • Loading branch information
FireMasterK authored Nov 27, 2023
2 parents 221cf79 + 9fb16d4 commit d7762f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
16 changes: 11 additions & 5 deletions src/main/java/me/kavin/piped/utils/CollectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

import static me.kavin.piped.utils.URLUtils.*;
Expand Down Expand Up @@ -42,18 +43,23 @@ public static Streams collectStreamInfo(StreamInfo info) {

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(),
Expand All @@ -73,8 +79,8 @@ public static Streams collectStreamInfo(StreamInfo info) {
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);
}

Expand Down
17 changes: 9 additions & 8 deletions src/main/java/me/kavin/piped/utils/URLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
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;

Expand Down Expand Up @@ -44,18 +41,18 @@ public static String substringYouTube(String s) {
}

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;

Expand Down Expand Up @@ -109,6 +106,10 @@ public static String rewriteURL(final String old, final String proxy) {
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("=")) {
Expand Down

0 comments on commit d7762f0

Please sign in to comment.