Skip to content

Commit

Permalink
feat #229: 一键下载支持以标题/小标题是否匹配正则表达式为条件
Browse files Browse the repository at this point in the history
  • Loading branch information
nICEnnnnnnnLee committed Oct 23, 2024
1 parent 1daa4ce commit 547e43d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/nicelee/bilibili/util/batchdownload/BatchDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public BatchDownloadsBuilder(InputStream in) {
final static Pattern urlPattern = Pattern.compile("^\\[(url|favorite):(.*)\\]$");
final static Pattern stopPattern = Pattern.compile("^stop\\.condition *= *(.*)$");
final static Pattern downloadPattern = Pattern.compile("^download\\.condition *= *(.*)$");
final static Pattern expressionPattern = Pattern.compile("^([^:!<>]+)([:!<>])([^:!<>]+)$");
// final static Pattern expressionPattern = Pattern.compile("^([^:!<>]+)([:!<>])([^:!<>]+)$");
final static Pattern expressionPattern = Pattern.compile("^([^:!<>]+)([:!<>])(.+)$");
final static Pattern otherSettingsPattern = Pattern.compile("^([^=]+) *= *(.*)$");

public List<BatchDownload> Build() {
Expand Down
19 changes: 19 additions & 0 deletions src/nicelee/bilibili/util/batchdownload/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.regex.Pattern;

import nicelee.bilibili.enums.VideoQualityEnum;
import nicelee.bilibili.model.ClipInfo;
import nicelee.bilibili.util.Logger;
import nicelee.bilibili.util.RepoUtil;
import nicelee.ui.Global;

Expand All @@ -26,6 +28,7 @@ public class Condition {
validsOfLeft.add("favTime");
validsOfLeft.add("cTime");
validsOfLeft.add("avTitle");
validsOfLeft.add("clipTitle");
validsOfOperator = new HashSet<>();
validsOfOperator.add(":");
validsOfOperator.add("!");
Expand Down Expand Up @@ -111,6 +114,22 @@ public boolean match(ClipInfo clip, int page) {
}
}
throw new RuntimeException("不合法的表达式 " + left + operator + right);
case "avTitle":
boolean eq = operator.equals(":");
if (!eq && !operator.equals("!")) {
throw new RuntimeException("avTitle操作符只能为 : 或者 !, 不能是: " + operator);
}
boolean m0 = Pattern.matches(right, clip.getAvTitle());
Logger.printf("标题正则匹配: %s\nPattern: %s\nContent: %s", m0, right, clip.getAvTitle());
return eq? m0 : !m0;
case "clipTitle":
boolean eq = operator.equals(":");
if (!eq && !operator.equals("!")) {
throw new RuntimeException("clipTitle操作符只能为 : 或者 !, 不能是: " + operator);
}
boolean m1 = Pattern.matches(right, clip.getTitle());
Logger.printf("小标题正则匹配: %s\nPattern: %s\nContent: %s", m1, right, clip.getTitle());
return eq? m1 : !m1;
}

return true;
Expand Down

0 comments on commit 547e43d

Please sign in to comment.