Add exclude for rule

pull/270/head
FongMi 2 years ago
parent 43c509adda
commit 33d783c1ef
  1. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  2. 10
      app/src/main/java/com/fongmi/android/tv/bean/Rule.java
  3. 28
      app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java
  4. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java

@ -265,7 +265,7 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, GroupP
private void getLive() {
mBinding.control.home.setText(getHome().getName());
mPlayers.setPlayer(getPlayerType(-1));
mPlayers.setPlayer(Setting.getLivePlayer());
mViewModel.getLive(getHome());
setPlayerView();
setDecodeView();

@ -23,11 +23,17 @@ public class Rule {
private List<String> regex;
@SerializedName("script")
private List<String> script;
@SerializedName("exclude")
private List<String> exclude;
public static Rule create(String name) {
return new Rule(name);
}
public static Rule empty() {
return new Rule("");
}
public Rule(String name) {
this.name = name;
}
@ -54,6 +60,10 @@ public class Rule {
return script == null ? Collections.emptyList() : script;
}
public List<String> getExclude() {
return exclude == null ? Collections.emptyList() : exclude;
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) return true;

@ -9,7 +9,6 @@ import com.github.catvod.utils.Json;
import com.github.catvod.utils.Util;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -20,7 +19,7 @@ public class Sniffer {
public static final Pattern CLICKER = Pattern.compile("\\[a=cr:(\\{.*?\\})\\/](.*?)\\[\\/a]");
public static final Pattern AI_PUSH = Pattern.compile("(http|https|rtmp|rtsp|smb|ftp|thunder|magnet|ed2k|mitv|tvbox-xg|jianpian|video):[^\\s]+", Pattern.MULTILINE);
public static final Pattern SNIFFER = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)|http((?!http).)*?video/tos*");
public static final Pattern SNIFFER = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)|http((?!http).)*?video/tos*|http((?!http).)*?obj/tos*");
public static final List<String> THUNDER = Arrays.asList("thunder", "magnet", "ed2k");
@ -51,23 +50,26 @@ public class Sniffer {
}
private static boolean containOrMatch(String url) {
List<String> items = getRegex(UrlUtil.uri(url));
for (String regex : items) if (url.contains(regex)) return true;
for (String regex : items) if (Pattern.compile(regex).matcher(url).find()) return true;
Rule rule = getRule(UrlUtil.uri(url));
for (String exclude : rule.getExclude()) if (url.contains(exclude)) return false;
for (String exclude : rule.getExclude()) if (Pattern.compile(exclude).matcher(url).find()) return false;
for (String regex : rule.getRegex()) if (url.contains(regex)) return true;
for (String regex : rule.getRegex()) if (Pattern.compile(regex).matcher(url).find()) return true;
return false;
}
public static List<String> getRegex(Uri uri) {
if (uri.getHost() == null) return Collections.emptyList();
public static Rule getRule(Uri uri) {
if (uri.getHost() == null) return Rule.empty();
String hosts = TextUtils.join(",", Arrays.asList(UrlUtil.host(uri), UrlUtil.host(uri.getQueryParameter("url"))));
for (Rule rule : VodConfig.get().getRules()) for (String host : rule.getHosts()) if (Util.containOrMatch(hosts, host)) return rule.getRegex();
return Collections.emptyList();
for (Rule rule : VodConfig.get().getRules()) for (String host : rule.getHosts()) if (Util.containOrMatch(hosts, host)) return rule;
return Rule.empty();
}
public static List<String> getRegex(Uri uri) {
return getRule(uri).getRegex();
}
public static List<String> getScript(Uri uri) {
if (uri.getHost() == null) return Collections.emptyList();
String hosts = TextUtils.join(",", Arrays.asList(UrlUtil.host(uri), UrlUtil.host(uri.getQueryParameter("url"))));
for (Rule rule : VodConfig.get().getRules()) for (String host : rule.getHosts()) if (Util.containOrMatch(hosts, host)) return rule.getScript();
return Collections.emptyList();
return getRule(uri).getScript();
}
}

@ -290,7 +290,7 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, Custom
private void getLive() {
mBinding.control.action.home.setText(getHome().getName());
mPlayers.setPlayer(getPlayerType(-1));
mPlayers.setPlayer(Setting.getLivePlayer());
mViewModel.getLive(getHome());
setPlayerView();
setDecodeView();

Loading…
Cancel
Save