mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 11:02:35 +01:00
inital YoutubeExtractor test
This commit is contained in:
parent
cd3f405bff
commit
97c924341c
@ -2,8 +2,11 @@ package org.schabi.newpipe.services.youtube;
|
|||||||
|
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.VideoPreviewInfo;
|
||||||
import org.schabi.newpipe.services.SearchEngine;
|
import org.schabi.newpipe.services.SearchEngine;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by the-scrabi on 29.12.15.
|
* Created by the-scrabi on 29.12.15.
|
||||||
*
|
*
|
||||||
@ -25,18 +28,18 @@ import org.schabi.newpipe.services.SearchEngine;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class YoutubeSearchEngineTest extends AndroidTestCase {
|
public class YoutubeSearchEngineTest extends AndroidTestCase {
|
||||||
|
private SearchEngine.Result result;
|
||||||
SearchEngine engine;
|
private ArrayList<String> suggestionReply;
|
||||||
SearchEngine.Result result;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception{
|
public void setUp() throws Exception{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
engine = new YoutubeSearchEngine();
|
SearchEngine engine = new YoutubeSearchEngine();
|
||||||
result = engine.search("https://www.youtube.com/results?search_query=bla", 0, "de");
|
result = engine.search("https://www.youtube.com/results?search_query=bla", 0, "de");
|
||||||
|
suggestionReply = engine.suggestionList("hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfNoErrorOccure() {
|
public void testIfNoErrorOccur() {
|
||||||
assertEquals(result.errorMessage, "");
|
assertEquals(result.errorMessage, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,24 +47,43 @@ public class YoutubeSearchEngineTest extends AndroidTestCase {
|
|||||||
assertEquals(result.resultList.size() > 0, true);
|
assertEquals(result.resultList.size() > 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testItemHasTitle() {
|
public void testItemsHaveTitle() {
|
||||||
assertEquals(result.resultList.get(0).title.isEmpty(), false);
|
for(VideoPreviewInfo i : result.resultList) {
|
||||||
|
assertEquals(i.title.isEmpty(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testItemHasUploader() {
|
public void testItemsHaveUploader() {
|
||||||
assertEquals(result.resultList.get(0).uploader.isEmpty(), false);
|
for(VideoPreviewInfo i : result.resultList) {
|
||||||
|
assertEquals(i.uploader.isEmpty(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testItemHasRightDuration() {
|
public void testItemsHaveRightDuration() {
|
||||||
assertTrue(result.resultList.get(0).webpage_url,
|
for(VideoPreviewInfo i : result.resultList) {
|
||||||
result.resultList.get(0).webpage_url.contains(":")); }
|
assertTrue(i.duration, i.duration.contains(":"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testItemHasRightThumbnail() {
|
public void testItemsHaveRightThumbnail() {
|
||||||
assertTrue(result.resultList.get(0).webpage_url,
|
for (VideoPreviewInfo i : result.resultList) {
|
||||||
result.resultList.get(0).webpage_url.contains("https://")); }
|
assertTrue(i.thumbnail_url, i.thumbnail_url.contains("https://"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testItemHasRightVideoUrl() {
|
public void testItemsHaveRightVideoUrl() {
|
||||||
assertTrue(result.resultList.get(0).webpage_url,
|
for (VideoPreviewInfo i : result.resultList) {
|
||||||
result.resultList.get(0).webpage_url.contains("https://"));
|
assertTrue(i.webpage_url, i.webpage_url.contains("https://"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIfSuggestionsAreReplied() {
|
||||||
|
assertEquals(suggestionReply.size() > 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIfSuggestionsAreValid() {
|
||||||
|
for(String s : suggestionReply) {
|
||||||
|
assertTrue(s, !s.isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,100 @@
|
|||||||
|
package org.schabi.newpipe.services.youtube;
|
||||||
|
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.services.VideoInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by the-scrabi on 30.12.15.
|
||||||
|
*
|
||||||
|
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
||||||
|
* YoutubeVideoExtractorDefault.java is part of NewPipe.
|
||||||
|
*
|
||||||
|
* NewPipe is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* NewPipe is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class YoutubeVideoExtractorDefaultTest extends AndroidTestCase {
|
||||||
|
private YoutubeVideoExtractor extractor;
|
||||||
|
|
||||||
|
public void setUp() {
|
||||||
|
extractor = new YoutubeVideoExtractor("https://www.youtube.com/watch?v=FmG385_uUys");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetErrorCode() {
|
||||||
|
assertEquals(extractor.getErrorCode(), VideoInfo.NO_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetErrorMessage() {
|
||||||
|
assertEquals(extractor.getErrorMessage(), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetTimeStamp() {
|
||||||
|
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||||
|
extractor.getTimeStamp() >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetTitle() {
|
||||||
|
assertTrue(!extractor.getTitle().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetDescription() {
|
||||||
|
assertTrue(extractor.getDescription() != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetUploader() {
|
||||||
|
assertTrue(!extractor.getUploader().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetLength() {
|
||||||
|
assertTrue(extractor.getLength() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetViews() {
|
||||||
|
assertTrue(extractor.getLength() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetUploadDate() {
|
||||||
|
assertTrue(extractor.getUploadDate().length() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetThumbnailUrl() {
|
||||||
|
assertTrue(extractor.getThumbnailUrl(),
|
||||||
|
extractor.getThumbnailUrl().contains("https://"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetUploaderThumbnailUrl() {
|
||||||
|
assertTrue(extractor.getUploaderThumbnailUrl(),
|
||||||
|
extractor.getUploaderThumbnailUrl().contains("https://"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetAudioStreams() {
|
||||||
|
for(VideoInfo.AudioStream s : extractor.getAudioStreams()) {
|
||||||
|
assertTrue(s.url,
|
||||||
|
s.url.contains("https://"));
|
||||||
|
assertTrue(s.bandwidth > 0);
|
||||||
|
assertTrue(s.samplingRate > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetVideoStreams() {
|
||||||
|
for(VideoInfo.VideoStream s : extractor.getVideoStreams()) {
|
||||||
|
assertTrue(s.url,
|
||||||
|
s.url.contains("https://"));
|
||||||
|
assertTrue(s.resolution.length() > 0);
|
||||||
|
assertTrue(Integer.toString(s.format),
|
||||||
|
0 <= s.format && s.format <= 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package org.schabi.newpipe.services.youtube;
|
||||||
|
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.services.VideoInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by the-scrabi on 30.12.15.
|
||||||
|
*
|
||||||
|
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
||||||
|
* YoutubeVideoExtractorGema.java is part of NewPipe.
|
||||||
|
*
|
||||||
|
* NewPipe is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* NewPipe is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class YoutubeVideoExtractorGemaTest extends AndroidTestCase {
|
||||||
|
|
||||||
|
private YoutubeVideoExtractor extractor;
|
||||||
|
|
||||||
|
public void setUp() {
|
||||||
|
extractor = new YoutubeVideoExtractor("https://www.youtube.com/watch?v=3O1_3zBUKM8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetErrorCode() {
|
||||||
|
assertEquals(extractor.getErrorCode(), VideoInfo.ERROR_BLOCKED_BY_GEMA);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetErrorMessage() {
|
||||||
|
assertTrue(extractor.getErrorMessage(),
|
||||||
|
extractor.getErrorMessage().contains("GEMA"));
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.services.MediaFormat;
|
||||||
import org.schabi.newpipe.services.VideoInfo;
|
import org.schabi.newpipe.services.VideoInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package org.schabi.newpipe;
|
package org.schabi.newpipe.services;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Adam Howard on 08/11/15.
|
* Created by Adam Howard on 08/11/15.
|
@ -107,19 +107,22 @@ public abstract class VideoExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected abstract int getErrorCode();
|
public abstract int getErrorCode();
|
||||||
protected abstract String getErrorMessage();
|
public abstract String getErrorMessage();
|
||||||
protected abstract String getVideoUrl(String videoId);
|
|
||||||
protected abstract String getVideoId(String siteUrl);
|
//todo: remove these functions, or make them static, otherwise its useles, to have them here
|
||||||
protected abstract int getTimeStamp();
|
public abstract String getVideoUrl(String videoId);
|
||||||
protected abstract String getTitle();
|
public abstract String getVideoId(String siteUrl);
|
||||||
protected abstract String getDescription();
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
protected abstract String getUploader();
|
public abstract int getTimeStamp();
|
||||||
protected abstract int getLength();
|
public abstract String getTitle();
|
||||||
protected abstract long getViews();
|
public abstract String getDescription();
|
||||||
protected abstract String getUploadDate();
|
public abstract String getUploader();
|
||||||
protected abstract String getThumbnailUrl();
|
public abstract int getLength();
|
||||||
protected abstract String getUploaderThumbnailUrl();
|
public abstract long getViews();
|
||||||
protected abstract VideoInfo.AudioStream[] getAudioStreams();
|
public abstract String getUploadDate();
|
||||||
protected abstract VideoInfo.VideoStream[] getVideoStreams();
|
public abstract String getThumbnailUrl();
|
||||||
|
public abstract String getUploaderThumbnailUrl();
|
||||||
|
public abstract VideoInfo.AudioStream[] getAudioStreams();
|
||||||
|
public abstract VideoInfo.VideoStream[] getVideoStreams();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import org.mozilla.javascript.Function;
|
|||||||
import org.mozilla.javascript.ScriptableObject;
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
import org.schabi.newpipe.services.VideoExtractor;
|
import org.schabi.newpipe.services.VideoExtractor;
|
||||||
import org.schabi.newpipe.MediaFormat;
|
import org.schabi.newpipe.services.MediaFormat;
|
||||||
import org.schabi.newpipe.services.VideoInfo;
|
import org.schabi.newpipe.services.VideoInfo;
|
||||||
import org.schabi.newpipe.VideoPreviewInfo;
|
import org.schabi.newpipe.VideoPreviewInfo;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
Loading…
Reference in New Issue
Block a user