From 5daabd1793c3b09259ec0c38ebccb335c9a7d680 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Tue, 22 Nov 2022 02:17:10 +0100 Subject: [PATCH 1/2] fix: #976 search subscriber count extraction with channel handles --- .../YoutubeChannelInfoItemExtractor.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java index 1193de76..a78a8a93 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java @@ -34,9 +34,26 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor { private final JsonObject channelInfoItem; + /** + * New layout: + * "subscriberCountText": Channel handle + * "videoCountText": Subscriber count + */ + private final boolean withHandle; public YoutubeChannelInfoItemExtractor(final JsonObject channelInfoItem) { this.channelInfoItem = channelInfoItem; + + boolean wHandle = false; + try { + final String subscriberCountText = getTextFromObject( + channelInfoItem.getObject("subscriberCountText")); + if (subscriberCountText != null) { + wHandle = subscriberCountText.startsWith("@"); + } + } catch (final ParsingException ignored) { + } + this.withHandle = wHandle; } @Override @@ -78,6 +95,11 @@ public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor return -1; } + if (withHandle) { + return Utils.mixedNumberWordToLong(getTextFromObject( + channelInfoItem.getObject("videoCountText"))); + } + return Utils.mixedNumberWordToLong(getTextFromObject( channelInfoItem.getObject("subscriberCountText"))); } catch (final Exception e) { @@ -88,7 +110,7 @@ public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor @Override public long getStreamCount() throws ParsingException { try { - if (!channelInfoItem.has("videoCountText")) { + if (withHandle || !channelInfoItem.has("videoCountText")) { // Video count is not available, channel probably has no public uploads. return ListExtractor.ITEM_COUNT_UNKNOWN; } From 016623131e28bc9a078e1fc3112dbdb843742fda Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Tue, 29 Nov 2022 19:06:03 +0100 Subject: [PATCH 2/2] docs: update comment in YoutubeChannelInfoItemExtractor --- .../youtube/extractors/YoutubeChannelInfoItemExtractor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java index a78a8a93..8d1720f6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java @@ -111,7 +111,8 @@ public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor public long getStreamCount() throws ParsingException { try { if (withHandle || !channelInfoItem.has("videoCountText")) { - // Video count is not available, channel probably has no public uploads. + // Video count is not available, either the channel has no public uploads + // or YouTube displays the channel handle instead. return ListExtractor.ITEM_COUNT_UNKNOWN; }