diff --git a/app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java b/app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java index 05dcb5381..136251a08 100644 --- a/app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java +++ b/app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java @@ -116,7 +116,7 @@ public class ExoUtil { if (subs.size() > 0) builder.setSubtitleConfigurations(getSubtitles(subs)); builder.setAllowChunklessPreparation(Players.isHard()); if (mimeType != null) builder.setMimeType(mimeType); - builder.setAds(Sniffer.getAdsRegex(uri)); + builder.setAds(Sniffer.getRegex(uri)); return builder.build(); } diff --git a/app/src/main/java/com/fongmi/android/tv/server/Nano.java b/app/src/main/java/com/fongmi/android/tv/server/Nano.java index 3ebf03ebc..12edc3143 100644 --- a/app/src/main/java/com/fongmi/android/tv/server/Nano.java +++ b/app/src/main/java/com/fongmi/android/tv/server/Nano.java @@ -125,7 +125,7 @@ public class Nano extends NanoHTTPD { try { String url = session.getParms().get("url"); String result = M3U8.get(url, session.getHeaders()); - for (String ad : Sniffer.getAdsRegex(Uri.parse(url))) result = result.replaceAll(ad, ""); + for (String ad : Sniffer.getRegex(Uri.parse(url))) result = result.replaceAll(ad, ""); return newFixedLengthResponse(Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT, result); } catch (Exception e) { return createErrorResponse(e.getMessage()); 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 69ab34795..6b17fbdc4 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 @@ -6,6 +6,7 @@ import com.fongmi.android.tv.api.ApiConfig; import com.fongmi.android.tv.bean.Rule; import com.github.catvod.crawler.SpiderDebug; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -17,6 +18,16 @@ public class Sniffer { public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.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*"); + 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; + } + + private static boolean match(String url) { + for (String regex : getRegex()) return Pattern.compile(regex).matcher(url).find(); + return false; + } + public static boolean isVideoFormat(String url) { return isVideoFormat(url, new HashMap<>()); } @@ -29,25 +40,20 @@ public class Sniffer { return match(url) || RULE.matcher(url).find(); } - private static boolean matchOrContain(String url) { - Uri uri = Uri.parse(url); - if (uri.getHost() == null) return false; - for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (uri.getHost().contains(host)) for (String regex : rule.getRegex()) return Pattern.compile(regex).matcher(url).find() || url.contains(regex); - return false; - } - - private static boolean match(String url) { - for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (host.equals("*")) for (String regex : rule.getRegex()) return Pattern.compile(regex).matcher(url).find(); + public static boolean isAds(Uri uri) { + for (String regex : getRegex(uri)) if (regex.contains("#EXTINF")) return true; return false; } - public static boolean isAds(Uri uri) { - if (uri.getHost() != null) for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (uri.getHost().contains(host)) for (String regex : rule.getRegex()) if (regex.contains("#EXTINF")) return true; - return false; + 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; } - public static List getAdsRegex(Uri uri) { - if (uri.getHost() != null) for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (uri.getHost().contains(host)) return rule.getRegex(); + public static List getRegex(Uri uri) { + if (uri.getHost() == null) return Collections.emptyList(); + for (Rule rule : ApiConfig.get().getRules()) for (String host : rule.getHosts()) if (uri.getHost().contains(host)) return rule.getRegex(); return Collections.emptyList(); } }