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

107 lines
3.3 KiB
Java
Raw Normal View History

2017-08-06 22:20:15 +02:00
package org.schabi.newpipe.extractor.services.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.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.VideoStream;
import java.io.IOException;
2017-08-11 03:23:09 +02:00
import static org.junit.Assert.assertEquals;
2017-08-06 22:20:15 +02:00
import static org.junit.Assert.assertTrue;
2017-08-07 18:12:51 +02:00
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2017-08-06 22:20:15 +02:00
/**
* 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());
2017-08-07 18:12:51 +02:00
extractor = YouTube.getService()
2017-08-06 22:20:15 +02:00
.getStreamExtractor("https://www.youtube.com/watch?v=i6JTvzrpBy0");
}
@Test
public void testGetInvalidTimeStamp() throws ParsingException {
2017-08-11 03:23:09 +02:00
assertTrue(extractor.getTimeStamp() + "", extractor.getTimeStamp() <= 0);
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetValidTimeStamp() throws IOException, ExtractionException {
2017-08-11 03:23:09 +02:00
StreamExtractor extractor = YouTube.getService().getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
assertEquals(extractor.getTimeStamp() + "", "174");
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetAgeLimit() throws ParsingException {
assertTrue(extractor.getAgeLimit() == 18);
}
@Test
public void testGetTitle() throws ParsingException {
2017-08-11 03:23:09 +02:00
assertTrue(!extractor.getName().isEmpty());
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetDescription() throws ParsingException {
assertTrue(extractor.getDescription() != null);
}
@Test
2017-08-08 23:36:11 +02:00
public void testGetUploaderName() throws ParsingException {
assertTrue(!extractor.getUploaderName().isEmpty());
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetLength() throws ParsingException {
assertTrue(extractor.getLength() > 0);
}
@Test
public void testGetViews() throws ParsingException {
assertTrue(extractor.getViewCount() > 0);
2017-08-06 22:20:15 +02:00
}
@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
2017-08-08 23:36:11 +02:00
public void testGetUploaderAvatarUrl() throws ParsingException {
assertTrue(extractor.getUploaderAvatarUrl(),
extractor.getUploaderAvatarUrl().contains(HTTPS));
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetAudioStreams() throws IOException, ExtractionException {
// audiostream not always necessary
assertTrue(!extractor.getAudioStreams().isEmpty());
}
@Test
public void testGetVideoStreams() throws IOException, ExtractionException {
for (VideoStream s : extractor.getVideoStreams()) {
2017-08-06 22:20:15 +02:00
assertTrue(s.url,
s.url.contains(HTTPS));
assertTrue(s.resolution.length() > 0);
assertTrue(Integer.toString(s.format),
0 <= s.format && s.format <= 4);
}
}
}