mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-11-08 11:13:00 +00:00
Update extractor and refactored NewPipe
This commit is contained in:
@@ -1,108 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger on 12.09.16.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
||||
* YoutubeSearchEngineStreamTest.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for {@link ChannelExtractor}
|
||||
*/
|
||||
|
||||
public class YoutubeChannelExtractorTest {
|
||||
|
||||
ChannelExtractor extractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = NewPipe.getService("Youtube")
|
||||
.getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDownloader() throws Exception {
|
||||
assertNotNull(NewPipe.getDownloader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetChannelName() throws Exception {
|
||||
assertEquals(extractor.getChannelName(), "Gronkh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvatarUrl() throws Exception {
|
||||
assertTrue(extractor.getAvatarUrl(), extractor.getAvatarUrl().contains("yt3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBannerurl() throws Exception {
|
||||
assertTrue(extractor.getBannerUrl(), extractor.getBannerUrl().contains("yt3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFeedUrl() throws Exception {
|
||||
assertTrue(extractor.getFeedUrl(), extractor.getFeedUrl().contains("feed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreams() throws Exception {
|
||||
assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreamsErrors() throws Exception {
|
||||
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasNextPage() throws Exception {
|
||||
// this particular example (link) has a next page !!!
|
||||
assertTrue("no next page link found", extractor.hasNextPage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubscriberCount() throws Exception {
|
||||
assertTrue("wrong subscriber count", extractor.getSubscriberCount() >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextPage() throws Exception {
|
||||
extractor = NewPipe.getService("Youtube")
|
||||
.getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 1);
|
||||
assertTrue("next page didn't have content", !extractor.getStreams().getItemList().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextNextPageUrl() throws Exception {
|
||||
extractor = NewPipe.getService("Youtube")
|
||||
.getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 2);
|
||||
assertTrue("next page didn't have content", extractor.hasNextPage());
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
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.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger on 29.12.15.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
||||
* YoutubeSearchEngineStreamTest.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class YoutubeSearchEngineAllTest {
|
||||
private SearchResult result;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SearchEngine engine = NewPipe.getService("Youtube").getSearchEngineInstance();
|
||||
|
||||
result = engine.search("asdf", 0, "de",
|
||||
EnumSet.of(SearchEngine.Filter.CHANNEL,
|
||||
SearchEngine.Filter.STREAM)).getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
assertTrue(result.suggestion != null);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
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.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger on 29.12.15.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
||||
* YoutubeSearchEngineStreamTest.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class YoutubeSearchEngineChannelTest {
|
||||
private SearchResult result;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SearchEngine engine = NewPipe.getService("Youtube").getSearchEngineInstance();
|
||||
|
||||
result = engine.search("gronkh", 0, "de",
|
||||
EnumSet.of(SearchEngine.Filter.CHANNEL)).getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelItemType() {
|
||||
assertEquals(result.resultList.get(0).infoType(), InfoItem.InfoType.CHANNEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
assertTrue(result.suggestion != null);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
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.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger on 29.12.15.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
||||
* YoutubeSearchEngineStreamTest.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class YoutubeSearchEngineStreamTest {
|
||||
private SearchResult result;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SearchEngine engine = NewPipe.getService("Youtube").getSearchEngineInstance();
|
||||
|
||||
result = engine.search("this is something boring", 0, "de",
|
||||
EnumSet.of(SearchEngine.Filter.STREAM)).getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelItemType() {
|
||||
assertEquals(result.resultList.get(0).infoType(), InfoItem.InfoType.STREAM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertTrue(result.errors == null || result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
//todo write a real test
|
||||
assertTrue(result.suggestion != null);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.SuggestionExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeSuggestionExtractor;
|
||||
import java.util.List;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger on 18.11.16.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
||||
* YoutubeSearchResultTest.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for {@link SuggestionExtractor}
|
||||
*/
|
||||
public class YoutubeSearchResultTest {
|
||||
List<String> suggestionReply;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SuggestionExtractor engine = new YoutubeSuggestionExtractor(0);
|
||||
suggestionReply = engine.suggestionList("hello", "de");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfSuggestions() {
|
||||
assertFalse(suggestionReply.isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.AbstractStreamInfo;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream_info.VideoStream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for {@link StreamExtractor}
|
||||
*/
|
||||
public class YoutubeStreamExtractorDefaultTest {
|
||||
public static final String HTTPS = "https://";
|
||||
private StreamExtractor extractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = NewPipe.getService("Youtube")
|
||||
.getExtractorInstance("https://www.youtube.com/watch?v=YQHsXMglC9A");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInvalidTimeStamp() throws ParsingException {
|
||||
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||
extractor.getTimeStamp() <= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValidTimeStamp() throws ExtractionException, IOException {
|
||||
StreamExtractor extractor =
|
||||
NewPipe.getService("Youtube")
|
||||
.getExtractorInstance("https://youtu.be/FmG385_uUys?t=174");
|
||||
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||
extractor.getTimeStamp() == 174);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTitle() throws ParsingException {
|
||||
assertTrue(!extractor.getTitle().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDescription() throws ParsingException {
|
||||
assertTrue(extractor.getDescription() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploader() throws ParsingException {
|
||||
assertTrue(!extractor.getUploader().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLength() throws ParsingException {
|
||||
assertTrue(extractor.getLength() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetViewCount() throws ParsingException {
|
||||
assertTrue(Long.toString(extractor.getViewCount()),
|
||||
extractor.getViewCount() > /* specific to that video */ 1224000074);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploadDate() throws ParsingException {
|
||||
assertTrue(extractor.getUploadDate().length() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetChannelUrl() throws ParsingException {
|
||||
assertTrue(extractor.getChannelUrl().length() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThumbnailUrl() throws ParsingException {
|
||||
assertTrue(extractor.getThumbnailUrl(),
|
||||
extractor.getThumbnailUrl().contains(HTTPS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploaderThumbnailUrl() throws ParsingException {
|
||||
assertTrue(extractor.getUploaderThumbnailUrl(),
|
||||
extractor.getUploaderThumbnailUrl().contains(HTTPS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAudioStreams() throws ParsingException {
|
||||
assertTrue(!extractor.getAudioStreams().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVideoStreams() throws ParsingException {
|
||||
for(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);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamType() throws ParsingException {
|
||||
assertTrue(extractor.getStreamType() == AbstractStreamInfo.StreamType.VIDEO_STREAM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDashMpd() throws ParsingException {
|
||||
assertTrue(extractor.getDashMpdUrl(),
|
||||
extractor.getDashMpdUrl() != null || !extractor.getDashMpdUrl().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
|
||||
import java.io.IOException;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by Christian Schabesberger 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/>.
|
||||
*/
|
||||
|
||||
|
||||
// This class only works in Germany.
|
||||
/**
|
||||
* Test for {@link YoutubeStreamExtractor}
|
||||
*/
|
||||
public class YoutubeStreamExtractorGemaTest {
|
||||
|
||||
// Deaktivate this Test Case bevore uploading it githup, otherwise CI will fail.
|
||||
private static final boolean testActive = false;
|
||||
|
||||
@Test
|
||||
public void testGemaError() throws IOException, ExtractionException {
|
||||
if(testActive) {
|
||||
try {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
NewPipe.getService("Youtube")
|
||||
.getExtractorInstance("https://www.youtube.com/watch?v=3O1_3zBUKM8");
|
||||
} catch(YoutubeStreamExtractor.GemaException ge) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamUrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
|
||||
import org.schabi.newpipe.extractor.stream_info.VideoStream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test for {@link YoutubeStreamUrlIdHandler}
|
||||
*/
|
||||
public class YoutubeStreamExtractorRestrictedTest {
|
||||
public static final String HTTPS = "https://";
|
||||
private StreamExtractor extractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = NewPipe.getService("Youtube")
|
||||
.getExtractorInstance("https://www.youtube.com/watch?v=i6JTvzrpBy0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInvalidTimeStamp() throws ParsingException {
|
||||
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||
extractor.getTimeStamp() <= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValidTimeStamp() throws ExtractionException, IOException {
|
||||
StreamExtractor extractor= NewPipe.getService("Youtube")
|
||||
.getExtractorInstance("https://youtu.be/FmG385_uUys?t=174");
|
||||
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
||||
extractor.getTimeStamp() == 174);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAgeLimit() throws ParsingException {
|
||||
assertTrue(extractor.getAgeLimit() == 18);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTitle() throws ParsingException {
|
||||
assertTrue(!extractor.getTitle().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDescription() throws ParsingException {
|
||||
assertTrue(extractor.getDescription() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploader() throws ParsingException {
|
||||
assertTrue(!extractor.getUploader().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLength() throws ParsingException {
|
||||
assertTrue(extractor.getLength() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetViews() throws ParsingException {
|
||||
assertTrue(extractor.getLength() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploadDate() throws ParsingException {
|
||||
assertTrue(extractor.getUploadDate().length() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThumbnailUrl() throws ParsingException {
|
||||
assertTrue(extractor.getThumbnailUrl(),
|
||||
extractor.getThumbnailUrl().contains(HTTPS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploaderThumbnailUrl() throws ParsingException {
|
||||
assertTrue(extractor.getUploaderThumbnailUrl(),
|
||||
extractor.getUploaderThumbnailUrl().contains(HTTPS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAudioStreams() throws ParsingException {
|
||||
// audiostream not always necessary
|
||||
//assertTrue(!extractor.getAudioStreams().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVideoStreams() throws ParsingException {
|
||||
for(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamUrlIdHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.fail;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test for {@link YoutubeStreamUrlIdHandler}
|
||||
*/
|
||||
public class YoutubeStreamUrlIdHandlerTest {
|
||||
private static String AD_URL = "https://googleads.g.doubleclick.net/aclk?sa=l&ai=C-2IPgeVTWPf4GcOStgfOnIOADf78n61GvKmmobYDrgIQASDj-5MDKAJg9ZXOgeAEoAGgy_T-A8gBAakC2gkpmquIsT6oAwGqBJMBT9BgD5kVgbN0dX602bFFaDw9vsxq-We-S8VkrXVBi6W_e7brZ36GCz1WO3EPEeklYuJjXLUowwCOKsd-8xr1UlS_tusuFJv9iX35xoBHKTRvs8-0aDbfEIm6in37QDfFuZjqgEMB8-tg0Jn_Pf1RU5OzbuU40B4Gy25NUTnOxhDKthOhKBUSZEksCEerUV8GMu10iAXCxquwApIFBggDEAEYAaAGGsgGlIjthrUDgAfItIsBqAemvhvYBwHSCAUIgGEQAbgT6AE&num=1&sig=AOD64_1DybDd4qAm5O7o9UAbTNRdqXXHFQ&ctype=21&video_id=dMO_IXYPZew&client=ca-pub-6219811747049371&adurl=http://www.youtube.com/watch%3Fv%3DdMO_IXYPZew";
|
||||
private YoutubeStreamUrlIdHandler urlIdHandler;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
urlIdHandler = YoutubeStreamUrlIdHandler.getInstance();
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void getIdWithNullAsUrl() throws ParsingException {
|
||||
urlIdHandler.getId(null);
|
||||
}
|
||||
|
||||
@Test(expected = FoundAdException.class)
|
||||
public void getIdForAd() throws ParsingException {
|
||||
urlIdHandler.getId(AD_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdForInvalidUrls() throws ParsingException {
|
||||
List<String> invalidUrls = new ArrayList<>(50);
|
||||
invalidUrls.add("https://www.youtube.com/watch?v=jZViOEv90d");
|
||||
invalidUrls.add("https://www.youtube.com/watchjZViOEv90d");
|
||||
invalidUrls.add("https://www.youtube.com/");
|
||||
for(String invalidUrl: invalidUrls) {
|
||||
Throwable exception = null;
|
||||
try {
|
||||
urlIdHandler.getId(invalidUrl);
|
||||
} catch (ParsingException e) {
|
||||
exception = e;
|
||||
}
|
||||
if(exception == null) {
|
||||
fail("Expected ParsingException for url: " + invalidUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void getId() throws Exception {
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("https://www.youtube.com/watch?v=jZViOEv90dI"));
|
||||
assertEquals("W-fFHeTX70Q", urlIdHandler.getId("https://www.youtube.com/watch?v=W-fFHeTX70Q"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("https://www.youtube.com/watch?v=jZViOEv90dI?t=100"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("https://WWW.YouTube.com/watch?v=jZViOEv90dI?t=100"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("HTTPS://www.youtube.com/watch?v=jZViOEv90dI?t=100"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("https://youtu.be/jZViOEv90dI?t=9s"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("HTTPS://Youtu.be/jZViOEv90dI?t=9s"));
|
||||
assertEquals("uEJuoEs1UxY", urlIdHandler.getId("http://www.youtube.com/watch_popup?v=uEJuoEs1UxY"));
|
||||
assertEquals("uEJuoEs1UxY", urlIdHandler.getId("http://www.Youtube.com/watch_popup?v=uEJuoEs1UxY"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("https://www.youtube.com/embed/jZViOEv90dI"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("https://www.youtube-nocookie.com/embed/jZViOEv90dI"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("http://www.youtube.com/watch?v=jZViOEv90dI"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("http://youtube.com/watch?v=jZViOEv90dI"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("http://youtu.be/jZViOEv90dI?t=9s"));
|
||||
assertEquals("7_WWz2DSnT8", urlIdHandler.getId("https://youtu.be/7_WWz2DSnT8"));
|
||||
assertEquals("oy6NvWeVruY", urlIdHandler.getId("https://m.youtube.com/watch?v=oy6NvWeVruY"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("http://www.youtube.com/embed/jZViOEv90dI"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("http://www.Youtube.com/embed/jZViOEv90dI"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("http://www.youtube-nocookie.com/embed/jZViOEv90dI"));
|
||||
assertEquals("EhxJLojIE_o", urlIdHandler.getId("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI"));
|
||||
assertEquals("jZViOEv90dI", urlIdHandler.getId("vnd.youtube:jZViOEv90dI"));
|
||||
|
||||
// Shared links
|
||||
String sharedId = "7JIArTByb3E";
|
||||
String realId = "Q7JsK50NGaA";
|
||||
assertEquals(realId, urlIdHandler.getId("vnd.youtube://www.YouTube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link"));
|
||||
assertEquals(realId, urlIdHandler.getId("vnd.youtube://www.youtube.com/shared?ci=" + sharedId ));
|
||||
assertEquals(realId, urlIdHandler.getId("https://www.youtube.com/shared?ci=7JIArTByb3E"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAcceptUrl() {
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/watch?v=jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/watch?v=jZViOEv90dI?t=100"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://WWW.YouTube.com/watch?v=jZViOEv90dI?t=100"));
|
||||
assertTrue(urlIdHandler.acceptUrl("HTTPS://www.youtube.com/watch?v=jZViOEv90dI?t=100"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://youtu.be/jZViOEv90dI?t=9s"));
|
||||
//assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/watch/jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/embed/jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.youtube-nocookie.com/embed/jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://www.youtube.com/watch?v=jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://youtu.be/jZViOEv90dI?t=9s"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://www.youtube.com/embed/jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare"));
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI"));
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube:jZViOEv90dI"));
|
||||
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube:jZViOEv90dI"));
|
||||
|
||||
String sharedId = "8A940MXKFmQ";
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link"));
|
||||
assertTrue(urlIdHandler.acceptUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId ));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/shared?ci=" + sharedId));
|
||||
}
|
||||
}
|
||||
199
app/src/test/java/org/schabi/newpipe/util/ListHelperTest.java
Normal file
199
app/src/test/java/org/schabi/newpipe/util/ListHelperTest.java
Normal file
@@ -0,0 +1,199 @@
|
||||
package org.schabi.newpipe.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ListHelperTest {
|
||||
private static final String BEST_RESOLUTION_KEY = "best_resolution";
|
||||
private static final List<AudioStream> audioStreamsTestList = Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.MP3.id, /**/ 64),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 128),
|
||||
new AudioStream("", MediaFormat.MP3.id, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 64),
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 320),
|
||||
new AudioStream("", MediaFormat.MP3.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 320));
|
||||
|
||||
private static final List<VideoStream> videoStreamsTestList = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "720p"),
|
||||
new VideoStream("", MediaFormat.v3GPP.id, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.WEBM.id, /**/ "480p"),
|
||||
new VideoStream("", MediaFormat.v3GPP.id, /**/ "144p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.WEBM.id, /**/ "360p"));
|
||||
|
||||
private static final List<VideoStream> videoOnlyStreamsTestList = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "720p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "720p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "2160p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "1440p60", true),
|
||||
new VideoStream("", MediaFormat.WEBM.id, /**/ "720p60", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "2160p60", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "720p60", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "1080p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "1080p60", true));
|
||||
|
||||
@Test
|
||||
public void getSortedStreamVideosListTest() throws Exception {
|
||||
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true, videoStreamsTestList, videoOnlyStreamsTestList, true);
|
||||
|
||||
List<String> expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
//for (VideoStream videoStream : result) System.out.println(videoStream.resolution + " > " + MediaFormat.getSuffixById(videoStream.format) + " > " + videoStream.isVideoOnly);
|
||||
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(result.get(i).resolution, expected.get(i));
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// Reverse Order //
|
||||
//////////////////
|
||||
|
||||
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true, videoStreamsTestList, videoOnlyStreamsTestList, false);
|
||||
expected = Arrays.asList("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) assertEquals(result.get(i).resolution, expected.get(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSortedStreamVideosExceptHighResolutionsTest() throws Exception {
|
||||
////////////////////////////////////
|
||||
// Don't show Higher resolutions //
|
||||
//////////////////////////////////
|
||||
|
||||
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, false, videoStreamsTestList, videoOnlyStreamsTestList, false);
|
||||
List<String> expected = Arrays.asList("1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) assertEquals(result.get(i).resolution, expected.get(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultResolutionTest() throws Exception {
|
||||
List<VideoStream> testList = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "720p"),
|
||||
new VideoStream("", MediaFormat.v3GPP.id, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.WEBM.id, /**/ "480p"),
|
||||
new VideoStream("", MediaFormat.WEBM.id, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.WEBM.id, /**/ "144p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4.id, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.WEBM.id, /**/ "360p"));
|
||||
VideoStream result = testList.get(ListHelper.getDefaultResolutionIndex("720p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4.id, result.format);
|
||||
|
||||
// Have resolution and the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("480p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM.id, result.format);
|
||||
|
||||
// Have resolution but not the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("480p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM.id, result.format);
|
||||
|
||||
// Have resolution and the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("240p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("240p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM.id, result.format);
|
||||
|
||||
// The best resolution
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(BEST_RESOLUTION_KEY, BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4.id, result.format);
|
||||
|
||||
// Doesn't have the 60fps variant and format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("720p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4.id, result.format);
|
||||
|
||||
// Doesn't have the 60fps variant
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("480p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM.id, result.format);
|
||||
|
||||
// Doesn't have the resolution, will return the best one
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("2160p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4.id, result.format);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioTest() throws Exception {
|
||||
assertEquals(320, ListHelper.getHighestQualityAudio(audioStreamsTestList).average_bitrate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioFormatTest() throws Exception {
|
||||
AudioStream stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.M4A, audioStreamsTestList));
|
||||
assertEquals(320, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.M4A.id, stream.format);
|
||||
|
||||
stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.WEBMA, audioStreamsTestList));
|
||||
assertEquals(320, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.WEBMA.id, stream.format);
|
||||
|
||||
stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, audioStreamsTestList));
|
||||
assertEquals(192, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.MP3.id, stream.format);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioFormatPreferredAbsent() throws Exception {
|
||||
|
||||
//////////////////////////////////////////
|
||||
// Doesn't contain the preferred format //
|
||||
////////////////////////////////////////
|
||||
|
||||
List<AudioStream> testList = Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 192));
|
||||
// List doesn't contains this format, it should fallback to the highest bitrate audio no matter what format it is
|
||||
AudioStream stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
|
||||
assertEquals(192, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.WEBMA.id, stream.format);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Multiple not-preferred-formats and equal bitrates //
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
testList = new ArrayList<>(Arrays.asList(
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 192)));
|
||||
// List doesn't contains this format, it should fallback to the highest bitrate audio no matter what format it is
|
||||
// and as it have multiple with the same high value, the last one wins
|
||||
stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
|
||||
assertEquals(192, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.M4A.id, stream.format);
|
||||
|
||||
|
||||
// Again with a new element
|
||||
testList.add(new AudioStream("", MediaFormat.WEBMA.id, /**/ 192));
|
||||
stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
|
||||
assertEquals(192, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.WEBMA.id, stream.format);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioNull() throws Exception {
|
||||
assertEquals(-1, ListHelper.getHighestQualityAudioIndex(null, null));
|
||||
assertEquals(-1, ListHelper.getHighestQualityAudioIndex(null, new ArrayList<AudioStream>()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.schabi.newpipe.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.stream_info.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream_info.VideoStream;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class UtilsTest {
|
||||
private List<AudioStream> audioStreamsTestList = Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 120, 0, 0),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 190, 0, 0),
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 130, 0, 0),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 60, 0, 0),
|
||||
new AudioStream("", MediaFormat.M4A.id, /**/ 320, 0, 0),
|
||||
new AudioStream("", MediaFormat.WEBMA.id, /**/ 320, 0, 0));
|
||||
|
||||
private List<VideoStream> videoStreamsTestList = Arrays.asList(
|
||||
new VideoStream("", /**/ MediaFormat.MPEG_4.id, /**/ "720p"),
|
||||
new VideoStream("", /**/ MediaFormat.v3GPP.id, /**/ "240p"),
|
||||
new VideoStream("", /**/ MediaFormat.WEBM.id, /**/ "480p"),
|
||||
new VideoStream("", /**/ MediaFormat.v3GPP.id, /**/ "144p"),
|
||||
new VideoStream("", /**/ MediaFormat.MPEG_4.id, /**/ "360p"),
|
||||
new VideoStream("", /**/ MediaFormat.WEBM.id, /**/ "360p"));
|
||||
|
||||
private List<VideoStream> videoOnlyStreamsTestList = Arrays.asList(
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "720p"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "720p"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "2160p"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "1440p60"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.WEBM.id, /**/ "720p60"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "2160p60"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "720p60"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "1080p"),
|
||||
new VideoStream(true, "", /**/ MediaFormat.MPEG_4.id, /**/ "1080p60"));
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioTest() throws Exception {
|
||||
assertEquals(320, Utils.getHighestQualityAudio(audioStreamsTestList).avgBitrate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSortedStreamVideosListTest() throws Exception {
|
||||
List<VideoStream> result = Utils.getSortedStreamVideosList(MediaFormat.MPEG_4, true, videoStreamsTestList, videoOnlyStreamsTestList, true);
|
||||
|
||||
List<String> expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
//for (VideoStream videoStream : result) System.out.println(videoStream.resolution + " > " + MediaFormat.getSuffixById(videoStream.format) + " > " + videoStream.isVideoOnly);
|
||||
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(result.get(i).resolution, expected.get(i));
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// Reverse Order //
|
||||
//////////////////
|
||||
|
||||
result = Utils.getSortedStreamVideosList(MediaFormat.MPEG_4, true, videoStreamsTestList, videoOnlyStreamsTestList, false);
|
||||
|
||||
expected = Arrays.asList("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) assertEquals(result.get(i).resolution, expected.get(i));
|
||||
|
||||
////////////////////////////////////
|
||||
// Don't show Higher resolutions //
|
||||
//////////////////////////////////
|
||||
|
||||
result = Utils.getSortedStreamVideosList(MediaFormat.MPEG_4, false, videoStreamsTestList, videoOnlyStreamsTestList, false);
|
||||
expected = Arrays.asList("1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) assertEquals(result.get(i).resolution, expected.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user