Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0908b9cd76
7 changed files with 21 additions and 10 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.schabi.newpipe.services.youtube;
|
||||
package org.schabi.newpipe.extractor.youtube;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue