Skip to content

Commit

Permalink
Merge pull request #281 from zetalpha/main
Browse files Browse the repository at this point in the history
优化静态筛选
  • Loading branch information
Hiram-Wong authored Jun 30, 2024
2 parents fcf0381 + f9d549a commit ea25e2c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/renderer/src/locales/lang/en_US/pages/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ export default {
rule: {
demo:'demo',
class: 'Class',
class_name:'class_name',
class_url:'class_url',
cateExclude: 'CateExclude',
link: 'Link',
filter: 'Filter',
Expand Down Expand Up @@ -498,6 +500,8 @@ export default {
reg: 'Reg',
},
placeholder: {
classNameTip:'classname(e.g movie&tv)',
classUrlTip:'classurl(e.g 1&2)',
classParseTip: 'Selector(e.g. list;title;url;match)',
cateExcludeTip: 'Excluded(e.g. HOME|APP)',
linkTip: 'Splicing fyclass(e.g. /id/fyclass.html)',
Expand All @@ -517,6 +521,7 @@ export default {
inputNoClassParse: 'Parms classParse is empty',
sourceFirst: 'Get source first',
inputNoFilterAndFilterInfo: 'Parms filter or filterInfo is empty',
classResultisEmpty:'Please process the major categories first'
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/src/locales/lang/zh_CN/pages/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ export default {
rule: {
demo:'示例',
class: '大类',
class_name:'class_name',
class_url:'class_url',
cateExclude: '排除',
link: '链接',
filter: '筛选',
Expand Down Expand Up @@ -498,6 +500,8 @@ export default {
reg: '正则',
},
placeholder: {
classNameTip:'classname(例如 电影&剧集)',
classUrlTip:'classurl(例如 1&2)',
classParseTip: '选择器(如 list;title;url;match)',
cateExcludeTip: '排除(如 首页|留言|APP)',
linkTip: '拼接fyclass(如 /id/fyclass.html)',
Expand All @@ -517,6 +521,7 @@ export default {
inputNoClassParse: '参数大类为空',
sourceFirst: '必须先获取源代码',
inputNoFilterAndFilterInfo: '参数筛选或筛选详细为空',
classResultisEmpty:'请先进行大类处理'
},
},
},
Expand Down
94 changes: 72 additions & 22 deletions src/renderer/src/pages/setting/editSource/Sift.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<div>
<t-button theme="default" @click="demo">{{ $t('pages.setting.editSource.sift.rule.demo') }}</t-button>
</div>
<t-input v-model="form.class_name" :label="$t('pages.setting.editSource.sift.rule.class_name')"
:placeholder="$t('pages.setting.editSource.sift.placeholder.classNameTip')" class="input w-100%" />
<t-input v-model="form.class_url" :label="$t('pages.setting.editSource.sift.rule.class_url')"
:placeholder="$t('pages.setting.editSource.sift.placeholder.classUrlTip')" class="input w-100%" />
<t-input v-model="form.class_parse" :label="$t('pages.setting.editSource.sift.rule.class')"
:placeholder="$t('pages.setting.editSource.sift.placeholder.classParseTip')" class="input w-100%" />
<t-input v-model="form.cate_exclude" :label="$t('pages.setting.editSource.sift.rule.cateExclude')"
Expand Down Expand Up @@ -160,7 +164,7 @@ import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import { t } from '@/locales';
import { useSettingStore } from '@/store';
import { getHtml, copyToClipboardApi,encodeGzip, encodeBtoa } from '@/utils/tool';
import { getHtml, copyToClipboardApi, encodeGzip, encodeBtoa } from '@/utils/tool';
import { getFilters, processCategories } from '@/utils/drpy/lab/hipyFilter';
import axios from 'axios';
import { json } from 'node:stream/consumers';
Expand Down Expand Up @@ -209,6 +213,8 @@ let form = ref({
source: ''
},
class_parse: '',
class_name: '',
class_url: '',
cate_exclude: '首页|留言|APP|下载|资讯|新闻|动态',
reurl: '',
filter: '',
Expand All @@ -217,6 +223,7 @@ let form = ref({
matchs: {
},
classResult: {},
// matchs: {
// plot: 'show(.*?)/id',
// area: 'show(.*?)/id',
Expand All @@ -238,14 +245,14 @@ const isVisible = reactive({
tool: false
});
const demo=()=>{
form.value.req.url="https://hapihd.com/index.php/vod/show/id/dianying.html";
form.value.class_parse=String.raw`.navbar-items li;a&&Text;a&&href;/(\w+).html`;
form.value.reurl="https://hapihd.com/index.php/vod/show/id/fyclass.html";
form.value.cate_exclude="更新|热搜榜";
form.value.filter="body&&.scroll-box";
form.value.filterInfo=";.module-item-title&&Text;body&&a;a&&Text;a&&href";
form.value.matchs={
const demo = () => {
form.value.req.url = "https://hapihd.com/index.php/vod/show/id/dianying.html";
form.value.class_parse = String.raw`.navbar-items li;a&&Text;a&&href;/(\w+).html`;
form.value.reurl = "https://hapihd.com/index.php/vod/show/id/fyclass.html";
form.value.cate_exclude = "更新|热搜榜";
form.value.filter = "body&&.scroll-box";
form.value.filterInfo = ";.module-item-title&&Text;body&&a;a&&Text;a&&href";
form.value.matchs = {
剧情: 'show(.*?)/id',
地区: 'show(.*?)/id',
语言: '(/lang.*?)\.html@@',
Expand Down Expand Up @@ -464,30 +471,63 @@ const getMatchs = () => {
key: item,
value: form.value.matchs[item]
}));
}
function uniqueObjectsByProperty(array, key){
const map = new Map();
array.forEach(item => {
const keyValue = item[key];
map.set(keyValue, item);
});
return Array.from(map.values());
}
// inputs.value = [
// { id: 1, value: '' },
// { id: 2, value: '' },
// { id: 3, value: '' }
// ];
function concatenateObjects(array) {
return array.reduce((accumulator, current) => {
accumulator.m = accumulator.m ? `${accumulator.m}&${current.m}` : current.m;
accumulator.title = accumulator.title ? `${accumulator.title}&${current.title}` : current.title;
return accumulator;
}, { m: '', title: '' });
}
const actionClass = () => {
const { class_parse = '', cate_exclude = '', reurl = '' } = form.value;
const { class_parse = '', class_name = '', class_url = '', cate_exclude = '', reurl = '' } = form.value;
const { url } = form.value.req;
const contentHtml = form.value.content.source;
if (!class_parse) {
if (!class_parse && !class_name && !class_url) {
MessagePlugin.warning(t('pages.setting.editSource.sift.message.inputNoClassParse'));
return;
};
if (!contentHtml.trim()) {
MessagePlugin.warning(t('pages.setting.editSource.sift.message.sourceFirst'));
return;
}
const response = processCategories(contentHtml, class_parse, cate_exclude, reurl, url);
console.log(contentHtml, class_parse, cate_exclude, reurl, url)
let response = processCategories(contentHtml, class_parse, cate_exclude, reurl, url);
let set = new Set();
if (class_name && class_url) {
if (response.hasOwnProperty("m")) {
response.m += "&" + class_url;
response.title += "&" + class_name;
}
}
if (Object.keys(response).length > 0) {
response.m.split("&").map((x, i) => {
set.add({ m: x, title: response.title.split("&")[i] })
})
var rs = uniqueObjectsByProperty(Array.from(set), 'm');
response = concatenateObjects(rs);
}
if (Object.keys(response).length == 0) {
if (class_name && class_url) {
response.m = class_url;
response.title = class_name;
}
}
console.log(response)
const transformData = (data) => {
const titles = data.title.split('&');
Expand All @@ -500,20 +540,32 @@ const actionClass = () => {
}));
}
if (response?.title && response?.m) form.value.content.debug = transformData(response);
form.value.classResult = transformData(response);
changeNav('debug', 'class');
};
const batchResults = () => {
let r = form.value.content.debug;
let classResult = form.value.classResult;
//console.log(r);
const { filterInfo = '', filter = '', matchs } = form.value;
if (!(filterInfo && filter)) {
MessagePlugin.warning(t('pages.setting.editSource.sift.message.inputNoFilterAndFilterInfo'));
return;
};
if (Object.keys(classResult).length == 0) {
MessagePlugin.warning(t('pages.setting.editSource.sift.message.classResultisEmpty'));
return;
}
if (Object.keys(classResult).length == 0) {
MessagePlugin.warning(t('pages.setting.editSource.sift.message.classResultisEmpty'));
return;
}
// 调用batchFetch并处理结果
batchFetch(r)
batchFetch(classResult)
.then(results => {
let rs = {};
results.map(item => {
Expand All @@ -534,8 +586,6 @@ const batchResults = () => {
};
const batchFetch = async (obj) => {
let { method, encode, header, body, contentType } = form.value.req;
header = header ? header : '{}';
Expand Down

0 comments on commit ea25e2c

Please sign in to comment.