mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-29 00:10:35 +05:30
[YouTube] Support Shorts UI in playlists
Also remove an outdated A/B test comment.
This commit is contained in:
parent
7936987955
commit
e6f371fb94
@ -41,6 +41,9 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||||||
// Names of some objects in JSON response frequently used in this class
|
// Names of some objects in JSON response frequently used in this class
|
||||||
private static final String PLAYLIST_VIDEO_RENDERER = "playlistVideoRenderer";
|
private static final String PLAYLIST_VIDEO_RENDERER = "playlistVideoRenderer";
|
||||||
private static final String PLAYLIST_VIDEO_LIST_RENDERER = "playlistVideoListRenderer";
|
private static final String PLAYLIST_VIDEO_LIST_RENDERER = "playlistVideoListRenderer";
|
||||||
|
private static final String RICH_GRID_RENDERER = "richGridRenderer";
|
||||||
|
private static final String RICH_ITEM_RENDERER = "richItemRenderer";
|
||||||
|
private static final String REEL_ITEM_RENDERER = "reelItemRenderer";
|
||||||
private static final String SIDEBAR = "sidebar";
|
private static final String SIDEBAR = "sidebar";
|
||||||
private static final String VIDEO_OWNER_RENDERER = "videoOwnerRenderer";
|
private static final String VIDEO_OWNER_RENDERER = "videoOwnerRenderer";
|
||||||
|
|
||||||
@ -85,10 +88,6 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||||||
* browse response (the old returns instead a sidebar one).
|
* browse response (the old returns instead a sidebar one).
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <p>
|
|
||||||
* This new playlist UI is currently A/B tested.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @return Whether the playlist response is using only the new playlist design
|
* @return Whether the playlist response is using only the new playlist design
|
||||||
*/
|
*/
|
||||||
private boolean checkIfResponseIsNewPlaylistInterface() {
|
private boolean checkIfResponseIsNewPlaylistInterface() {
|
||||||
@ -327,17 +326,22 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||||||
.map(content -> content.getObject("itemSectionRenderer")
|
.map(content -> content.getObject("itemSectionRenderer")
|
||||||
.getArray("contents")
|
.getArray("contents")
|
||||||
.getObject(0))
|
.getObject(0))
|
||||||
.filter(contentItemSectionRendererContents ->
|
.filter(content -> content.has(PLAYLIST_VIDEO_LIST_RENDERER)
|
||||||
contentItemSectionRendererContents.has(PLAYLIST_VIDEO_LIST_RENDERER)
|
|| content.has(RICH_GRID_RENDERER))
|
||||||
|| contentItemSectionRendererContents.has(
|
|
||||||
"playlistSegmentRenderer"))
|
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if (videoPlaylistObject != null && videoPlaylistObject.has(PLAYLIST_VIDEO_LIST_RENDERER)) {
|
if (videoPlaylistObject != null) {
|
||||||
final JsonArray videosArray = videoPlaylistObject
|
final JsonObject renderer;
|
||||||
.getObject(PLAYLIST_VIDEO_LIST_RENDERER)
|
if (videoPlaylistObject.has(PLAYLIST_VIDEO_LIST_RENDERER)) {
|
||||||
.getArray("contents");
|
renderer = videoPlaylistObject.getObject(PLAYLIST_VIDEO_LIST_RENDERER);
|
||||||
|
} else if (videoPlaylistObject.has(RICH_GRID_RENDERER)) {
|
||||||
|
renderer = videoPlaylistObject.getObject(RICH_GRID_RENDERER);
|
||||||
|
} else {
|
||||||
|
return new InfoItemsPage<>(collector, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonArray videosArray = renderer.getArray("contents");
|
||||||
collectStreamsFrom(collector, videosArray);
|
collectStreamsFrom(collector, videosArray);
|
||||||
|
|
||||||
nextPage = getNextPageFrom(videosArray);
|
nextPage = getNextPageFrom(videosArray);
|
||||||
@ -399,14 +403,26 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||||||
private void collectStreamsFrom(@Nonnull final StreamInfoItemsCollector collector,
|
private void collectStreamsFrom(@Nonnull final StreamInfoItemsCollector collector,
|
||||||
@Nonnull final JsonArray videos) {
|
@Nonnull final JsonArray videos) {
|
||||||
final TimeAgoParser timeAgoParser = getTimeAgoParser();
|
final TimeAgoParser timeAgoParser = getTimeAgoParser();
|
||||||
|
|
||||||
videos.stream()
|
videos.stream()
|
||||||
.filter(JsonObject.class::isInstance)
|
.filter(JsonObject.class::isInstance)
|
||||||
.map(JsonObject.class::cast)
|
.map(JsonObject.class::cast)
|
||||||
.filter(video -> video.has(PLAYLIST_VIDEO_RENDERER))
|
.forEach(video -> {
|
||||||
.map(video -> new YoutubeStreamInfoItemExtractor(
|
if (video.has(PLAYLIST_VIDEO_RENDERER)) {
|
||||||
video.getObject(PLAYLIST_VIDEO_RENDERER), timeAgoParser))
|
collector.commit(new YoutubeStreamInfoItemExtractor(
|
||||||
.forEachOrdered(collector::commit);
|
video.getObject(PLAYLIST_VIDEO_RENDERER), timeAgoParser));
|
||||||
|
} else if (video.has(RICH_ITEM_RENDERER)) {
|
||||||
|
final JsonObject richItemRenderer = video.getObject(RICH_ITEM_RENDERER);
|
||||||
|
if (richItemRenderer.has("content")) {
|
||||||
|
final JsonObject richItemRendererContent =
|
||||||
|
richItemRenderer.getObject("content");
|
||||||
|
if (richItemRendererContent.has(REEL_ITEM_RENDERER)) {
|
||||||
|
collector.commit(new YoutubeReelInfoItemExtractor(
|
||||||
|
richItemRendererContent.getObject(REEL_ITEM_RENDERER),
|
||||||
|
timeAgoParser));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
Loading…
x
Reference in New Issue
Block a user