Skip to content

Commit 66c3c3f

Browse files
committed
fix channel links in description part 2
1 parent 4469d11 commit 66c3c3f

2 files changed

Lines changed: 140 additions & 105 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ private String parseHtmlAndGetFullLinks(String descriptionHtml)
178178
// They refer to the youtube search. We do not handle them.
179179
a.text(link);
180180

181-
} else if(redirectLink.toString().contains("watch?v=")
182-
|| redirectLink.toString().contains("https://www.youtube.com/")) {
183-
// Another posibility is that this link is pointing to another video
184-
// we need to put the redirectLink in here explicitly in order to add the domain part to the link.
185-
a.text(redirectLink.toString());
186181
}
182+
} else if(redirectLink.toString().contains("watch?v=")
183+
|| redirectLink.toString().contains("https://www.youtube.com/")) {
184+
// Another posibility is that this link is pointing to another video
185+
// we need to put the redirectLink in here explicitly in order to add the domain part to the link.
186+
a.text(redirectLink.toString());
187187
}
188188
}
189189
return description.select("body").first().html();

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java

Lines changed: 135 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.junit.Assert.*;
1717
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
1818
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
19+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeTrendingExtractorTest.extractor;
1920

2021
/*
2122
* Created by Christian Schabesberger on 30.12.15.
@@ -41,127 +42,161 @@
4142
* Test for {@link StreamExtractor}
4243
*/
4344
public class YoutubeStreamExtractorDefaultTest {
44-
private static YoutubeStreamExtractor extractor;
45-
46-
@BeforeClass
47-
public static void setUp() throws Exception {
48-
NewPipe.init(Downloader.getInstance());
49-
extractor = (YoutubeStreamExtractor) YouTube
50-
.getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
51-
extractor.fetchPage();
52-
}
5345

54-
@Test
55-
public void testGetInvalidTimeStamp() throws ParsingException {
56-
assertTrue(extractor.getTimeStamp() + "",
57-
extractor.getTimeStamp() <= 0);
58-
}
46+
public static class AdeleHello {
47+
private static YoutubeStreamExtractor extractor;
5948

60-
@Test
61-
public void testGetValidTimeStamp() throws ExtractionException {
62-
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
63-
assertEquals(extractor.getTimeStamp() + "", "174");
64-
}
49+
@BeforeClass
50+
public static void setUp() throws Exception {
51+
NewPipe.init(Downloader.getInstance());
52+
extractor = (YoutubeStreamExtractor) YouTube
53+
.getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
54+
extractor.fetchPage();
55+
}
6556

66-
@Test
67-
public void testGetTitle() throws ParsingException {
68-
assertFalse(extractor.getName().isEmpty());
69-
}
57+
@Test
58+
public void testGetInvalidTimeStamp() throws ParsingException {
59+
assertTrue(extractor.getTimeStamp() + "",
60+
extractor.getTimeStamp() <= 0);
61+
}
7062

71-
@Test
72-
public void testGetDescription() throws ParsingException {
73-
assertNotNull(extractor.getDescription());
74-
assertFalse(extractor.getDescription().isEmpty());
75-
}
63+
@Test
64+
public void testGetValidTimeStamp() throws ExtractionException {
65+
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
66+
assertEquals(extractor.getTimeStamp() + "", "174");
67+
}
7668

77-
@Test
78-
public void testGetFullLinksInDescriptlion() throws ParsingException {
79-
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt"));
80-
assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
81-
}
69+
@Test
70+
public void testGetTitle() throws ParsingException {
71+
assertFalse(extractor.getName().isEmpty());
72+
}
8273

83-
@Test
84-
public void testGetUploaderName() throws ParsingException {
85-
assertNotNull(extractor.getUploaderName());
86-
assertFalse(extractor.getUploaderName().isEmpty());
87-
}
74+
@Test
75+
public void testGetDescription() throws ParsingException {
76+
assertNotNull(extractor.getDescription());
77+
assertFalse(extractor.getDescription().isEmpty());
78+
}
8879

80+
@Test
81+
public void testGetFullLinksInDescriptlion() throws ParsingException {
82+
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt"));
83+
assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
84+
}
8985

90-
@Test
91-
public void testGetLength() throws ParsingException {
92-
assertTrue(extractor.getLength() > 0);
93-
}
86+
@Test
87+
public void testGetUploaderName() throws ParsingException {
88+
assertNotNull(extractor.getUploaderName());
89+
assertFalse(extractor.getUploaderName().isEmpty());
90+
}
9491

95-
@Test
96-
public void testGetViewCount() throws ParsingException {
97-
Long count = extractor.getViewCount();
98-
assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784);
99-
}
10092

101-
@Test
102-
public void testGetUploadDate() throws ParsingException {
103-
assertTrue(extractor.getUploadDate().length() > 0);
104-
}
93+
@Test
94+
public void testGetLength() throws ParsingException {
95+
assertTrue(extractor.getLength() > 0);
96+
}
10597

106-
@Test
107-
public void testGetUploaderUrl() throws ParsingException {
108-
assertTrue(extractor.getUploaderUrl().length() > 0);
109-
}
98+
@Test
99+
public void testGetViewCount() throws ParsingException {
100+
Long count = extractor.getViewCount();
101+
assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784);
102+
}
110103

