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,64 +60,67 @@ 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 (lowercaseUrl.contains("youtu.be")) {
if (lowercaseUrl.contains("list=")) {
throw new ParsingException("Error no suitable url: " + url);
}
if (url.contains("v=")) { if (url.contains("v=")) {
id = Parser.matchGroup1("v=" + ID_PATTERN, url); return Parser.matchGroup1("v=" + ID_PATTERN, url);
} else {
id = Parser.matchGroup1("[Yy][Oo][Uu][Tt][Uu]\\.[Bb][Ee]/" + ID_PATTERN, url);
} }
} else if(lowercaseUrl.contains("hooktube")) { return Parser.matchGroup1("[Yy][Oo][Uu][Tt][Uu]\\.[Bb][Ee]/" + ID_PATTERN, url);
if(lowercaseUrl.contains("&v=") }
if (lowercaseUrl.contains("hooktube")) {
if (lowercaseUrl.contains("&v=")
|| lowercaseUrl.contains("?v=")) { || lowercaseUrl.contains("?v=")) {
id = Parser.matchGroup1("[?&]v=" + ID_PATTERN, url); return Parser.matchGroup1("[?&]v=" + ID_PATTERN, url);
} else if (url.contains("/embed/")) { }
id = Parser.matchGroup1("embed/" + ID_PATTERN, url); if (url.contains("/embed/")) {
} else if (url.contains("/v/")) { return Parser.matchGroup1("embed/" + ID_PATTERN, url);
id = Parser.matchGroup1("v/" + ID_PATTERN, url); }
} else if (url.contains("/watch/")) { if (url.contains("/v/")) {
id = Parser.matchGroup1("watch/" + ID_PATTERN, url); return Parser.matchGroup1("v/" + ID_PATTERN, url);
} else { }
if (url.contains("/watch/")) {
return Parser.matchGroup1("watch/" + ID_PATTERN, url);
}
}
throw new ParsingException("Error no suitable url: " + url); throw new ParsingException("Error no suitable url: " + url);
} }
} else {
throw new ParsingException("Error no suitable url: " + url);
}
if (!id.isEmpty()) {
return id;
} else {
throw new ParsingException("Error could not parse 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;
// bad programming I know <-- nice meme
}
try { try {
getId(url); getId(url);
return true; return true;
@ -126,8 +129,5 @@ public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory {
} catch (ParsingException e) { } catch (ParsingException e) {
return false; return false;
} }
} else {
return false;
}
} }
} }