Skip to content

Commit 389a87f

Browse files
committed
add link parsing for youtube description
1 parent aeb8138 commit 389a87f

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
1919
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
2020
import org.schabi.newpipe.extractor.stream.*;
21-
import org.schabi.newpipe.extractor.utils.DonationLinkHelper;
2221
import org.schabi.newpipe.extractor.utils.Parser;
2322
import org.schabi.newpipe.extractor.utils.Utils;
2423

2524
import javax.annotation.Nonnull;
2625
import javax.annotation.Nullable;
2726
import java.io.IOException;
27+
import java.io.UnsupportedEncodingException;
28+
import java.net.MalformedURLException;
29+
import java.net.URL;
2830
import java.util.*;
2931

3032
/*
@@ -152,12 +154,24 @@ public String getThumbnailUrl() throws ParsingException {
152154
public String getDescription() throws ParsingException {
153155
assertPageFetched();
154156
try {
155-
return doc.select("p[id=\"eow-description\"]").first().html();
157+
return parseHtmlAndGetFullLinks(doc.select("p[id=\"eow-description\"]").first().html());
156158
} catch (Exception e) {//todo: add fallback method <-- there is no ... as long as i know
157159
throw new ParsingException("Could not get the description", e);
158160
}
159161
}
160162

163+
private String parseHtmlAndGetFullLinks(String descriptionHtml)
164+
throws MalformedURLException, UnsupportedEncodingException, ParsingException {
165+
final Document description = Jsoup.parse(descriptionHtml, getUrl());
166+
for(Element a : description.select("a")) {
167+
final URL redirectLink = new URL(
168+
a.attr("abs:href"));
169+
final String link = Parser.compatParseMap(redirectLink.getQuery()).get("q");
170+
a.text(link);
171+
}
172+
return description.select("body").first().html();
173+
}
174+
161175
@Override
162176
public int getAgeLimit() throws ParsingException {
163177
assertPageFetched();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public void testGetDescription() throws ParsingException {
7373
assertFalse(extractor.getDescription().isEmpty());
7474
}
7575

76+
@Test
77+
public void testGetFullLinksInDescriptlion() throws ParsingException {
78+
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt"));
79+
assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
80+
System.out.println(extractor.getDescription());
81+
}
82+
7683
@Test
7784
public void testGetUploaderName() throws ParsingException {
7885
assertNotNull(extractor.getUploaderName());

0 commit comments

Comments
 (0)