From 3578fa50c971deb71c58a5a0754a53e335d52c29 Mon Sep 17 00:00:00 2001 From: FongMi Date: Thu, 28 Sep 2023 23:22:46 +0800 Subject: [PATCH] Fix bug --- .../com/fongmi/android/tv/utils/Sniffer.java | 26 +++++-------------- .../com/github/catvod/net/ProxySelector.java | 3 ++- .../java/com/github/catvod/utils/Util.java | 8 ++++++ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java b/app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java index 135f0d0f5..5fa8a903c 100644 --- a/app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java +++ b/app/src/main/java/com/fongmi/android/tv/utils/Sniffer.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 getRegex() { - List 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 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 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; - } } diff --git a/catvod/src/main/java/com/github/catvod/net/ProxySelector.java b/catvod/src/main/java/com/github/catvod/net/ProxySelector.java index 53315e49f..1c53589df 100644 --- a/catvod/src/main/java/com/github/catvod/net/ProxySelector.java +++ b/catvod/src/main/java/com/github/catvod/net/ProxySelector.java @@ -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 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); } diff --git a/catvod/src/main/java/com/github/catvod/utils/Util.java b/catvod/src/main/java/com/github/catvod/utils/Util.java index e9ab3c1e1..3d6f3569e 100644 --- a/catvod/src/main/java/com/github/catvod/utils/Util.java +++ b/catvod/src/main/java/com/github/catvod/utils/Util.java @@ -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();