|
|
|
|
@ -8,7 +8,6 @@ import com.fongmi.android.tv.bean.Rule; |
|
|
|
|
import com.github.catvod.utils.Util; |
|
|
|
|
import com.orhanobut.logger.Logger; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
@ -45,31 +44,20 @@ public class Sniffer { |
|
|
|
|
if (matchOrContain(url)) return true; |
|
|
|
|
if (headers.containsKey("Accept") && headers.get("Accept").startsWith("image")) return false; |
|
|
|
|
if (url.contains("url=http") || url.contains("v=http") || url.contains(".css") || url.contains(".html")) return false; |
|
|
|
|
return match(url) || url.matches(RULE); |
|
|
|
|
return url.matches(RULE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static List<String> getRegex() { |
|
|
|
|
List<String> regex = new ArrayList<>(); |
|
|
|
|
for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (host.equals("*")) regex.addAll(rule.getRegex()); |
|
|
|
|
return regex; |
|
|
|
|
private static boolean matchOrContain(String url) { |
|
|
|
|
List<String> items = getRegex(Uri.parse(url)); |
|
|
|
|
for (String regex : items) if (url.contains(regex)) return true; |
|
|
|
|
for (String regex : items) if (url.matches(regex)) return true; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static List<String> getRegex(Uri uri) { |
|
|
|
|
if (uri.getHost() == null) return Collections.emptyList(); |
|
|
|
|
String hosts = TextUtils.join(",", Arrays.asList(Util.host(uri), Util.host(uri.getQueryParameter("url")))); |
|
|
|
|
for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (hosts.contains(host) || hosts.matches(host)) return rule.getRegex(); |
|
|
|
|
for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (Util.containOrMatch(hosts, host)) return rule.getRegex(); |
|
|
|
|
return Collections.emptyList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean matchOrContain(String url) { |
|
|
|
|
boolean match = false; |
|
|
|
|
for (String regex : getRegex(Uri.parse(url))) if (url.contains(regex) || url.matches(regex)) match = true; |
|
|
|
|
return match; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean match(String url) { |
|
|
|
|
boolean match = false; |
|
|
|
|
for (String regex : getRegex()) if (url.matches(regex)) match = true; |
|
|
|
|
return match; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|