Merge pull request #97 from MadderRagax/master

Fixed  #1548 and #1546 - Playlist links not getting parsed properly
This commit is contained in:
Christian Schabesberger 2018-09-15 22:29:08 +02:00 committed by GitHub
commit 1e7bcfbd66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 47 deletions

View File

@ -60,73 +60,73 @@ public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory {
throw new IllegalArgumentException("The url parameter should not be empty"); throw new IllegalArgumentException("The url parameter should not be empty");
} }
String id;
String lowercaseUrl = url.toLowerCase(); String lowercaseUrl = url.toLowerCase();
if (lowercaseUrl.contains("youtube")) { if (lowercaseUrl.contains("youtube")) {
if (lowercaseUrl.contains("list=")) {
throw new ParsingException("Error no suitable url: " + url);
}
if (url.contains("attribution_link")) { if (url.contains("attribution_link")) {
try { try {
String escapedQuery = Parser.matchGroup1("u=(.[^&|$]*)", url); String escapedQuery = Parser.matchGroup1("u=(.[^&|$]*)", url);
String query = URLDecoder.decode(escapedQuery, "UTF-8"); String query = URLDecoder.decode(escapedQuery, "UTF-8");
id = Parser.matchGroup1("v=" + ID_PATTERN, query); return Parser.matchGroup1("v=" + ID_PATTERN, query);
} catch (UnsupportedEncodingException uee) { } catch (UnsupportedEncodingException uee) {
throw new ParsingException("Could not parse attribution_link", uee); throw new ParsingException("Could not parse attribution_link", uee);
} }
} else if (url.contains("vnd.youtube")) { }
id = Parser.matchGroup1(ID_PATTERN, url); if (url.contains("vnd.youtube")) {
} else if (url.contains("embed")) { return Parser.matchGroup1(ID_PATTERN, url);
id = Parser.matchGroup1("embed/" + ID_PATTERN, url); }
} else if (url.contains("googleads")) { if (url.contains("embed")) {
return Parser.matchGroup1("embed/" + ID_PATTERN, url);
}
if (url.contains("googleads")) {
throw new FoundAdException("Error found add: " + url); throw new FoundAdException("Error found add: " + url);
} else {
id = Parser.matchGroup1("[?&]v=" + ID_PATTERN, url);
} }
} else if (lowercaseUrl.contains("youtu.be")) { return Parser.matchGroup1("[?&]v=" + ID_PATTERN, url);
if (url.contains("v=")) { }
id = Parser.matchGroup1("v=" + ID_PATTERN, url); if (lowercaseUrl.contains("youtu.be")) {
} else { if (lowercaseUrl.contains("list=")) {
id = Parser.matchGroup1("[Yy][Oo][Uu][Tt][Uu]\\.[Bb][Ee]/" + ID_PATTERN, url);
}
} else if(lowercaseUrl.contains("hooktube")) {
if(lowercaseUrl.contains("&v=")
|| lowercaseUrl.contains("?v=")) {
id = Parser.matchGroup1("[?&]v=" + ID_PATTERN, url);
} else if (url.contains("/embed/")) {
id = Parser.matchGroup1("embed/" + ID_PATTERN, url);
} else if (url.contains("/v/")) {
id = Parser.matchGroup1("v/" + ID_PATTERN, url);
} else if (url.contains("/watch/")) {
id = Parser.matchGroup1("watch/" + ID_PATTERN, url);
} else {
throw new ParsingException("Error no suitable url: " + url); throw new ParsingException("Error no suitable url: " + url);
} }
} else { if (url.contains("v=")) {
throw new ParsingException("Error no suitable url: " + url); return Parser.matchGroup1("v=" + ID_PATTERN, url);
}
return Parser.matchGroup1("[Yy][Oo][Uu][Tt][Uu]\\.[Bb][Ee]/" + ID_PATTERN, url);
} }
if (lowercaseUrl.contains("hooktube")) {
if (lowercaseUrl.contains("&v=")
if (!id.isEmpty()) { || lowercaseUrl.contains("?v=")) {
return id; return Parser.matchGroup1("[?&]v=" + ID_PATTERN, url);
} else { }
throw new ParsingException("Error could not parse url: " + url); if (url.contains("/embed/")) {
return Parser.matchGroup1("embed/" + ID_PATTERN, url);
}
if (url.contains("/v/")) {
return Parser.matchGroup1("v/" + ID_PATTERN, url);
}
if (url.contains("/watch/")) {
return Parser.matchGroup1("watch/" + ID_PATTERN, url);
}
} }
throw new ParsingException("Error no suitable url: " + url);
} }
@Override @Override
public boolean onAcceptUrl(final String url) throws FoundAdException { public boolean onAcceptUrl(final String url) throws FoundAdException {
final String lowercaseUrl = url.toLowerCase(); final String lowercaseUrl = url.toLowerCase();
if (lowercaseUrl.contains("youtube") if (!lowercaseUrl.contains("youtube") &&
|| lowercaseUrl.contains("youtu.be") !lowercaseUrl.contains("youtu.be") &&
|| lowercaseUrl.contains("hooktube")) { !lowercaseUrl.contains("hooktube")) {
// bad programming I know return false;
try { // bad programming I know <-- nice meme
getId(url); }
return true; try {
} catch (FoundAdException fe) { getId(url);
throw fe; return true;
} catch (ParsingException e) { } catch (FoundAdException fe) {
return false; throw fe;
} } catch (ParsingException e) {
} else {
return false; return false;
} }
} }