pull/142/head
FongMi 3 years ago
parent b2e7b5e81a
commit d489bf6cb8
  1. 22
      app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java
  2. 6
      catvod/src/main/java/com/github/catvod/net/ProxySelector.java

@ -14,14 +14,13 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class Sniffer {
private static final String TAG = Sniffer.class.getSimpleName();
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36";
public static final Pattern RULE = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|http((?!http).)*?video/tos*");
public static final String RULE = "http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|http((?!http).)*?video/tos*";
public static final List<String> PUSH = Arrays.asList("smb", "http", "https", "thunder", "magnet", "ed2k", "mitv", "jianpian");
public static final List<String> THUNDER = Arrays.asList("thunder", "magnet", "ed2k");
@ -46,7 +45,7 @@ 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) || RULE.matcher(url).find();
return match(url) || url.matches(RULE);
}
public static List<String> getRegex() {
@ -55,25 +54,22 @@ public class Sniffer {
return regex;
}
public static List<String> getProxy() {
for (Rule rule : ApiConfig.get().getRules()) if ("proxy".equals(rule.getName())) return rule.getHosts();
return Collections.emptyList();
}
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)) return rule.getRegex();
for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (hosts.contains(host) || hosts.matches(host)) return rule.getRegex();
return Collections.emptyList();
}
private static boolean matchOrContain(String url) {
for (String regex : getRegex(Uri.parse(url))) return Pattern.compile(regex).matcher(url).find() || url.contains(regex);
return false;
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) {
for (String regex : getRegex()) return Pattern.compile(regex).matcher(url).find();
return false;
boolean match = false;
for (String regex : getRegex()) if (url.matches(regex)) match = true;
return match;
}
}

@ -25,14 +25,10 @@ public class ProxySelector extends java.net.ProxySelector {
this.proxy = getProxy(proxy);
}
public Proxy getProxy() {
return proxy;
}
@Override
public List<Proxy> select(URI uri) {
if (proxy == null || hosts == null || hosts.isEmpty() || uri.getHost() == null || "127.0.0.1".equals(uri.getHost())) return Collections.singletonList(Proxy.NO_PROXY);
for (String host : hosts) if (uri.getHost().contains(host)) return Collections.singletonList(proxy);
for (String host : hosts) if (uri.getHost().contains(host) || uri.getHost().matches(host)) return Collections.singletonList(proxy);
return Collections.singletonList(Proxy.NO_PROXY);
}

Loading…
Cancel
Save