mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-13 13:50:33 +05:30
split isYoutubeALikeURL into multiple methods
This commit is contained in:
parent
2ede47d36c
commit
7493ed903b
@ -46,7 +46,8 @@ public class YoutubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
URL urlObj = Utils.stringToURL(url);
|
||||
String path = urlObj.getPath();
|
||||
|
||||
if (!YoutubeParsingHelper.isYoutubeALikeURL(urlObj)) { // fixme: accepts youtu.be and youtube-nocookie.com
|
||||
if (!Utils.isHTTP(urlObj) || !(YoutubeParsingHelper.isYoutubeURL(urlObj) ||
|
||||
YoutubeParsingHelper.isInvidioURL(urlObj) || YoutubeParsingHelper.isHooktubeURL(urlObj))) {
|
||||
throw new ParsingException("the URL given is not a Youtube-URL");
|
||||
}
|
||||
|
||||
|
@ -30,41 +30,25 @@ public class YoutubeParsingHelper {
|
||||
private YoutubeParsingHelper() {
|
||||
}
|
||||
|
||||
private static boolean isHTTP(URL url) {
|
||||
// make sure its http or https
|
||||
String protocol = url.getProtocol();
|
||||
if (!protocol.equals("http") && !protocol.equals("https")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean usesDefaultPort = url.getPort() == url.getDefaultPort();
|
||||
boolean setsNoPort = url.getPort() == -1;
|
||||
|
||||
return setsNoPort || usesDefaultPort;
|
||||
}
|
||||
|
||||
public static boolean isYoutubeURL(URL url) {
|
||||
// make sure its http or https
|
||||
if (!isHTTP(url))
|
||||
return false;
|
||||
|
||||
// make sure its a known youtube url
|
||||
String host = url.getHost();
|
||||
return host.equalsIgnoreCase("youtube.com") || host.equalsIgnoreCase("www.youtube.com")
|
||||
|| host.equalsIgnoreCase("m.youtube.com");
|
||||
}
|
||||
|
||||
public static boolean isYoutubeALikeURL(URL url) {
|
||||
// make sure its http or https
|
||||
if (!isHTTP(url))
|
||||
return false;
|
||||
|
||||
// make sure its a known youtube url
|
||||
public static boolean isYoutubeServiceURL(URL url) {
|
||||
String host = url.getHost();
|
||||
return host.equalsIgnoreCase("youtube.com") || host.equalsIgnoreCase("www.youtube.com")
|
||||
|| host.equalsIgnoreCase("m.youtube.com") || host.equalsIgnoreCase("www.youtube-nocookie.com")
|
||||
|| host.equalsIgnoreCase("youtu.be") || host.equalsIgnoreCase("hooktube.com")
|
||||
|| host.equalsIgnoreCase("invidio.us");
|
||||
return host.equalsIgnoreCase("www.youtube-nocookie.com") || host.equalsIgnoreCase("youtu.be");
|
||||
}
|
||||
|
||||
public static boolean isHooktubeURL(URL url) {
|
||||
String host = url.getHost();
|
||||
return host.equalsIgnoreCase("hooktube.com");
|
||||
}
|
||||
|
||||
public static boolean isInvidioURL(URL url) {
|
||||
String host = url.getHost();
|
||||
return host.equalsIgnoreCase("invidio.us") || host.equalsIgnoreCase("www.invidio.us");
|
||||
}
|
||||
|
||||
public static long parseDurationString(String input)
|
||||
|
@ -25,7 +25,7 @@ public class YoutubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
try {
|
||||
URL urlObj = Utils.stringToURL(url);
|
||||
|
||||
if (!YoutubeParsingHelper.isYoutubeURL(urlObj)) {
|
||||
if (!Utils.isHTTP(urlObj) || !YoutubeParsingHelper.isYoutubeURL(urlObj)) {
|
||||
throw new ParsingException("the url given is not a Youtube-URL");
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,9 @@ public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
if (!YoutubeParsingHelper.isYoutubeALikeURL(url)) {
|
||||
if (!Utils.isHTTP(url) || !(YoutubeParsingHelper.isYoutubeURL(url) ||
|
||||
YoutubeParsingHelper.isYoutubeServiceURL(url) || YoutubeParsingHelper.isHooktubeURL(url) ||
|
||||
YoutubeParsingHelper.isInvidioURL(url))) {
|
||||
if (host.equalsIgnoreCase("googleads.g.doubleclick.net")) {
|
||||
throw new FoundAdException("Error found ad: " + urlString);
|
||||
}
|
||||
@ -160,6 +162,7 @@ public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||
// there is no break-statement here on purpose so the next code-block gets also run for hooktube
|
||||
}
|
||||
|
||||
case "WWW.INVIDIO.US":
|
||||
case "INVIDIO.US": { // code-block for hooktube.com and invidio.us
|
||||
if (path.equals("watch")) {
|
||||
String viewQueryValue = Utils.getQueryValue(url, "v");
|
||||
|
@ -48,6 +48,6 @@ public class YoutubeTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
}
|
||||
|
||||
String urlPath = urlObj.getPath();
|
||||
return YoutubeParsingHelper.isYoutubeURL(urlObj) && urlPath.equals("/feed/trending");
|
||||
return Utils.isHTTP(urlObj) && (YoutubeParsingHelper.isYoutubeURL(urlObj)) && urlPath.equals("/feed/trending");
|
||||
}
|
||||
}
|
||||
|
@ -120,4 +120,17 @@ public class Utils {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHTTP(URL url) {
|
||||
// make sure its http or https
|
||||
String protocol = url.getProtocol();
|
||||
if (!protocol.equals("http") && !protocol.equals("https")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean usesDefaultPort = url.getPort() == url.getDefaultPort();
|
||||
boolean setsNoPort = url.getPort() == -1;
|
||||
|
||||
return setsNoPort || usesDefaultPort;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user