fix link parsing for yt internal links

blub
This commit is contained in:
Christian Schabesberger 2018-08-16 17:37:19 +02:00
parent 389a87fc89
commit 981cb333b5
1 changed files with 9 additions and 3 deletions

View File

@ -155,7 +155,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
assertPageFetched(); assertPageFetched();
try { try {
return parseHtmlAndGetFullLinks(doc.select("p[id=\"eow-description\"]").first().html()); return parseHtmlAndGetFullLinks(doc.select("p[id=\"eow-description\"]").first().html());
} catch (Exception e) {//todo: add fallback method <-- there is no ... as long as i know } catch (Exception e) {
throw new ParsingException("Could not get the description", e); throw new ParsingException("Could not get the description", e);
} }
} }
@ -166,8 +166,14 @@ public class YoutubeStreamExtractor extends StreamExtractor {
for(Element a : description.select("a")) { for(Element a : description.select("a")) {
final URL redirectLink = new URL( final URL redirectLink = new URL(
a.attr("abs:href")); a.attr("abs:href"));
final String link = Parser.compatParseMap(redirectLink.getQuery()).get("q"); final String queryString = redirectLink.getQuery();
a.text(link); if(queryString != null) {
// if the query string is null we are not dealing with a redirect link,
// so we don't need to override it.
final String link =
Parser.compatParseMap(queryString).get("q");
a.text(link);
}
} }
return description.select("body").first().html(); return description.select("body").first().html();
} }