2017-08-06 22:20:15 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube;
|
|
|
|
|
|
|
|
import org.junit.Before;
|
2017-11-25 01:10:04 +01:00
|
|
|
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;
|
2017-11-23 16:33:03 +01:00
|
|
|
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;
|
|
|
|
|
2017-11-25 01:10:04 +01:00
|
|
|
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://";
|
2017-11-25 01:10:04 +01:00
|
|
|
private YoutubeStreamExtractor extractor;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
NewPipe.init(Downloader.getInstance());
|
2017-11-25 01:10:04 +01:00
|
|
|
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
|
2017-11-25 01:10:04 +01:00
|
|
|
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 {
|
2017-11-25 01:10:04 +01:00
|
|
|
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 {
|
2017-11-25 01:10:04 +01:00
|
|
|
assertNotNull(extractor.getUploaderName());
|
|
|
|
assertFalse(extractor.getUploaderName().isEmpty());
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
2017-11-25 01:10:04 +01: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 {
|
2017-08-16 04:40:03 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-25 01:10:04 +01:00
|
|
|
// FIXME: 25.11.17 Are there no streams or are they not listed?
|
2017-11-25 01:56:37 +01:00
|
|
|
@Ignore
|
2017-08-06 22:20:15 +02:00
|
|
|
@Test
|
|
|
|
public void testGetAudioStreams() throws IOException, ExtractionException {
|
2017-11-25 01:10:04 +01:00
|
|
|
// audio streams are not always necessary
|
2017-11-25 01:56:37 +01:00
|
|
|
assertFalse(extractor.getAudioStreams().isEmpty());
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetVideoStreams() throws IOException, ExtractionException {
|
2017-08-08 17:01:50 +02:00
|
|
|
for (VideoStream s : extractor.getVideoStreams()) {
|
2017-11-11 12:17:14 +01:00
|
|
|
assertTrue(s.getUrl(),
|
|
|
|
s.getUrl().contains(HTTPS));
|
2017-08-06 22:20:15 +02:00
|
|
|
assertTrue(s.resolution.length() > 0);
|
2017-11-11 12:17:14 +01:00
|
|
|
assertTrue(Integer.toString(s.getFormatId()),
|
|
|
|
0 <= s.getFormatId() && s.getFormatId() <= 4);
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-22 18:39:38 +01:00
|
|
|
|
2017-11-23 16:33:03 +01:00
|
|
|
|
|
|
|
@Test
|
2017-11-24 13:57:54 +01:00
|
|
|
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
|
2017-11-23 16:33:03 +01:00
|
|
|
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
2017-11-25 02:20:16 +01:00
|
|
|
assertNull(extractor.getSubtitlesDefault());
|
2017-11-23 16:33:03 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 18:39:38 +01:00
|
|
|
@Test
|
2017-11-24 13:57:54 +01:00
|
|
|
public void testGetSubtitlesList() throws IOException, ExtractionException {
|
2017-11-23 16:33:03 +01:00
|
|
|
// 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-11-22 18:39:38 +01:00
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|