From 3aa7ff6d0e5d7a5d849f4e00bd747154dd7931dc Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 27 Aug 2018 20:45:43 +0200 Subject: [PATCH] make ytdescription alter href instead of the text of links --- .../youtube/extractors/YoutubeStreamExtractor.java | 10 ++++++++-- .../youtube/YoutubeStreamExtractorDefaultTest.java | 5 ++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 0551e0f9..65c4bf18 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -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()); } } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java index 484c0e67..da589aa0 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java @@ -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