From 179025af7e34ce183e1a2380551fea1172811fdb Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Wed, 21 Apr 2021 19:32:50 +0530 Subject: [PATCH] Change from ids to base64 encoded continuations. --- .../me/kavin/piped/utils/ResponseHelper.java | 35 ++++++++++--------- .../me/kavin/piped/utils/obj/Channel.java | 6 ++-- .../me/kavin/piped/utils/obj/Playlist.java | 8 ++--- .../me/kavin/piped/utils/obj/StreamsPage.java | 6 ++-- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index 6e0720a..f902f2d 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.json.JSONObject; @@ -137,7 +138,7 @@ public class ResponseHelper { final List relatedStreams = new ObjectArrayList<>(); - info.getRelatedStreams().forEach(o -> { + info.getRelatedItems().forEach(o -> { StreamInfoItem item = (StreamInfoItem) o; relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(), rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23), @@ -172,15 +173,15 @@ public class ResponseHelper { item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); }); - String nextpage = null, id = null; + String nextpage = null, body = null; if (info.hasNextPage()) { Page page = info.getNextPage(); nextpage = page.getUrl(); - id = info.getNextPage().getId(); + body = Base64.encodeBase64String(info.getNextPage().getBody()); } final Channel channel = new Channel(info.getId(), info.getName(), rewriteURL(info.getAvatarUrl()), - rewriteURL(info.getBannerUrl()), info.getDescription(), nextpage, id, relatedStreams); + rewriteURL(info.getBannerUrl()), info.getDescription(), nextpage, body, relatedStreams); IPFS.publishData(channel); @@ -188,11 +189,11 @@ public class ResponseHelper { } - public static final byte[] channelPageResponse(String channelId, String url, String id) + public static final byte[] channelPageResponse(String channelId, String url, String body_req) throws IOException, ExtractionException, InterruptedException { InfoItemsPage info = ChannelInfo.getMoreItems(Constants.YOUTUBE_SERVICE, - "https://youtube.com/channel/" + channelId, new Page(url, id)); + "https://youtube.com/channel/" + channelId, new Page(url, Base64.decodeBase64(body_req))); final List relatedStreams = new ObjectArrayList<>(); @@ -203,14 +204,14 @@ public class ResponseHelper { item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); }); - String nextpage = null, next_id = null; + String nextpage = null, body = null; if (info.hasNextPage()) { Page page = info.getNextPage(); nextpage = page.getUrl(); - next_id = info.getNextPage().getId(); + body = Base64.encodeBase64String(info.getNextPage().getBody()); } - final StreamsPage streamspage = new StreamsPage(nextpage, next_id, relatedStreams); + final StreamsPage streamspage = new StreamsPage(nextpage, body, relatedStreams); return Constants.mapper.writeValueAsBytes(streamspage); @@ -248,15 +249,15 @@ public class ResponseHelper { item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); }); - String nextpage = null, next_id = null; + String nextpage = null, body = null; if (info.hasNextPage()) { Page page = info.getNextPage(); nextpage = page.getUrl(); - next_id = info.getNextPage().getId(); + body = Base64.encodeBase64String(info.getNextPage().getBody()); } final Playlist playlist = new Playlist(info.getName(), rewriteURL(info.getThumbnailUrl()), - rewriteURL(info.getBannerUrl()), nextpage, next_id, info.getUploaderName(), + rewriteURL(info.getBannerUrl()), nextpage, body, info.getUploaderName(), info.getUploaderUrl().substring(23), rewriteURL(info.getUploaderAvatarUrl()), (int) info.getStreamCount(), relatedStreams); @@ -264,11 +265,11 @@ public class ResponseHelper { } - public static final byte[] playlistPageResponse(String playlistId, String url, String id) + public static final byte[] playlistPageResponse(String playlistId, String url, String body_req) throws IOException, ExtractionException, InterruptedException { InfoItemsPage info = PlaylistInfo.getMoreItems(Constants.YOUTUBE_SERVICE, - "https://www.youtube.com/playlist?list=" + playlistId, new Page(url, id)); + "https://www.youtube.com/playlist?list=" + playlistId, new Page(url, Base64.decodeBase64(body_req))); final List relatedStreams = new ObjectArrayList<>(); @@ -279,14 +280,14 @@ public class ResponseHelper { item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); }); - String nextpage = null, next_id = null; + String nextpage = null, body = null; if (info.hasNextPage()) { Page page = info.getNextPage(); nextpage = page.getUrl(); - next_id = info.getNextPage().getId(); + body = Base64.encodeBase64String(info.getNextPage().getBody()); } - final StreamsPage streamspage = new StreamsPage(nextpage, next_id, relatedStreams); + final StreamsPage streamspage = new StreamsPage(nextpage, body, relatedStreams); return Constants.mapper.writeValueAsBytes(streamspage); diff --git a/src/main/java/me/kavin/piped/utils/obj/Channel.java b/src/main/java/me/kavin/piped/utils/obj/Channel.java index cf88054..646ba02 100644 --- a/src/main/java/me/kavin/piped/utils/obj/Channel.java +++ b/src/main/java/me/kavin/piped/utils/obj/Channel.java @@ -4,18 +4,18 @@ import java.util.List; public class Channel { - public String id, name, avatarUrl, bannerUrl, description, nextpage, nextid; + public String id, name, avatarUrl, bannerUrl, description, nextpage, nextbody; public List relatedStreams; public Channel(String id, String name, String avatarUrl, String bannerUrl, String description, String nextpage, - String nextid, List relatedStreams) { + String nextbody, List relatedStreams) { this.id = id; this.name = name; this.avatarUrl = avatarUrl; this.bannerUrl = bannerUrl; this.description = description; this.nextpage = nextpage; - this.nextid = nextid; + this.nextbody = nextbody; this.relatedStreams = relatedStreams; } } diff --git a/src/main/java/me/kavin/piped/utils/obj/Playlist.java b/src/main/java/me/kavin/piped/utils/obj/Playlist.java index 38a0205..6873fdb 100644 --- a/src/main/java/me/kavin/piped/utils/obj/Playlist.java +++ b/src/main/java/me/kavin/piped/utils/obj/Playlist.java @@ -4,17 +4,17 @@ import java.util.List; public class Playlist { - public String name, thumbnailUrl, bannerUrl, nextpage, nextid, uploader, uploaderUrl, uploaderAvatar; + public String name, thumbnailUrl, bannerUrl, nextpage, nextbody, uploader, uploaderUrl, uploaderAvatar; public int videos; public List relatedStreams; - public Playlist(String name, String thumbnailUrl, String bannerUrl, String nextpage, String nextid, String uploader, - String uploaderUrl, String uploaderAvatar, int videos, List relatedStreams) { + public Playlist(String name, String thumbnailUrl, String bannerUrl, String nextpage, String nextbody, + String uploader, String uploaderUrl, String uploaderAvatar, int videos, List relatedStreams) { this.name = name; this.thumbnailUrl = thumbnailUrl; this.bannerUrl = bannerUrl; this.nextpage = nextpage; - this.nextid = nextid; + this.nextbody = nextbody; this.videos = videos; this.uploader = uploader; this.uploaderUrl = uploaderUrl; diff --git a/src/main/java/me/kavin/piped/utils/obj/StreamsPage.java b/src/main/java/me/kavin/piped/utils/obj/StreamsPage.java index 96fee19..059485d 100644 --- a/src/main/java/me/kavin/piped/utils/obj/StreamsPage.java +++ b/src/main/java/me/kavin/piped/utils/obj/StreamsPage.java @@ -4,12 +4,12 @@ import java.util.List; public class StreamsPage { - public String nextpage, nextid; + public String nextpage, nextbody; public List relatedStreams; - public StreamsPage(String nextpage, String nextid, List relatedStreams) { + public StreamsPage(String nextpage, String nextbody, List relatedStreams) { this.nextpage = nextpage; - this.nextid = nextid; + this.nextbody = nextbody; this.relatedStreams = relatedStreams; } }