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

134 lines
4.6 KiB
Java
Raw Normal View History

2017-08-06 22:20:15 +02:00
package org.schabi.newpipe.extractor.services.youtube;
import org.junit.BeforeClass;
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.MediaFormat;
2017-08-06 22:20:15 +02:00
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2018-05-08 21:19:03 +02:00
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
2017-08-06 22:20:15 +02:00
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.VideoStream;
2018-09-15 21:47:53 +02:00
import org.schabi.newpipe.extractor.utils.Localization;
2017-08-06 22:20:15 +02:00
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
2017-08-06 22:20:15 +02:00
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
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 YoutubeStreamLinkHandlerFactory}
2017-08-06 22:20:15 +02:00
*/
public class YoutubeStreamExtractorAgeRestrictedTest {
2017-08-06 22:20:15 +02:00
public static final String HTTPS = "https://";
private static YoutubeStreamExtractor extractor;
2017-08-06 22:20:15 +02:00
@BeforeClass
public static void setUp() throws Exception {
2018-09-15 21:47:53 +02:00
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=MmBeUZqv1QA");
2017-11-28 13:37:01 +01:00
extractor.fetchPage();
2017-08-06 22:20:15 +02:00
}
@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 {
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
2017-08-11 03:23:09 +02:00
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
}
@Test
public void testGetLength() throws ParsingException {
assertEquals(1789, extractor.getLength());
2017-08-06 22:20:15 +02:00
}
@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 {
assertIsSecureUrl(extractor.getThumbnailUrl());
2017-08-06 22:20:15 +02:00
}
@Test
2017-08-08 23:36:11 +02:00
public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
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 {
List<VideoStream> streams = new ArrayList<>();
streams.addAll(extractor.getVideoStreams());
streams.addAll(extractor.getVideoOnlyStreams());
assertTrue(Integer.toString(streams.size()),streams.size() > 0);
for (VideoStream s : streams) {
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()),
2019-01-28 15:43:21 +01:00
0 <= s.getFormatId() && s.getFormatId() <= 0x100);
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
assertTrue(extractor.getSubtitlesDefault().isEmpty());
}
@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
assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
}
2017-08-06 22:20:15 +02:00
}