Skip to content

Commit cc3f3b8

Browse files
committed
-Fixed Youtube page extraction on flagged / offensive content urls.
-Added test for flagged content url extraction.
1 parent b420647 commit cc3f3b8

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package org.schabi.newpipe.extractor.services.youtube;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Ignore;
5+
import org.junit.Test;
6+
import org.schabi.newpipe.Downloader;
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.stream.StreamExtractor;
11+
import org.schabi.newpipe.extractor.stream.SubtitlesFormat;
12+
import org.schabi.newpipe.extractor.stream.VideoStream;
13+
14+
import java.io.IOException;
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
import static org.junit.Assert.*;
19+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
20+
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
21+
22+
/**
23+
* Test for {@link YoutubeStreamUrlIdHandler}
24+
*/
25+
public class YoutubeStreamExtractorControversialTest {
26+
private static YoutubeStreamExtractor extractor;
27+
28+
@BeforeClass
29+
public static void setUp() throws Exception {
30+
NewPipe.init(Downloader.getInstance());
31+
extractor = (YoutubeStreamExtractor) YouTube
32+
.getStreamExtractor("https://www.youtube.com/watch?v=T4XJQO3qol8");
33+
extractor.fetchPage();
34+
}
35+
36+
@Test
37+
public void testGetInvalidTimeStamp() throws ParsingException {
38+
assertTrue(extractor.getTimeStamp() + "", extractor.getTimeStamp() <= 0);
39+
}
40+
41+
@Test
42+
public void testGetValidTimeStamp() throws IOException, ExtractionException {
43+
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
44+
assertEquals(extractor.getTimeStamp() + "", "174");
45+
}
46+
47+
@Test
48+
@Ignore
49+
public void testGetAgeLimit() throws ParsingException {
50+
assertEquals(18, extractor.getAgeLimit());
51+
}
52+
53+
@Test
54+
public void testGetName() throws ParsingException {
55+
assertNotNull("name is null", extractor.getName());
56+
assertFalse("name is empty", extractor.getName().isEmpty());
57+
}
58+
59+
@Test
60+
public void testGetDescription() throws ParsingException {
61+
assertNotNull(extractor.getDescription());
62+
assertFalse(extractor.getDescription().isEmpty());
63+
}
64+
65+
@Test
66+
public void testGetUploaderName() throws ParsingException {
67+
assertNotNull(extractor.getUploaderName());
68+
assertFalse(extractor.getUploaderName().isEmpty());
69+
}
70+
71+
@Ignore // Currently there is no way get the length from restricted videos
72+
@Test
73+
public void testGetLength() throws ParsingException {
74+
assertTrue(extractor.getLength() > 0);
75+
}
76+
77+
@Test
78+
public void testGetViews() throws ParsingException {
79+
assertTrue(extractor.getViewCount() > 0);
80+
}
81+
82+
@Test
83+
public void testGetUploadDate() throws ParsingException {
84+
assertTrue(extractor.getUploadDate().length() > 0);
85+
}
86+
87+
@Test
88+
public void testGetThumbnailUrl() throws ParsingException {
89+
assertIsSecureUrl(extractor.getThumbnailUrl());
90+
}
91+
92+
@Test
93+
public void testGetUploaderAvatarUrl() throws ParsingException {
94+
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
95+
}
96+
97+
// FIXME: 25.11.17 Are there no streams or are they not listed?
98+
@Ignore
99+
@Test
100+
public void testGetAudioStreams() throws IOException, ExtractionException {
101+
// audio streams are not always necessary
102+
assertFalse(extractor.getAudioStreams().isEmpty());
103+
}
104+
105+
@Test
106+
public void testGetVideoStreams() throws IOException, ExtractionException {
107+
List<VideoStream> streams = new ArrayList<>();
108+
streams.addAll(extractor.getVideoStreams());
109+
streams.addAll(extractor.getVideoOnlyStreams());
110+
assertTrue(streams.size() > 0);
111+
}
112+
113+
114+
@Test
115+
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
116+
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
117+
assertTrue(!extractor.getSubtitlesDefault().isEmpty());
118+
}
119+
120+
@Test
121+
public void testGetSubtitlesList() throws IOException, ExtractionException {
122+
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
123+
assertTrue(!extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty());
124+
}
125+
}

0 commit comments

Comments
 (0)