Fix playlist continuation.

This commit is contained in:
FireMasterK 2021-03-30 15:06:01 +05:30
parent 8e9547ef8d
commit 0d76c7437e
No known key found for this signature in database
GPG key ID: 8DFF5DD33E93DB58
3 changed files with 28 additions and 14 deletions

View file

@ -94,8 +94,10 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
}
}).map("/nextpage/playlists/:playlistId", request -> {
try {
return getJsonResponse(ResponseHelper.playlistPageResponse(request.getPathParameter("playlistId"),
request.getQueryParameter("url")), "public, s-maxage=3600");
return getJsonResponse(
ResponseHelper.playlistPageResponse(request.getPathParameter("playlistId"),
request.getQueryParameter("url"), request.getQueryParameter("id")),
"public, s-maxage=3600");
} catch (Exception e) {
return getErrorResponse(e);
}

View file

@ -204,7 +204,7 @@ public class ResponseHelper {
if (info.hasNextPage()) {
Page page = info.getNextPage();
nextpage = page.getUrl();
id = info.getNextPage().getId();
next_id = info.getNextPage().getId();
}
final StreamsPage streamspage = new StreamsPage(nextpage, next_id, relatedStreams);
@ -245,34 +245,45 @@ public class ResponseHelper {
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
});
String nextpage = info.hasNextPage() ? info.getNextPage().getUrl() : null;
String nextpage = null, next_id = null;
if (info.hasNextPage()) {
Page page = info.getNextPage();
nextpage = page.getUrl();
next_id = info.getNextPage().getId();
}
final Playlist playlist = new Playlist(info.getName(), rewriteURL(info.getThumbnailUrl()),
rewriteURL(info.getBannerUrl()), nextpage, info.getUploaderName(), info.getUploaderUrl().substring(23),
rewriteURL(info.getUploaderAvatarUrl()), (int) info.getStreamCount(), relatedStreams);
rewriteURL(info.getBannerUrl()), nextpage, next_id, info.getUploaderName(),
info.getUploaderUrl().substring(23), rewriteURL(info.getUploaderAvatarUrl()),
(int) info.getStreamCount(), relatedStreams);
return Constants.mapper.writeValueAsBytes(playlist);
}
public static final byte[] playlistPageResponse(String playlistId, String url)
public static final byte[] playlistPageResponse(String playlistId, String url, String id)
throws IOException, ExtractionException, InterruptedException {
InfoItemsPage<StreamInfoItem> page = PlaylistInfo.getMoreItems(Constants.YOUTUBE_SERVICE,
"https://www.youtube.com/playlist?list=" + playlistId, new Page(url));
InfoItemsPage<StreamInfoItem> info = PlaylistInfo.getMoreItems(Constants.YOUTUBE_SERVICE,
"https://www.youtube.com/playlist?list=" + playlistId, new Page(url, id));
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
page.getItems().forEach(o -> {
info.getItems().forEach(o -> {
StreamInfoItem item = o;
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
});
String nextpage = page.hasNextPage() ? page.getNextPage().getUrl() : null;
String nextpage = null, next_id = null;
if (info.hasNextPage()) {
Page page = info.getNextPage();
nextpage = page.getUrl();
next_id = info.getNextPage().getId();
}
final StreamsPage streamspage = new StreamsPage(nextpage, relatedStreams);
final StreamsPage streamspage = new StreamsPage(nextpage, next_id, relatedStreams);
return Constants.mapper.writeValueAsBytes(streamspage);

View file

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