make ytdescription alter href instead of the text of links

This commit is contained in:
Christian Schabesberger 2018-08-27 20:45:43 +02:00
parent e662c97433
commit 3aa7ff6d0e
2 changed files with 10 additions and 5 deletions

View file

@ -173,9 +173,15 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final String link =
Parser.compatParseMap(queryString).get("q");
// if link is null the a tag is a hashtag. They refer to the youtube search. We do not handle them.
if(link != null) {
a.text(link);
// if link is null the a tag is a hashtag.
// They refer to the youtube search. We do not handle them.
a.attr("abs:href", link);
} else if(redirectLink.toString().contains("watch?v=")) {
// 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.attr("abs:href", redirectLink.toString());
}
}
}

View file

@ -58,7 +58,7 @@ public class YoutubeStreamExtractorDefaultTest {
}
@Test
public void testGetValidTimeStamp() throws IOException, ExtractionException {
public void testGetValidTimeStamp() throws ExtractionException {
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
assertEquals(extractor.getTimeStamp() + "", "174");
}
@ -77,8 +77,7 @@ public class YoutubeStreamExtractorDefaultTest {
@Test
public void testGetFullLinksInDescriptlion() throws ParsingException {
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt"));
assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
System.out.println(extractor.getDescription());
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
}
@Test