Skip to content

Commit f52d226

Browse files
committed
[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.
1 parent 1690984 commit f52d226

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelHelper.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.defaultAlertsCheck;
1919
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
2020
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
21+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.hasArtistOrVerifiedIconBadgeAttachment;
2122
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
2223
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2324

@@ -363,27 +364,11 @@ public static boolean isChannelVerified(@Nonnull final ChannelHeader channelHead
363364
final JsonObject pageHeaderViewModel = channelHeader.json.getObject(CONTENT)
364365
.getObject(PAGE_HEADER_VIEW_MODEL);
365366

366-
final boolean hasCircleOrMusicIcon = pageHeaderViewModel.getObject(TITLE)
367-
.getObject("dynamicTextViewModel")
368-
.getObject("text")
369-
.getArray("attachmentRuns")
370-
.stream()
371-
.filter(JsonObject.class::isInstance)
372-
.map(JsonObject.class::cast)
373-
.anyMatch(attachmentRun -> attachmentRun.getObject("element")
374-
.getObject("type")
375-
.getObject("imageType")
376-
.getObject("image")
377-
.getArray("sources")
378-
.stream()
379-
.filter(JsonObject.class::isInstance)
380-
.map(JsonObject.class::cast)
381-
.anyMatch(source -> {
382-
final String imageName = source.getObject("clientResource")
383-
.getString("imageName");
384-
return "CHECK_CIRCLE_FILLED".equals(imageName)
385-
|| "MUSIC_FILLED".equals(imageName);
386-
}));
367+
final boolean hasCircleOrMusicIcon = hasArtistOrVerifiedIconBadgeAttachment(
368+
pageHeaderViewModel.getObject(TITLE)
369+
.getObject("dynamicTextViewModel")
370+
.getObject("text")
371+
.getArray("attachmentRuns"));
387372
if (!hasCircleOrMusicIcon && pageHeaderViewModel.getObject("image")
388373
.has("contentPreviewImageViewModel")) {
389374
// If a pageHeaderRenderer has no object in which a check verified may be

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,29 @@ public static boolean isVerified(final JsonArray badges) {
15841584
return false;
15851585
}
15861586

1587+
public static boolean hasArtistOrVerifiedIconBadgeAttachment(
1588+
@Nonnull final JsonArray attachmentRuns) {
1589+
return attachmentRuns.stream()
1590+
.filter(JsonObject.class::isInstance)
1591+
.map(JsonObject.class::cast)
1592+
.anyMatch(attachmentRun -> attachmentRun.getObject("element")
1593+
.getObject("type")
1594+
.getObject("imageType")
1595+
.getObject("image")
1596+
.getArray("sources")
1597+
.stream()
1598+
.filter(JsonObject.class::isInstance)
1599+
.map(JsonObject.class::cast)
1600+
.anyMatch(source -> {
1601+
final String imageName = source.getObject("clientResource")
1602+
.getString("imageName");
1603+
return "CHECK_CIRCLE_FILLED".equals(imageName)
1604+
|| "AUDIO_BADGE".equals(imageName)
1605+
|| "MUSIC_FILLED".equals(imageName);
1606+
}));
1607+
1608+
}
1609+
15871610
/**
15881611
* Generate a content playback nonce (also called {@code cpn}), sent by YouTube clients in
15891612
* playback requests (and also for some clients, in the player request body).

0 commit comments

Comments
 (0)