Skip to content

Commit

Permalink
排除与匹配可以根据字幕组筛选
Browse files Browse the repository at this point in the history
  • Loading branch information
wushuo894 committed Nov 5, 2024
1 parent 0e53301 commit 8a25154
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/main/java/ani/rss/enums/StringEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class StringEnum {
public static final String YEAR_REG = " ?\\((19|20)\\d{2}\\)";
public static final String TMDB_ID_REG = " ?\\[tmdbid=(\\d+)]";
public static final String MAGNET_REG = "^magnet\\:\\?xt=urn:btih\\:(\\w+)";
public static final String SUBGROUP_REG_STR = "^\\{\\{(.+)}}:(.+)$";
}
21 changes: 17 additions & 4 deletions src/main/java/ani/rss/util/ItemsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
Expand Down Expand Up @@ -187,22 +188,34 @@ public static List<Item> getItems(Ani ani, String xml, Item newItem) {
.setSize(size)
.setPubDate(pubDate);

// 进行过滤
Function<String, String> map = s -> {
String subgroup = ReUtil.get(StringEnum.SUBGROUP_REG_STR, s, 1);
if (StrUtil.isBlank(subgroup)) {
return s;
}
if (subgroup.equals(newItem.getSubgroup())) {
return ReUtil.get(StringEnum.SUBGROUP_REG_STR, s, 2);
}
return "";
};

// 排除
if (!exclude.isEmpty()) {
if (exclude.stream().anyMatch(s -> ReUtil.contains(s, addNewItem.getTitle()))) {
if (exclude.stream().map(map).filter(StrUtil::isNotBlank).anyMatch(s -> ReUtil.contains(s, addNewItem.getTitle()))) {
continue;
}
}

// 匹配
if (!match.isEmpty()) {
if (match.stream().anyMatch(s -> !ReUtil.contains(s, addNewItem.getTitle()))) {
if (match.stream().map(map).filter(StrUtil::isNotBlank).anyMatch(s -> !ReUtil.contains(s, addNewItem.getTitle()))) {
continue;
}
}

// 全局排除
if (globalExclude) {
if (globalExcludeList.stream().anyMatch(s -> ReUtil.contains(s, addNewItem.getTitle()))) {
if (globalExcludeList.stream().map(map).filter(StrUtil::isNotBlank).anyMatch(s -> ReUtil.contains(s, addNewItem.getTitle()))) {
continue;
}
}
Expand Down
55 changes: 37 additions & 18 deletions ui/src/config/Exclude.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<template>
<el-dialog title="添加正则" v-if="add" v-model:model-value="add" center align-center width="300">
<el-form label-width="auto">
<el-form-item label="字幕组">
<el-input placeholder="留空匹配所有字幕组" v-model="subgroup"></el-input>
</el-form-item>
<div style="margin: 4px;"></div>
<el-form-item label="正则">
<el-input placeholder="如 720、简、\d-\d" v-model="exclude"></el-input>
</el-form-item>
</el-form>
<div style="width: 100%;display: flex;justify-content: end;margin-top: 8px;">
<el-button bg text @click="addExclude">添加</el-button>
</div>
</el-dialog>

<div style="width: 100%;">
<div class="flex gap-2">
<el-tag v-if="!props.exclude.length"
Expand All @@ -16,17 +31,9 @@
>
{{ tag }}
</el-tag>
<el-input
style="max-width: 120px;margin-right: 4px;margin-bottom: 4px;"
v-if="excludeVisible"
ref="InputRef"
v-model="excludeValue"
class="w-20"
size="small"
@keyup.enter="handleInputConfirm"
@blur="handleInputConfirm"
/>
<el-button v-else class="button-new-tag" size="small" @click="showInput" bg text
<el-button class="button-new-tag" size="small" @click="()=>{
add = true
}" bg text
style="margin-right: 4px;margin-bottom: 4px;">
+
</el-button>
Expand All @@ -50,26 +57,21 @@
import {ref} from "vue";
import api from "../api.js";
import {ElMessage} from "element-plus";
const excludeVisible = ref(false)
const excludeValue = ref('')
const handleClose = (tag) => {
props.exclude.splice(props.exclude.indexOf(tag), 1)
}
const add = ref(false)
const InputRef = ref()
const showInput = () => {
excludeVisible.value = true
InputRef.value?.input?.focus()
}
const handleInputConfirm = () => {
if (excludeValue.value) {
props.exclude.push(excludeValue.value)
}
excludeVisible.value = false
excludeValue.value = ''
}
Expand All @@ -94,5 +96,22 @@ let importExclude = () => {
}
let subgroup = ref('')
let exclude = ref('')
let addExclude = () => {
if (!exclude.value) {
ElMessage.error('正则为空')
return
}
if (subgroup.value) {
exclude.value = `{{${subgroup.value}}}:${exclude.value}`
}
props.exclude.push(exclude.value)
subgroup.value = ''
exclude.value = ''
add.value = false
}
let props = defineProps(['exclude', 'importExclude', 'showText'])
</script>
2 changes: 1 addition & 1 deletion ui/src/home/Ani.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<BackRss ref="backRss" :ani="props.ani"/>
<Mikan ref="mikanRef" @add="args => {
ani.subgroup = args.group
ani.match = args.match
ani.match = args.match.map(s => `{{${args.group}}}:${s}`)
ani.url = args.url
}"/>
<div style="height: 500px;">
Expand Down

0 comments on commit 8a25154

Please sign in to comment.