2017-02-16 00:17:43 +01:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.youtube;
|
2016-02-21 18:25:18 +01:00
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2016-11-20 19:01:06 +01:00
|
|
|
import org.schabi.newpipe.Downloader;
|
2016-09-27 22:59:04 +02:00
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
2016-11-18 23:52:17 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2017-02-16 00:17:43 +01:00
|
|
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamUrlIdHandler;
|
2016-11-18 23:52:17 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
|
2016-09-28 17:13:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream_info.VideoStream;
|
2016-02-21 18:25:18 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
import static junit.framework.Assert.assertTrue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for {@link YoutubeStreamUrlIdHandler}
|
|
|
|
*/
|
|
|
|
public class YoutubeStreamExtractorRestrictedTest {
|
2016-06-24 11:54:18 +02:00
|
|
|
public static final String HTTPS = "https://";
|
2016-03-04 13:36:06 +01:00
|
|
|
private StreamExtractor extractor;
|
2016-02-21 18:25:18 +01:00
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Before
|
2016-11-20 19:01:06 +01:00
|
|
|
public void setUp() throws Exception {
|
2016-12-24 17:11:29 +01:00
|
|
|
NewPipe.init(Downloader.getInstance());
|
2016-09-27 22:59:04 +02:00
|
|
|
extractor = NewPipe.getService("Youtube")
|
2016-11-18 23:52:17 +01:00
|
|
|
.getExtractorInstance("https://www.youtube.com/watch?v=i6JTvzrpBy0");
|
2016-02-21 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetInvalidTimeStamp() throws ParsingException {
|
|
|
|
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
|
|
|
extractor.getTimeStamp() <= 0);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-22 19:17:05 +01:00
|
|
|
public void testGetValidTimeStamp() throws ExtractionException, IOException {
|
2016-09-27 22:59:04 +02:00
|
|
|
StreamExtractor extractor= NewPipe.getService("Youtube")
|
2016-11-18 23:52:17 +01:00
|
|
|
.getExtractorInstance("https://youtu.be/FmG385_uUys?t=174");
|
2016-02-21 18:25:18 +01:00
|
|
|
assertTrue(Integer.toString(extractor.getTimeStamp()),
|
|
|
|
extractor.getTimeStamp() == 174);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:45:28 +01:00
|
|
|
public void testGetAgeLimit() throws ParsingException {
|
|
|
|
assertTrue(extractor.getAgeLimit() == 18);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetTitle() throws ParsingException {
|
|
|
|
assertTrue(!extractor.getTitle().isEmpty());
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetDescription() throws ParsingException {
|
|
|
|
assertTrue(extractor.getDescription() != null);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetUploader() throws ParsingException {
|
|
|
|
assertTrue(!extractor.getUploader().isEmpty());
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetLength() throws ParsingException {
|
|
|
|
assertTrue(extractor.getLength() > 0);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetViews() throws ParsingException {
|
|
|
|
assertTrue(extractor.getLength() > 0);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetUploadDate() throws ParsingException {
|
|
|
|
assertTrue(extractor.getUploadDate().length() > 0);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetThumbnailUrl() throws ParsingException {
|
|
|
|
assertTrue(extractor.getThumbnailUrl(),
|
2016-06-24 11:54:18 +02:00
|
|
|
extractor.getThumbnailUrl().contains(HTTPS));
|
2016-02-21 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetUploaderThumbnailUrl() throws ParsingException {
|
|
|
|
assertTrue(extractor.getUploaderThumbnailUrl(),
|
2016-06-24 11:54:18 +02:00
|
|
|
extractor.getUploaderThumbnailUrl().contains(HTTPS));
|
2016-02-21 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetAudioStreams() throws ParsingException {
|
2016-11-18 23:52:17 +01:00
|
|
|
// audiostream not always necessary
|
|
|
|
//assertTrue(!extractor.getAudioStreams().isEmpty());
|
2016-02-21 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 00:17:43 +01:00
|
|
|
@Test
|
2016-02-21 18:25:18 +01:00
|
|
|
public void testGetVideoStreams() throws ParsingException {
|
2016-03-04 13:36:06 +01:00
|
|
|
for(VideoStream s : extractor.getVideoStreams()) {
|
2016-02-21 18:25:18 +01:00
|
|
|
assertTrue(s.url,
|
2016-06-24 11:54:18 +02:00
|
|
|
s.url.contains(HTTPS));
|
2016-02-21 18:25:18 +01:00
|
|
|
assertTrue(s.resolution.length() > 0);
|
|
|
|
assertTrue(Integer.toString(s.format),
|
|
|
|
0 <= s.format && s.format <= 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|