pull/183/head
FongMi 2 years ago
parent 784fc51e88
commit 3578fa50c9
  1. 26
      app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java
  2. 3
      catvod/src/main/java/com/github/catvod/net/ProxySelector.java
  3. 8
      catvod/src/main/java/com/github/catvod/utils/Util.java

@ -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;
}
}

@ -2,6 +2,7 @@ package com.github.catvod.net;
import android.net.Uri;
import com.github.catvod.utils.Util;
import com.orhanobut.logger.Logger;
import java.io.IOException;
@ -32,7 +33,7 @@ public class ProxySelector extends java.net.ProxySelector {
public List<Proxy> select(URI uri) {
Logger.t(TAG).d(uri.getHost());
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) || uri.getHost().matches(host)) return Collections.singletonList(proxy);
for (String host : hosts) if (Util.containOrMatch(uri.getHost(), host)) return Collections.singletonList(proxy);
return Collections.singletonList(Proxy.NO_PROXY);
}

@ -109,6 +109,14 @@ public class Util {
return md5(Path.jar(name)).equalsIgnoreCase(md5);
}
public static boolean containOrMatch(String text, String regex) {
try {
return text.contains(regex) || text.matches(regex);
} catch (Exception e) {
return false;
}
}
public static long format(SimpleDateFormat format, String src) {
try {
return format.parse(src).getTime();

Loading…
Cancel
Save