Skip to content

Commit 896d7e0

Browse files
authored
Merge pull request #978 from Theta-Dev/fix/search-channel-handles
[YouTube] Fix search subscriber count extraction with channel handles
2 parents 41c8dce + 0166231 commit 896d7e0

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,26 @@
3434

3535
public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor {
3636
private final JsonObject channelInfoItem;
37+
/**
38+
* New layout:
39+
* "subscriberCountText": Channel handle
40+
* "videoCountText": Subscriber count
41+
*/
42+
private final boolean withHandle;
3743

3844
public YoutubeChannelInfoItemExtractor(final JsonObject channelInfoItem) {
3945
this.channelInfoItem = channelInfoItem;
46+
47+
boolean wHandle = false;
48+
try {
49+
final String subscriberCountText = getTextFromObject(
50+
channelInfoItem.getObject("subscriberCountText"));
51+
if (subscriberCountText != null) {
52+
wHandle = subscriberCountText.startsWith("@");
53+
}
54+
} catch (final ParsingException ignored) {
55+
}
56+
this.withHandle = wHandle;
4057
}
4158

4259
@Override
@@ -78,6 +95,11 @@ public long getSubscriberCount() throws ParsingException {
7895
return -1;
7996
}
8097

98+
if (withHandle) {
99+
return Utils.mixedNumberWordToLong(getTextFromObject(
100+
channelInfoItem.getObject("videoCountText")));
101+
}
102+
81103
return Utils.mixedNumberWordToLong(getTextFromObject(
82104
channelInfoItem.getObject("subscriberCountText")));
83105
} catch (final Exception e) {
@@ -88,8 +110,9 @@ public long getSubscriberCount() throws ParsingException {
88110
@Override
89111
public long getStreamCount() throws ParsingException {
90112
try {
91-
if (!channelInfoItem.has("videoCountText")) {
92-
// Video count is not available, channel probably has no public uploads.
113+
if (withHandle || !channelInfoItem.has("videoCountText")) {
114+
// Video count is not available, either the channel has no public uploads
115+
// or YouTube displays the channel handle instead.
93116
return ListExtractor.ITEM_COUNT_UNKNOWN;
94117
}
95118

0 commit comments

Comments
 (0)