From 30751bc45b0f509b07fd58be0077efde1b77ac00 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sun, 21 Jul 2024 09:11:02 +0200 Subject: [PATCH] Fix avatar,banner and description extraction for channels when 'pageHeaderRenderer' style are used --- .../extractors/YoutubeChannelExtractor.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java index fb24254103..eebfac4803 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java @@ -205,12 +205,20 @@ public List getAvatars() throws ParsingException { return channelHeader.map(header -> { switch (header.headerType) { case PAGE: - return header.json.getObject("content") + final JsonObject image = header.json.getObject("content") .getObject("pageHeaderViewModel") + .getObject("image"); + if (image.has("contentPreviewImageViewModel")) { + return image.getObject("contentPreviewImageViewModel") .getObject("image") - .getObject("contentPreviewImageViewModel") + .getArray("sources"); + } else { + return image.getObject("decoratedAvatarViewModel") + .getObject("avatar") + .getObject("avatarViewModel") .getObject("image") .getArray("sources"); + } case INTERACTIVE_TABBED: return header.json.getObject("boxArt") @@ -235,10 +243,20 @@ public List getBanners() { return List.of(); } - // No banner is available on pageHeaderRenderer headers - return channelHeader.filter(header -> header.headerType != HeaderType.PAGE) - .map(header -> header.json.getObject("banner") - .getArray("thumbnails")) + return channelHeader.map(header -> { + switch (header.headerType) { + case PAGE: + return header.json.getObject("content") + .getObject("pageHeaderViewModel") + .getObject("banner") + .getObject("imageBannerViewModel") + .getObject("image") + .getArray("sources"); + default: + return header.json.getObject("banner") + .getArray("thumbnails"); + } + }) .map(YoutubeParsingHelper::getImagesFromThumbnailsArray) .orElse(List.of()); } @@ -303,11 +321,6 @@ public String getDescription() throws ParsingException { if (channelHeader.isPresent()) { final ChannelHeader header = channelHeader.get(); - if (header.headerType == HeaderType.PAGE) { - // A pageHeaderRenderer doesn't contain a description - return null; - } - if (header.headerType == HeaderType.INTERACTIVE_TABBED) { /* In an interactiveTabbedHeaderRenderer, the real description, is only available