Skip to content

Commit 4453a63

Browse files
committed
Add test for YouTube livestreams
The current livestream is https://www.youtube.com/watch?v=EcEMX-63PKY
1 parent 5f8e76e commit 4453a63

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package org.schabi.newpipe.extractor.services.youtube.stream;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Test;
5+
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.MediaFormat;
7+
import org.schabi.newpipe.extractor.NewPipe;
8+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
9+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
10+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
11+
import org.schabi.newpipe.extractor.stream.StreamExtractor;
12+
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
13+
import org.schabi.newpipe.extractor.stream.StreamType;
14+
import org.schabi.newpipe.extractor.stream.VideoStream;
15+
import org.schabi.newpipe.extractor.utils.Localization;
16+
import org.schabi.newpipe.extractor.utils.Utils;
17+
18+
import java.io.IOException;
19+
20+
import static org.junit.Assert.*;
21+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
22+
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
23+
24+
public class YoutubeStreamExtractorLivestreamTest {
25+
private static YoutubeStreamExtractor extractor;
26+
27+
@BeforeClass
28+
public static void setUp() throws Exception {
29+
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
30+
extractor = (YoutubeStreamExtractor) YouTube
31+
.getStreamExtractor("https://www.youtube.com/watch?v=EcEMX-63PKY");
32+
extractor.fetchPage();
33+
}
34+
35+
@Test
36+
public void testGetInvalidTimeStamp() throws ParsingException {
37+
assertTrue(extractor.getTimeStamp() + "",
38+
extractor.getTimeStamp() <= 0);
39+
}
40+
41+
@Test
42+
public void testGetTitle() throws ParsingException {
43+
assertFalse(extractor.getName().isEmpty());
44+
}
45+
46+
@Test
47+
public void testGetDescription() throws ParsingException {
48+
assertNotNull(extractor.getDescription());
49+
assertFalse(extractor.getDescription().isEmpty());
50+
}
51+
52+
@Test
53+
public void testGetFullLinksInDescription() throws ParsingException {
54+
assertTrue(extractor.getDescription().contains("https://www.instagram.com/nathalie.baraton/"));
55+
assertFalse(extractor.getDescription().contains("https://www.instagram.com/nathalie.ba..."));
56+
}
57+
58+
@Test
59+
public void testGetUploaderName() throws ParsingException {
60+
assertNotNull(extractor.getUploaderName());
61+
assertFalse(extractor.getUploaderName().isEmpty());
62+
}
63+
64+
65+
@Test
66+
public void testGetLength() throws ParsingException {
67+
assertEquals(0, extractor.getLength());
68+
}
69+
70+
@Test
71+
public void testGetViewCount() throws ParsingException {
72+
long count = extractor.getViewCount();
73+
assertTrue(Long.toString(count), count >= 7148995);
74+
}
75+
76+
@Test
77+
public void testGetUploadDate() throws ParsingException {
78+
assertTrue(extractor.getUploadDate().length() > 0);
79+
}
80+
81+
@Test
82+
public void testGetUploaderUrl() throws ParsingException {
83+
assertEquals("https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow", extractor.getUploaderUrl());
84+
}
85+
86+
@Test
87+
public void testGetThumbnailUrl() throws ParsingException {
88+
assertIsSecureUrl(extractor.getThumbnailUrl());
89+
}
90+
91+
@Test
92+
public void testGetUploaderAvatarUrl() throws ParsingException {
93+
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
94+
}
95+
96+
@Test
97+
public void testGetAudioStreams() throws ExtractionException {
98+
assertFalse(extractor.getAudioStreams().isEmpty());
99+
}
100+
101+
@Test
102+
public void testGetVideoStreams() throws ExtractionException {
103+
for (VideoStream s : extractor.getVideoStreams()) {
104+
assertIsSecureUrl(s.url);
105+
assertTrue(s.resolution.length() > 0);
106+
assertTrue(Integer.toString(s.getFormatId()),
107+
0 <= s.getFormatId() && s.getFormatId() <= 0x100);
108+
}
109+
}
110+
111+
@Test
112+
public void testStreamType() throws ParsingException {
113+
assertTrue(extractor.getStreamType() == StreamType.LIVE_STREAM);
114+
}
115+
116+
@Test
117+
public void testGetDashMpd() throws ParsingException {
118+
// we dont expect this particular video to have a DASH file. For this purpouse we use a different test class.
119+
assertTrue(extractor.getDashMpdUrl(), extractor.getDashMpdUrl().isEmpty());
120+
}
121+
122+
@Test
123+
public void testGetRelatedVideos() throws ExtractionException, IOException {
124+
StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();
125+
Utils.printErrors(relatedVideos.getErrors());
126+
assertFalse(relatedVideos.getItems().isEmpty());
127+
assertTrue(relatedVideos.getErrors().isEmpty());
128+
}
129+
130+
@Test
131+
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
132+
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
133+
assertTrue(extractor.getSubtitlesDefault().isEmpty());
134+
}
135+
136+
@Test
137+
public void testGetSubtitlesList() throws IOException, ExtractionException {
138+
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
139+
assertTrue(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
140+
}
141+
}

0 commit comments

Comments
 (0)