Change from ids to base64 encoded continuations.

This commit is contained in:
FireMasterK 2021-04-21 19:32:50 +05:30
parent 1e612cbb04
commit 179025af7e
No known key found for this signature in database
GPG key ID: 8DFF5DD33E93DB58
4 changed files with 28 additions and 27 deletions

View file

@ -11,6 +11,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONObject; import org.json.JSONObject;
@ -137,7 +138,7 @@ public class ResponseHelper {
final List<StreamItem> relatedStreams = new ObjectArrayList<>(); final List<StreamItem> relatedStreams = new ObjectArrayList<>();
info.getRelatedStreams().forEach(o -> { info.getRelatedItems().forEach(o -> {
StreamInfoItem item = (StreamInfoItem) o; StreamInfoItem item = (StreamInfoItem) o;
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(), relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23), rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
@ -172,15 +173,15 @@ public class ResponseHelper {
item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
}); });
String nextpage = null, id = null; String nextpage = null, body = null;
if (info.hasNextPage()) { if (info.hasNextPage()) {
Page page = info.getNextPage(); Page page = info.getNextPage();
nextpage = page.getUrl(); 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()), 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); 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 { throws IOException, ExtractionException, InterruptedException {
InfoItemsPage<StreamInfoItem> info = ChannelInfo.getMoreItems(Constants.YOUTUBE_SERVICE, InfoItemsPage<StreamInfoItem> 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<StreamItem> relatedStreams = new ObjectArrayList<>(); final List<StreamItem> relatedStreams = new ObjectArrayList<>();
@ -203,14 +204,14 @@ public class ResponseHelper {
item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
}); });
String nextpage = null, next_id = null; String nextpage = null, body = null;
if (info.hasNextPage()) { if (info.hasNextPage()) {
Page page = info.getNextPage(); Page page = info.getNextPage();
nextpage = page.getUrl(); 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); return Constants.mapper.writeValueAsBytes(streamspage);
@ -248,15 +249,15 @@ public class ResponseHelper {
item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
}); });
String nextpage = null, next_id = null; String nextpage = null, body = null;
if (info.hasNextPage()) { if (info.hasNextPage()) {
Page page = info.getNextPage(); Page page = info.getNextPage();
nextpage = page.getUrl(); nextpage = page.getUrl();
next_id = info.getNextPage().getId(); body = Base64.encodeBase64String(info.getNextPage().getBody());
} }
final Playlist playlist = new Playlist(info.getName(), rewriteURL(info.getThumbnailUrl()), 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()), info.getUploaderUrl().substring(23), rewriteURL(info.getUploaderAvatarUrl()),
(int) info.getStreamCount(), relatedStreams); (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 { throws IOException, ExtractionException, InterruptedException {
InfoItemsPage<StreamInfoItem> info = PlaylistInfo.getMoreItems(Constants.YOUTUBE_SERVICE, InfoItemsPage<StreamInfoItem> 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<StreamItem> relatedStreams = new ObjectArrayList<>(); final List<StreamItem> relatedStreams = new ObjectArrayList<>();
@ -279,14 +280,14 @@ public class ResponseHelper {
item.getTextualUploadDate(), item.getDuration(), item.getViewCount())); item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
}); });
String nextpage = null, next_id = null; String nextpage = null, body = null;
if (info.hasNextPage()) { if (info.hasNextPage()) {
Page page = info.getNextPage(); Page page = info.getNextPage();
nextpage = page.getUrl(); 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); return Constants.mapper.writeValueAsBytes(streamspage);

View file

@ -4,18 +4,18 @@ import java.util.List;
public class Channel { public class Channel {
public String id, name, avatarUrl, bannerUrl, description, nextpage, nextid; public String id, name, avatarUrl, bannerUrl, description, nextpage, nextbody;
public List<StreamItem> relatedStreams; public List<StreamItem> relatedStreams;
public Channel(String id, String name, String avatarUrl, String bannerUrl, String description, String nextpage, public Channel(String id, String name, String avatarUrl, String bannerUrl, String description, String nextpage,
String nextid, List<StreamItem> relatedStreams) { String nextbody, List<StreamItem> relatedStreams) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.avatarUrl = avatarUrl; this.avatarUrl = avatarUrl;
this.bannerUrl = bannerUrl; this.bannerUrl = bannerUrl;
this.description = description; this.description = description;
this.nextpage = nextpage; this.nextpage = nextpage;
this.nextid = nextid; this.nextbody = nextbody;
this.relatedStreams = relatedStreams; this.relatedStreams = relatedStreams;
} }
} }

View file

@ -4,17 +4,17 @@ import java.util.List;
public class Playlist { 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 int videos;
public List<StreamItem> relatedStreams; public List<StreamItem> relatedStreams;
public Playlist(String name, String thumbnailUrl, String bannerUrl, String nextpage, String nextid, String uploader, public Playlist(String name, String thumbnailUrl, String bannerUrl, String nextpage, String nextbody,
String uploaderUrl, String uploaderAvatar, int videos, List<StreamItem> relatedStreams) { String uploader, String uploaderUrl, String uploaderAvatar, int videos, List<StreamItem> relatedStreams) {
this.name = name; this.name = name;
this.thumbnailUrl = thumbnailUrl; this.thumbnailUrl = thumbnailUrl;
this.bannerUrl = bannerUrl; this.bannerUrl = bannerUrl;
this.nextpage = nextpage; this.nextpage = nextpage;
this.nextid = nextid; this.nextbody = nextbody;
this.videos = videos; this.videos = videos;
this.uploader = uploader; this.uploader = uploader;
this.uploaderUrl = uploaderUrl; this.uploaderUrl = uploaderUrl;

View file

@ -4,12 +4,12 @@ import java.util.List;
public class StreamsPage { public class StreamsPage {
public String nextpage, nextid; public String nextpage, nextbody;
public List<StreamItem> relatedStreams; public List<StreamItem> relatedStreams;
public StreamsPage(String nextpage, String nextid, List<StreamItem> relatedStreams) { public StreamsPage(String nextpage, String nextbody, List<StreamItem> relatedStreams) {
this.nextpage = nextpage; this.nextpage = nextpage;
this.nextid = nextid; this.nextbody = nextbody;
this.relatedStreams = relatedStreams; this.relatedStreams = relatedStreams;
} }
} }