Merge pull request #187 from TeamPiped/clips-id

Add Support for extracting videoId from clipId
This commit is contained in:
Kavin 2022-02-10 15:02:32 +00:00 committed by GitHub
commit 24482e933e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 3 deletions

View file

@ -82,6 +82,13 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
} catch (Exception e) {
return getErrorResponse(e, request.getPath());
}
})).map(GET, "/clips/:clipId", AsyncServlet.ofBlocking(executor, request -> {
try {
return getJsonResponse(ResponseHelper.resolveClipId(request.getPathParameter("clipId")),
"public, max-age=31536000, immutable");
} catch (Exception e) {
return getErrorResponse(e, request.getPath());
}
})).map(GET, "/channel/:channelId", AsyncServlet.ofBlocking(executor, request -> {
try {
return getJsonResponse(

View file

@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.Scheduler;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonWriter;
import com.rometools.rome.feed.synd.*;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedOutput;
@ -41,6 +43,7 @@ import org.schabi.newpipe.extractor.search.SearchInfo;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@ -48,14 +51,18 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import static java.nio.charset.StandardCharsets.UTF_8;
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
import static me.kavin.piped.utils.URLUtils.rewriteURL;
import static me.kavin.piped.utils.URLUtils.substringYouTube;
import static org.schabi.newpipe.extractor.NewPipe.getPreferredContentCountry;
import static org.schabi.newpipe.extractor.NewPipe.getPreferredLocalization;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
public class ResponseHelper {
@ -162,6 +169,22 @@ public class ResponseHelper {
}
public static byte[] resolveClipId(String clipId) throws Exception {
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
getPreferredLocalization(), getPreferredContentCountry())
.value("url", "https://www.youtube.com/clip/" + clipId)
.done())
.getBytes(UTF_8);
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
body, getPreferredLocalization());
final String videoId = JsonUtils.getString(jsonResponse, "endpoint.watchEndpoint.videoId");
return Constants.mapper.writeValueAsBytes(new VideoResolvedResponse(videoId));
}
public static byte[] channelResponse(String channelPath) throws Exception {
final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath);
@ -336,7 +359,7 @@ public class ResponseHelper {
feed.setEntries(entries);
return new SyndFeedOutput().outputString(feed).getBytes(StandardCharsets.UTF_8);
return new SyndFeedOutput().outputString(feed).getBytes(UTF_8);
}
@ -789,7 +812,7 @@ public class ResponseHelper {
s.close();
return new SyndFeedOutput().outputString(feed).getBytes(StandardCharsets.UTF_8);
return new SyndFeedOutput().outputString(feed).getBytes(UTF_8);
}
s.close();

View file

@ -0,0 +1,10 @@
package me.kavin.piped.utils.resp;
public class VideoResolvedResponse {
public String videoId;
public VideoResolvedResponse(String videoId) {
this.videoId = videoId;
}
}

View file

@ -22,6 +22,9 @@ curl ${CURLOPTS[@]} $HOST/playlists/PLQSoWXSpjA3-egtFq45DcUydZ885W7MTT || exit 1
PLAYLIST_NEXTPAGE=$(curl -s -o - -f $HOST/playlists/PLQSoWXSpjA3-egtFq45DcUydZ885W7MTT | jq -r .nextpage)
curl ${CURLOPTS[@]} $HOST/nextpage/playlists/UCsXVk37bltHxD1rDPwtNM8Q -G --data-urlencode "nextpage=$PLAYLIST_NEXTPAGE" || exit 1
# Clips
curl ${CURLOPTS[@]} $HOST/clips/Ugkx71jS31nwsms_Cc65oi7yXF1mILflhhrO || exit 1
# Streams
curl ${CURLOPTS[@]} $HOST/streams/BtN-goy9VOY || exit 1