From 217d13b10280ab7685bea984b76618d826ad1560 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 11 Sep 2018 15:14:22 +0200 Subject: [PATCH] fix wrong subscription count --- .../YoutubeChannelInfoItemExtractor.java | 2 +- .../search/YoutubeSearchCountTest.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java 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 d62ce82d..9e0e975f 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 @@ -62,7 +62,7 @@ public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor final Element subsEl = el.select("span[class*=\"yt-subscriber-count\"]").first(); if (subsEl != null) { try { - return Long.parseLong(Utils.removeNonDigitCharacters(el.text())); + return Long.parseLong(Utils.removeNonDigitCharacters(subsEl.text())); } catch (NumberFormatException e) { throw new ParsingException("Could not get subscriber count", e); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java new file mode 100644 index 00000000..745b6a0a --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java @@ -0,0 +1,35 @@ +package org.schabi.newpipe.extractor.services.youtube.search; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.ChannelInfoItem; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor; +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory; + +import static java.util.Collections.singletonList; +import static junit.framework.TestCase.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + +public class YoutubeSearchCountTest { + public static class YoutubeChannelViewCountTest extends YoutubeSearchExtractorBaseTest { + @BeforeClass + public static void setUpClass() throws Exception { + NewPipe.init(Downloader.getInstance()); + extractor = (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie", + singletonList(YoutubeSearchQueryHandlerFactory.CHANNELS), null,"de"); + extractor.fetchPage(); + itemsPage = extractor.getInitialPage(); + } + + @Test + public void testViewCount() throws Exception { + boolean foundKnownChannel = false; + ChannelInfoItem ci = (ChannelInfoItem) itemsPage.getItems().get(0); + assertTrue("Count does not fit: " + Long.toString(ci.getSubscriberCount()), + 65043316 < ci.getSubscriberCount() && ci.getSubscriberCount() < 68043316); + } + } +}