Skip to content

Commit 0400ae0

Browse files
committed
Fix channels with subscription count disabled
Related: TeamNewPipe/NewPipe#1649
1 parent f6be85e commit 0400ae0

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import org.jsoup.Jsoup;
88
import org.jsoup.nodes.Document;
99
import org.jsoup.nodes.Element;
10-
import org.schabi.newpipe.extractor.*;
10+
import org.schabi.newpipe.extractor.Downloader;
11+
import org.schabi.newpipe.extractor.NewPipe;
12+
import org.schabi.newpipe.extractor.StreamingService;
1113
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
1214
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1315
import org.schabi.newpipe.extractor.exceptions.ParsingException;
16+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
1417
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1518
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
16-
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
1719
import org.schabi.newpipe.extractor.utils.DonationLinkHelper;
1820
import org.schabi.newpipe.extractor.utils.Parser;
1921
import org.schabi.newpipe.extractor.utils.Utils;
@@ -131,11 +133,16 @@ public String getFeedUrl() throws ParsingException {
131133

132134
@Override
133135
public long getSubscriberCount() throws ParsingException {
134-
Element el = doc.select("span[class*=\"yt-subscription-button-subscriber-count\"]").first();
136+
final Element el = doc.select("span[class*=\"yt-subscription-button-subscriber-count\"]").first();
135137
if (el != null) {
136-
return Long.parseLong(Utils.removeNonDigitCharacters(el.text()));
138+
try {
139+
return Long.parseLong(Utils.removeNonDigitCharacters(el.text()));
140+
} catch (NumberFormatException e) {
141+
throw new ParsingException("Could not get subscriber count", e);
142+
}
137143
} else {
138-
throw new ParsingException("Could not get subscriber count");
144+
// If the element is null, the channel have the subscriber count disabled
145+
return -1;
139146
}
140147
}
141148

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ public String getUrl() throws ParsingException {
5959

6060
@Override
6161
public long getSubscriberCount() throws ParsingException {
62-
Element subsEl = el.select("span[class*=\"yt-subscriber-count\"]").first();
63-
if (subsEl == null) {
64-
return 0;
62+
final Element subsEl = el.select("span[class*=\"yt-subscriber-count\"]").first();
63+
if (subsEl != null) {
64+
try {
65+
return Long.parseLong(Utils.removeNonDigitCharacters(el.text()));
66+
} catch (NumberFormatException e) {
67+
throw new ParsingException("Could not get subscriber count", e);
68+
}
6569
} else {
66-
return Long.parseLong(Utils.removeNonDigitCharacters(subsEl.text()));
70+
// If the element is null, the channel have the subscriber count disabled
71+
return -1;
6772
}
6873
}
6974

0 commit comments

Comments
 (0)