2019-09-12 15:05:22 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.stream;
|
|
|
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.DownloaderTestImpl;
|
2019-09-12 15:05:22 +02:00
|
|
|
import org.schabi.newpipe.extractor.MediaFormat;
|
|
|
|
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.services.youtube.extractors.YoutubeStreamExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
|
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
|
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
|
|
|
|
2020-02-26 17:31:01 +01:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
import static org.junit.Assert.assertSame;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
2019-09-12 15:05:22 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|
|
|
|
|
|
|
public class YoutubeStreamExtractorLivestreamTest {
|
|
|
|
private static YoutubeStreamExtractor extractor;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws Exception {
|
2019-04-28 22:03:16 +02:00
|
|
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
2019-09-12 15:05:22 +02:00
|
|
|
extractor = (YoutubeStreamExtractor) YouTube
|
2020-02-26 17:31:01 +01:00
|
|
|
.getStreamExtractor("https://www.youtube.com/watch?v=5qap5aO4i9A");
|
2019-09-12 15:05:22 +02:00
|
|
|
extractor.fetchPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetInvalidTimeStamp() throws ParsingException {
|
|
|
|
assertTrue(extractor.getTimeStamp() + "",
|
|
|
|
extractor.getTimeStamp() <= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetTitle() throws ParsingException {
|
|
|
|
assertFalse(extractor.getName().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetDescription() throws ParsingException {
|
|
|
|
assertNotNull(extractor.getDescription());
|
2020-02-06 23:35:46 +01:00
|
|
|
assertFalse(extractor.getDescription().getContent().isEmpty());
|
2019-09-12 15:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetFullLinksInDescription() throws ParsingException {
|
2020-02-26 17:31:01 +01:00
|
|
|
assertTrue(extractor.getDescription().getContent().contains("https://bit.ly/chilledcow-playlists"));
|
2019-09-12 15:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetUploaderName() throws ParsingException {
|
|
|
|
assertNotNull(extractor.getUploaderName());
|
|
|
|
assertFalse(extractor.getUploaderName().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetLength() throws ParsingException {
|
|
|
|
assertEquals(0, extractor.getLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetViewCount() throws ParsingException {
|
|
|
|
long count = extractor.getViewCount();
|
2019-04-28 22:03:17 +02:00
|
|
|
assertTrue(Long.toString(count), count > -1);
|
2019-09-12 15:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetUploadDate() throws ParsingException {
|
2019-04-28 22:03:16 +02:00
|
|
|
assertNull(extractor.getUploadDate());
|
|
|
|
assertNull(extractor.getTextualUploadDate());
|
2019-09-12 15:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetUploaderUrl() throws ParsingException {
|
|
|
|
assertEquals("https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow", extractor.getUploaderUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetThumbnailUrl() throws ParsingException {
|
|
|
|
assertIsSecureUrl(extractor.getThumbnailUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetUploaderAvatarUrl() throws ParsingException {
|
|
|
|
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetAudioStreams() throws ExtractionException {
|
|
|
|
assertFalse(extractor.getAudioStreams().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetVideoStreams() throws ExtractionException {
|
|
|
|
for (VideoStream s : extractor.getVideoStreams()) {
|
|
|
|
assertIsSecureUrl(s.url);
|
|
|
|
assertTrue(s.resolution.length() > 0);
|
|
|
|
assertTrue(Integer.toString(s.getFormatId()),
|
|
|
|
0 <= s.getFormatId() && s.getFormatId() <= 0x100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testStreamType() throws ParsingException {
|
2019-09-12 15:10:23 +02:00
|
|
|
assertSame(extractor.getStreamType(), StreamType.LIVE_STREAM);
|
2019-09-12 15:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetDashMpd() throws ParsingException {
|
2020-05-15 12:04:21 +02:00
|
|
|
assertTrue(extractor.getDashMpdUrl().startsWith("https://manifest.googlevideo.com/api/manifest/dash/"));
|
2019-09-12 15:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-02-26 17:31:01 +01:00
|
|
|
public void testGetRelatedVideos() throws ExtractionException {
|
2019-09-12 15:05:22 +02:00
|
|
|
StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();
|
|
|
|
Utils.printErrors(relatedVideos.getErrors());
|
|
|
|
assertFalse(relatedVideos.getItems().isEmpty());
|
|
|
|
assertTrue(relatedVideos.getErrors().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-02-26 17:31:01 +01:00
|
|
|
public void testGetSubtitlesListDefault() {
|
2019-09-12 15:05:22 +02:00
|
|
|
assertTrue(extractor.getSubtitlesDefault().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-02-26 17:31:01 +01:00
|
|
|
public void testGetSubtitlesList() {
|
2019-09-12 15:05:22 +02:00
|
|
|
assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
|
|
|
|
}
|
|
|
|
}
|