From f52d2269fcdd5af350bf462650b83023a2524d2c Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sun, 10 Nov 2024 20:18:04 +0100 Subject: [PATCH] [YouTube] Move channel verified status check from badges to a method This method will be used in more places such as the new playlist item data. Support for a new icon used in artist channels has been also added. --- .../youtube/YoutubeChannelHelper.java | 27 +++++-------------- .../youtube/YoutubeParsingHelper.java | 23 ++++++++++++++++ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java index 54d29032e..5eb852b0b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java @@ -18,6 +18,7 @@ import java.util.Optional; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.defaultAlertsCheck; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.hasArtistOrVerifiedIconBadgeAttachment; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; @@ -363,27 +364,11 @@ public final class YoutubeChannelHelper { final JsonObject pageHeaderViewModel = channelHeader.json.getObject(CONTENT) .getObject(PAGE_HEADER_VIEW_MODEL); - final boolean hasCircleOrMusicIcon = pageHeaderViewModel.getObject(TITLE) - .getObject("dynamicTextViewModel") - .getObject("text") - .getArray("attachmentRuns") - .stream() - .filter(JsonObject.class::isInstance) - .map(JsonObject.class::cast) - .anyMatch(attachmentRun -> attachmentRun.getObject("element") - .getObject("type") - .getObject("imageType") - .getObject("image") - .getArray("sources") - .stream() - .filter(JsonObject.class::isInstance) - .map(JsonObject.class::cast) - .anyMatch(source -> { - final String imageName = source.getObject("clientResource") - .getString("imageName"); - return "CHECK_CIRCLE_FILLED".equals(imageName) - || "MUSIC_FILLED".equals(imageName); - })); + final boolean hasCircleOrMusicIcon = hasArtistOrVerifiedIconBadgeAttachment( + pageHeaderViewModel.getObject(TITLE) + .getObject("dynamicTextViewModel") + .getObject("text") + .getArray("attachmentRuns")); if (!hasCircleOrMusicIcon && pageHeaderViewModel.getObject("image") .has("contentPreviewImageViewModel")) { // If a pageHeaderRenderer has no object in which a check verified may be diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index c0aee17cc..f514b61d6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -1584,6 +1584,29 @@ public final class YoutubeParsingHelper { return false; } + public static boolean hasArtistOrVerifiedIconBadgeAttachment( + @Nonnull final JsonArray attachmentRuns) { + return attachmentRuns.stream() + .filter(JsonObject.class::isInstance) + .map(JsonObject.class::cast) + .anyMatch(attachmentRun -> attachmentRun.getObject("element") + .getObject("type") + .getObject("imageType") + .getObject("image") + .getArray("sources") + .stream() + .filter(JsonObject.class::isInstance) + .map(JsonObject.class::cast) + .anyMatch(source -> { + final String imageName = source.getObject("clientResource") + .getString("imageName"); + return "CHECK_CIRCLE_FILLED".equals(imageName) + || "AUDIO_BADGE".equals(imageName) + || "MUSIC_FILLED".equals(imageName); + })); + + } + /** * Generate a content playback nonce (also called {@code cpn}), sent by YouTube clients in * playback requests (and also for some clients, in the player request body).