From 3441aceba3016cba4eb0a7b7bc3011a56e452e1e Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 24 Feb 2016 16:44:46 +0100 Subject: [PATCH] fixed viewcount failure --- .../extractor/youtube/YoutubeSearchEngineTest.java | 9 ++++++++- .../youtube/YoutubeStreamExtractorDefaultTest.java | 7 ++++--- .../youtube/YoutubeStreamExtractorGemaTest.java | 2 +- .../org/schabi/newpipe/extractor/StreamExtractor.java | 2 +- .../java/org/schabi/newpipe/extractor/VideoInfo.java | 2 +- .../extractor/services/youtube/YoutubeSearchEngine.java | 5 ++++- .../services/youtube/YoutubeStreamExtractor.java | 4 ++-- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java index ea52539fb..a0c888f35 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.services.youtube; +package org.schabi.newpipe.extractor.youtube; import android.test.AndroidTestCase; @@ -82,9 +82,16 @@ public class YoutubeSearchEngineTest extends AndroidTestCase { } public void testViewCount() { + /* for(VideoPreviewInfo i : result.resultList) { assertTrue(Long.toString(i.view_count), i.view_count != -1); } + */ + // that specific link used for this test, there are no videos with less + // than 10.000 views, so we can test against that. + for(VideoPreviewInfo i : result.resultList) { + assertTrue(Long.toString(i.view_count), i.view_count >= 10000); + } } public void testIfSuggestionsAreReplied() { diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java index 7790acf29..4f4c529e5 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.services.youtube; +package org.schabi.newpipe.extractor.youtube; import android.test.AndroidTestCase; @@ -70,8 +70,9 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase { assertTrue(extractor.getLength() > 0); } - public void testGetViews() throws ParsingException { - assertTrue(extractor.getLength() > 0); + public void testGetViewCount() throws ParsingException { + assertTrue(Long.toString(extractor.getViewCount()), + extractor.getViewCount() > /* specific to that video */ 1224000074); } public void testGetUploadDate() throws ParsingException { diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java index a4bdec252..c6c8471a9 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.services.youtube; +package org.schabi.newpipe.extractor.youtube; import android.test.AndroidTestCase; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java index a9b8c8e3a..2fcea90c2 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java @@ -59,7 +59,7 @@ public interface StreamExtractor { public abstract String getDescription() throws ParsingException; public abstract String getUploader() throws ParsingException; public abstract int getLength() throws ParsingException; - public abstract long getViews() throws ParsingException; + public abstract long getViewCount() throws ParsingException; public abstract String getUploadDate() throws ParsingException; public abstract String getThumbnailUrl() throws ParsingException; public abstract String getUploaderThumbnailUrl() throws ParsingException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/VideoInfo.java index b4f1ae47b..2ae58a9f2 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/VideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/VideoInfo.java @@ -150,7 +150,7 @@ public class VideoInfo extends AbstractVideoInfo { videoInfo.addException(e); } try { - videoInfo.view_count = extractor.getViews(); + videoInfo.view_count = extractor.getViewCount(); } catch(Exception e) { videoInfo.addException(e); } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java index 4f24fb5bd..5165814bb 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java @@ -241,7 +241,10 @@ public class YoutubeSearchEngine implements SearchEngine { String input = item.select("div[class=\"yt-lockup-meta\"]").first() .select("li").get(1) .text(); - output = Parser.matchGroup1("([0-9,\\. ])", input).replace(" ", ""); + output = Parser.matchGroup1("([0-9,\\. ]*)", input) + .replace(" ", "") + .replace(".", "") + .replace(",", ""); return Long.parseLong(output); } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index fa4695298..bbb61a011 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -360,12 +360,12 @@ public class YoutubeStreamExtractor implements StreamExtractor { } @Override - public long getViews() throws ParsingException { + public long getViewCount() throws ParsingException { try { String viewCountString = doc.select("meta[itemprop=interactionCount]").attr("content"); return Long.parseLong(viewCountString); } catch (Exception e) {//todo: find fallback method - throw new ParsingException("failed to number of views", e); + throw new ParsingException("failed to get number of views", e); } }