NewPipe/app/src/test/java/org/schabi/newpipe/extractor/services/youtube/youtube/YoutubeStreamExtractorRestr...

109 lines
3.4 KiB
Java
Raw Normal View History

2017-02-16 00:17:43 +01:00
package org.schabi.newpipe.extractor.services.youtube.youtube;
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;
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;
import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
2016-09-28 17:13:15 +02:00
import org.schabi.newpipe.extractor.stream_info.VideoStream;
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 {
public static final String HTTPS = "https://";
private StreamExtractor extractor;
2017-02-16 00:17:43 +01:00
@Before
2016-11-20 19:01:06 +01:00
public void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
2016-09-27 22:59:04 +02:00
extractor = NewPipe.getService("Youtube")
.getExtractorInstance("https://www.youtube.com/watch?v=i6JTvzrpBy0");
}
2017-02-16 00:17:43 +01:00
@Test
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")
.getExtractorInstance("https://youtu.be/FmG385_uUys?t=174");
assertTrue(Integer.toString(extractor.getTimeStamp()),
extractor.getTimeStamp() == 174);
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetAgeLimit() throws ParsingException {
assertTrue(extractor.getAgeLimit() == 18);
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetTitle() throws ParsingException {
assertTrue(!extractor.getTitle().isEmpty());
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetDescription() throws ParsingException {
assertTrue(extractor.getDescription() != null);
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetUploader() throws ParsingException {
assertTrue(!extractor.getUploader().isEmpty());
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetLength() throws ParsingException {
assertTrue(extractor.getLength() > 0);
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetViews() throws ParsingException {
assertTrue(extractor.getLength() > 0);
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetUploadDate() throws ParsingException {
assertTrue(extractor.getUploadDate().length() > 0);
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetThumbnailUrl() throws ParsingException {
assertTrue(extractor.getThumbnailUrl(),
extractor.getThumbnailUrl().contains(HTTPS));
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetUploaderThumbnailUrl() throws ParsingException {
assertTrue(extractor.getUploaderThumbnailUrl(),
extractor.getUploaderThumbnailUrl().contains(HTTPS));
}
2017-02-16 00:17:43 +01:00
@Test
public void testGetAudioStreams() throws ParsingException {
// audiostream not always necessary
//assertTrue(!extractor.getAudioStreams().isEmpty());
}
2017-02-16 00:17:43 +01:00
@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);
}
}
}