fix channel links in description part 2

This commit is contained in:
Christian Schabesberger 2018-09-07 22:18:22 +02:00
parent 4469d11307
commit 66c3c3f452
2 changed files with 139 additions and 104 deletions

View file

@ -178,12 +178,12 @@ public class YoutubeStreamExtractor extends StreamExtractor {
// They refer to the youtube search. We do not handle them. // They refer to the youtube search. We do not handle them.
a.text(link); a.text(link);
} else if(redirectLink.toString().contains("watch?v=")
|| redirectLink.toString().contains("https://www.youtube.com/")) {
// Another posibility is that this link is pointing to another video
// we need to put the redirectLink in here explicitly in order to add the domain part to the link.
a.text(redirectLink.toString());
} }
} else if(redirectLink.toString().contains("watch?v=")
|| redirectLink.toString().contains("https://www.youtube.com/")) {
// Another posibility is that this link is pointing to another video
// we need to put the redirectLink in here explicitly in order to add the domain part to the link.
a.text(redirectLink.toString());
} }
} }
return description.select("body").first().html(); return description.select("body").first().html();

View file

@ -16,6 +16,7 @@ import java.io.IOException;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeTrendingExtractorTest.extractor;
/* /*
* Created by Christian Schabesberger on 30.12.15. * Created by Christian Schabesberger on 30.12.15.
@ -41,127 +42,161 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
* Test for {@link StreamExtractor} * Test for {@link StreamExtractor}
*/ */
public class YoutubeStreamExtractorDefaultTest { public class YoutubeStreamExtractorDefaultTest {
private static YoutubeStreamExtractor extractor;
@BeforeClass public static class AdeleHello {
public static void setUp() throws Exception { private static YoutubeStreamExtractor extractor;
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
extractor.fetchPage();
}
@Test @BeforeClass
public void testGetInvalidTimeStamp() throws ParsingException { public static void setUp() throws Exception {
assertTrue(extractor.getTimeStamp() + "", NewPipe.init(Downloader.getInstance());
extractor.getTimeStamp() <= 0); extractor = (YoutubeStreamExtractor) YouTube
} .getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
extractor.fetchPage();
}
@Test @Test
public void testGetValidTimeStamp() throws ExtractionException { public void testGetInvalidTimeStamp() throws ParsingException {
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174"); assertTrue(extractor.getTimeStamp() + "",
assertEquals(extractor.getTimeStamp() + "", "174"); extractor.getTimeStamp() <= 0);
} }
@Test @Test
public void testGetTitle() throws ParsingException { public void testGetValidTimeStamp() throws ExtractionException {
assertFalse(extractor.getName().isEmpty()); StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
} assertEquals(extractor.getTimeStamp() + "", "174");
}
@Test @Test
public void testGetDescription() throws ParsingException { public void testGetTitle() throws ParsingException {
assertNotNull(extractor.getDescription()); assertFalse(extractor.getName().isEmpty());
assertFalse(extractor.getDescription().isEmpty()); }
}
@Test @Test
public void testGetFullLinksInDescriptlion() throws ParsingException { public void testGetDescription() throws ParsingException {
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt")); assertNotNull(extractor.getDescription());
assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi...")); assertFalse(extractor.getDescription().isEmpty());
} }
@Test @Test
public void testGetUploaderName() throws ParsingException { public void testGetFullLinksInDescriptlion() throws ParsingException {
assertNotNull(extractor.getUploaderName()); assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt"));
assertFalse(extractor.getUploaderName().isEmpty()); assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
} }
@Test
public void testGetUploaderName() throws ParsingException {
assertNotNull(extractor.getUploaderName());
assertFalse(extractor.getUploaderName().isEmpty());
}
@Test @Test
public void testGetLength() throws ParsingException { public void testGetLength() throws ParsingException {
assertTrue(extractor.getLength() > 0); assertTrue(extractor.getLength() > 0);
} }
@Test @Test
public void testGetViewCount() throws ParsingException { public void testGetViewCount() throws ParsingException {
Long count = extractor.getViewCount(); Long count = extractor.getViewCount();
assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784); assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784);
} }
@Test @Test
public void testGetUploadDate() throws ParsingException { public void testGetUploadDate() throws ParsingException {
assertTrue(extractor.getUploadDate().length() > 0); assertTrue(extractor.getUploadDate().length() > 0);
} }
@Test @Test
public void testGetUploaderUrl() throws ParsingException { public void testGetUploaderUrl() throws ParsingException {
assertTrue(extractor.getUploaderUrl().length() > 0); assertTrue(extractor.getUploaderUrl().length() > 0);
} }
@Test @Test
public void testGetThumbnailUrl() throws ParsingException { public void testGetThumbnailUrl() throws ParsingException {
assertIsSecureUrl(extractor.getThumbnailUrl()); assertIsSecureUrl(extractor.getThumbnailUrl());
} }
@Test @Test
public void testGetUploaderAvatarUrl() throws ParsingException { public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl()); assertIsSecureUrl(extractor.getUploaderAvatarUrl());
} }
@Test @Test
public void testGetAudioStreams() throws IOException, ExtractionException { public void testGetAudioStreams() throws IOException, ExtractionException {
assertFalse(extractor.getAudioStreams().isEmpty()); assertFalse(extractor.getAudioStreams().isEmpty());
} }
@Test @Test
public void testGetVideoStreams() throws IOException, ExtractionException { public void testGetVideoStreams() throws IOException, ExtractionException {
for (VideoStream s : extractor.getVideoStreams()) { for (VideoStream s : extractor.getVideoStreams()) {
assertIsSecureUrl(s.url); assertIsSecureUrl(s.url);
assertTrue(s.resolution.length() > 0); assertTrue(s.resolution.length() > 0);
assertTrue(Integer.toString(s.getFormatId()), assertTrue(Integer.toString(s.getFormatId()),
0 <= s.getFormatId() && s.getFormatId() <= 4); 0 <= s.getFormatId() && s.getFormatId() <= 4);
}
}
@Test
public void testStreamType() throws ParsingException {
assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM);
}
@Test
public void testGetDashMpd() throws ParsingException {
// we dont expect this particular video to have a DASH file. For this purpouse we use a different test class.
assertTrue(extractor.getDashMpdUrl(),
extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty());
}
@Test
public void testGetRelatedVideos() throws ExtractionException, IOException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos();
Utils.printErrors(relatedVideos.getErrors());
assertFalse(relatedVideos.getItems().isEmpty());
assertTrue(relatedVideos.getErrors().isEmpty());
}
@Test
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitlesDefault().isEmpty());
}
@Test
public void testGetSubtitlesList() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty());
} }
} }
@Test public static class DescriptionTestPewdiepie {
public void testStreamType() throws ParsingException { private static YoutubeStreamExtractor extractor;
assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM);
}
@Test @BeforeClass
public void testGetDashMpd() throws ParsingException { public static void setUp() throws Exception {
// we dont expect this particular video to have a DASH file. For this purpouse we use a different test class. NewPipe.init(Downloader.getInstance());
assertTrue(extractor.getDashMpdUrl(), extractor = (YoutubeStreamExtractor) YouTube
extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty()); .getStreamExtractor("https://www.youtube.com/watch?v=dJY8iT341F4");
} extractor.fetchPage();
}
@Test @Test
public void testGetRelatedVideos() throws ExtractionException, IOException { public void testGetDescription() throws ParsingException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); assertNotNull(extractor.getDescription());
Utils.printErrors(relatedVideos.getErrors()); assertFalse(extractor.getDescription().isEmpty());
assertFalse(relatedVideos.getItems().isEmpty()); }
assertTrue(relatedVideos.getErrors().isEmpty());
}
@Test @Test
public void testGetSubtitlesListDefault() throws IOException, ExtractionException { public void testGetFullLinksInDescriptlion() throws ParsingException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertTrue(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSubmissions/"));
assertTrue(extractor.getSubtitlesDefault().isEmpty()); assertTrue(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng"));
}
@Test assertFalse(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSub..."));
public void testGetSubtitlesList() throws IOException, ExtractionException { assertFalse(extractor.getDescription().contains("https://usa.clutchchairz.com/product/..."));
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertFalse(extractor.getDescription().contains("https://europe.clutchchairz.com/en/pr..."));
assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty()); assertFalse(extractor.getDescription().contains("https://canada.clutchchairz.com/produ..."));
assertFalse(extractor.getDescription().contains("http://store.steampowered.com/app/703..."));
assertFalse(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8..."));
}
} }
} }