111-
@Test
112-
public void testGetThumbnailUrl() throws ParsingException {
113-
assertIsSecureUrl(extractor.getThumbnailUrl());
114-
}
104+
@Test
105+
public void testGetUploadDate() throws ParsingException {
106+
assertTrue(extractor.getUploadDate().length() > 0);
107+
}
115108

116-
@Test
117-
public void testGetUploaderAvatarUrl() throws ParsingException {
118-
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
119-
}
109+
@Test
110+
public void testGetUploaderUrl() throws ParsingException {
111+
assertTrue(extractor.getUploaderUrl().length() > 0);
112+
}
120113

121-
@Test
122-
public void testGetAudioStreams() throws IOException, ExtractionException {
123-
assertFalse(extractor.getAudioStreams().isEmpty());
124-
}
114+
@Test
115+
public void testGetThumbnailUrl() throws ParsingException {
116+
assertIsSecureUrl(extractor.getThumbnailUrl());
117+
}
125118

126-
@Test
127-
public void testGetVideoStreams() throws IOException, ExtractionException {
128-
for (VideoStream s : extractor.getVideoStreams()) {
129-
assertIsSecureUrl(s.url);
130-
assertTrue(s.resolution.length() > 0);
131-
assertTrue(Integer.toString(s.getFormatId()),
132-
0 <= s.getFormatId() && s.getFormatId() <= 4);
119+
@Test
120+
public void testGetUploaderAvatarUrl() throws ParsingException {
121+
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
133122
}
134-
}
135123

136-
@Test
137-
public void testStreamType() throws ParsingException {
138-
assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM);
139-
}
124+
@Test
125+
public void testGetAudioStreams() throws IOException, ExtractionException {
126+
assertFalse(extractor.getAudioStreams().isEmpty());
127+
}
140128

141-
@Test
142-
public void testGetDashMpd() throws ParsingException {
143-
// we dont expect this particular video to have a DASH file. For this purpouse we use a different test class.
144-
assertTrue(extractor.getDashMpdUrl(),
145-
extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty());
146-
}
129+
@Test
130+
public void testGetVideoStreams() throws IOException, ExtractionException {
131+
for (VideoStream s : extractor.getVideoStreams()) {
132+
assertIsSecureUrl(s.url);
133+
assertTrue(s.resolution.length() > 0);
134+
assertTrue(Integer.toString(s.getFormatId()),
135+
0 <= s.getFormatId() && s.getFormatId() <= 4);
136+
}
137+
}
147138

148-
@Test
149-
public void testGetRelatedVideos() throws ExtractionException, IOException {
150-
StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos();
151-
Utils.printErrors(relatedVideos.getErrors());
152-
assertFalse(relatedVideos.getItems().isEmpty());
153-
assertTrue(relatedVideos.getErrors().isEmpty());
154-
}
139+
@Test
140+
public void testStreamType() throws ParsingException {
141+
assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM);
142+
}
143+
144+
@Test
145+
public void testGetDashMpd() throws ParsingException {
146+
// we dont expect this particular video to have a DASH file. For this purpouse we use a different test class.
147+
assertTrue(extractor.getDashMpdUrl(),
148+
extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty());
149+
}
155150

156-
@Test
157-
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
158-
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
159-
assertTrue(extractor.getSubtitlesDefault().isEmpty());
151+
@Test
152+
public void testGetRelatedVideos() throws ExtractionException, IOException {
153+
StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos();
154+
Utils.printErrors(relatedVideos.getErrors());
155+
assertFalse(relatedVideos.getItems().isEmpty());
156+
assertTrue(relatedVideos.getErrors().isEmpty());
157+
}
158+
159+
@Test
160+
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
161+
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
162+
assertTrue(extractor.getSubtitlesDefault().isEmpty());
163+
}
164+
165+
@Test
166+
public void testGetSubtitlesList() throws IOException, ExtractionException {
167+
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
168+
assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty());
169+
}
160170
}
161171

162-
@Test
163-
public void testGetSubtitlesList() throws IOException, ExtractionException {
164-
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
165-
assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty());
172+
public static class DescriptionTestPewdiepie {
173+
private static YoutubeStreamExtractor extractor;
174+
175+
@BeforeClass
176+
public static void setUp() throws Exception {
177+
NewPipe.init(Downloader.getInstance());
178+
extractor = (YoutubeStreamExtractor) YouTube
179+
.getStreamExtractor("https://www.youtube.com/watch?v=dJY8iT341F4");
180+
extractor.fetchPage();
181+
}
182+
183+
@Test
184+
public void testGetDescription() throws ParsingException {
185+
assertNotNull(extractor.getDescription());
186+
assertFalse(extractor.getDescription().isEmpty());
187+
}
188+
189+
@Test
190+
public void testGetFullLinksInDescriptlion() throws ParsingException {
191+
assertTrue(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSubmissions/"));
192+
assertTrue(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng"));
193+
194+
assertFalse(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSub..."));
195+
assertFalse(extractor.getDescription().contains("https://usa.clutchchairz.com/product/..."));
196+
assertFalse(extractor.getDescription().contains("https://europe.clutchchairz.com/en/pr..."));
197+
assertFalse(extractor.getDescription().contains("https://canada.clutchchairz.com/produ..."));
198+
assertFalse(extractor.getDescription().contains("http://store.steampowered.com/app/703..."));
199+
assertFalse(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8..."));
200+
}
166201
}
167202
}

0 commit comments

Comments
 (0)