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

127 lines
4.2 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.Ignore;
2017-08-06 22:20:15 +02:00
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.SubtitlesFormat;
2017-08-06 22:20:15 +02:00
import org.schabi.newpipe.extractor.stream.VideoStream;
import java.io.IOException;
import static org.junit.Assert.*;
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 YoutubeStreamExtractor extractor;
2017-08-06 22:20:15 +02:00
@Before
public void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeStreamExtractor) 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 {
2017-11-25 03:13:26 +01:00
assertEquals(18, extractor.getAgeLimit());
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetName() throws ParsingException {
assertNotNull("name is null", extractor.getName());
assertFalse("name is empty", extractor.getName().isEmpty());
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
assertFalse(extractor.getDescription().isEmpty());
2017-08-06 22:20:15 +02:00
}
@Test
2017-08-08 23:36:11 +02:00
public void testGetUploaderName() throws ParsingException {
assertNotNull(extractor.getUploaderName());
assertFalse(extractor.getUploaderName().isEmpty());
2017-08-06 22:20:15 +02:00
}
@Ignore // Currently there is no way get the length from restricted videos
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
}
// FIXME: 25.11.17 Are there no streams or are they not listed?
@Ignore
2017-08-06 22:20:15 +02:00
@Test
public void testGetAudioStreams() throws IOException, ExtractionException {
// audio streams are not always necessary
assertFalse(extractor.getAudioStreams().isEmpty());
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetVideoStreams() throws IOException, ExtractionException {
for (VideoStream s : extractor.getVideoStreams()) {
assertTrue(s.getUrl(),
s.getUrl().contains(HTTPS));
2017-08-06 22:20:15 +02:00
assertTrue(s.resolution.length() > 0);
assertTrue(Integer.toString(s.getFormatId()),
0 <= s.getFormatId() && s.getFormatId() <= 4);
2017-08-06 22:20:15 +02:00
}
}
@Test
2017-11-24 13:57:54 +01:00
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
2017-11-25 02:20:16 +01:00
assertNull(extractor.getSubtitlesDefault());
}
@Test
2017-11-24 13:57:54 +01:00
public void testGetSubtitlesList() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
2017-11-25 02:20:16 +01:00
assertNull(extractor.getSubtitles(SubtitlesFormat.VTT));
}
2017-08-06 22:20:15 +02:00
}