feat:新增集数识别

This commit is contained in:
fanxb 2022-12-02 17:37:41 +08:00
parent 4e18f01ae3
commit f83bb9902e
4 changed files with 98 additions and 47 deletions

View File

@ -4,6 +4,9 @@ import path from 'path';
let pattern = new RegExp(/s(eason)?(\d+)/); let pattern = new RegExp(/s(eason)?(\d+)/);
let eNumPatternArr = [new RegExp(/e(\d+)/), new RegExp(/\((\d+)\)/), new RegExp(/(\d+)/), new RegExp(/\.(\d+)\./), new RegExp(/-(\d+)-/), new RegExp(/(\d+)/)];
let resolutionPattern = new RegExp(/(\d+[pP])/);
let resolutionArr = ['1k', '1K', '2k', '2K', '4k', '4K', '8k', '8K'];
let charSet = new Set([' ', '[', '.', '(', '']); let charSet = new Set([' ', '[', '.', '(', '']);
export default class InsertRule implements RuleInterface { export default class InsertRule implements RuleInterface {
@ -19,6 +22,7 @@ export default class InsertRule implements RuleInterface {
* *
*/ */
endAdd: string; endAdd: string;
eNumWidth: number;
constructor(data: any) { constructor(data: any) {
this.type = data.type; this.type = data.type;
@ -52,11 +56,34 @@ export default class InsertRule implements RuleInterface {
} }
getStr += char; getStr += char;
} }
} else if (this.type === 'eNum') {
let lowName = file.originName.toLocaleLowerCase();
for (let i in eNumPatternArr) {
let patternRes = lowName.match(eNumPatternArr[i]);
if (patternRes && patternRes.length > 1) {
getStr = patternRes[1];
for (let i = 0; i < this.eNumWidth - getStr.length; i++) {
getStr = '0' + getStr;
}
break;
}
}
} else if (this.type === 'resolution') {
let res = file.originName.match(resolutionPattern);
if (res && res.length > 1) {
getStr = res[1];
} else {
for (let i = 0; i < resolutionArr.length; i++) {
if (file.originName.indexOf(resolutionArr[i]) > -1) {
getStr = resolutionArr[i];
break;
}
}
}
} }
if (getStr && getStr.length > 0) { if (getStr && getStr.length > 0) {
file.realName = file.realName + this.frontAdd + getStr + this.endAdd; file.realName = file.realName + this.frontAdd + getStr + this.endAdd;
file.name = file.realName + file.expandName; file.name = file.realName + file.expandName;
} }
} }
} }

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang=""> <html lang="zh">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />

View File

@ -2,20 +2,18 @@
<div class="flex"> <div class="flex">
<span class="left">识别类型</span> <span class="left">识别类型</span>
<div class="location"> <div class="location">
<el-radio v-model="ruleObj.data.type" label="season" <el-radio v-for="item in radioList" :key="item.code" v-model="ruleObj.data.type" :label="item.code"
>季号识别 >{{ item.label }}
<el-tooltip effect="dark" :content="message2" placement="top"> <el-tooltip effect="dark" :content="item.message" placement="top">
<el-icon><InfoFilled /></el-icon>
</el-tooltip>
</el-radio>
<el-radio v-model="ruleObj.data.type" label="name"
>剧名/电影名识别
<el-tooltip effect="dark" :content="message2" placement="top">
<el-icon><InfoFilled /></el-icon> <el-icon><InfoFilled /></el-icon>
</el-tooltip> </el-tooltip>
</el-radio> </el-radio>
</div> </div>
</div> </div>
<div class="flex" v-if="ruleObj.data.type == 'eNum'">
<div class="left">集数宽度:</div>
<el-input-number :min="1" v-model="ruleObj.data.eNumWidth" />
</div>
<div class="flex"> <div class="flex">
<div class="left">前面追加:</div> <div class="left">前面追加:</div>
<el-input v-model="ruleObj.data.frontAdd" placeholder="识别内容前面追加,未识别到不会追加" style="width: 20em" /> <el-input v-model="ruleObj.data.frontAdd" placeholder="识别内容前面追加,未识别到不会追加" style="width: 20em" />
@ -34,9 +32,29 @@ export default {
components: { InfoFilled }, components: { InfoFilled },
data() { data() {
return { return {
message1: '通过识别文件夹名称获取季号,放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的', radioList: [
message2: {
label: "季号识别",
message: '通过识别文件夹名称获取季号,放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的',
code: "season",
},
{
label: "集数识别",
message: "通过提取文件名称来提取集数,支持 E数字/e数字/(数字)/(数字)/.数字/-数字/纯数字 。优先级依次递减,如果存在多组纯数字,选择第一组",
code: "eNum",
},
{
label: "剧名/电影名识别",
message:
"如果父文件夹包含season字段那么会从父文件夹的父文件夹名称中取剧名否则将从父文件夹名称中取电影名。规则为从开头开始取直到遇见第一个空格/./[等符号", "如果父文件夹包含season字段那么会从父文件夹的父文件夹名称中取剧名否则将从父文件夹名称中取电影名。规则为从开头开始取直到遇见第一个空格/./[等符号",
code: "name",
},
{
label: "分辨率识别",
message: "通过文件名提取出分辨率,支持 数字P/数字p/1k/1K/2k/2K/4k/4K",
code: "resolution",
},
],
ruleObj: { ruleObj: {
type: "auto", type: "auto",
message: "", message: "",
@ -44,6 +62,7 @@ export default {
type: "", type: "",
frontAdd: "", frontAdd: "",
endAdd: "", endAdd: "",
eNumWidth: 2,
}, },
}, },
}; };
@ -60,7 +79,10 @@ export default {
this.$message({ message: "请选择识别类型", type: "warning" }); this.$message({ message: "请选择识别类型", type: "warning" });
return null; return null;
} }
this.ruleObj.message = `自动识别:"${this.ruleObj.data.type == "season" ? "季号" : "剧名/电影名识别"}";`; this.ruleObj.message = `自动识别:"${this.radioList.filter((item) => item.code == this.ruleObj.data.type)[0].label}";`;
if (this.ruleObj.data.type == "eNum") {
this.ruleObj.message += "集数宽度:" + this.ruleObj.data.eNumWidth + ";";
}
if (this.ruleObj.data.frontAdd.length > 0) { if (this.ruleObj.data.frontAdd.length > 0) {
this.ruleObj.message += `前缀添加:${this.ruleObj.data.frontAdd}`; this.ruleObj.message += `前缀添加:${this.ruleObj.data.frontAdd}`;
} }

View File

@ -25,7 +25,6 @@
<div> <div>
<el-button type="primary" size="small" @click="selectAllFiles">反选</el-button> <el-button type="primary" size="small" @click="selectAllFiles">反选</el-button>
<el-button type="danger" size="small" @click="deleteCheckedFiles">删除</el-button> <el-button type="danger" size="small" @click="deleteCheckedFiles">删除</el-button>
<template v-if="showMove">
<el-button type="primary" size="small" @click="moveIndex('top')"> <el-button type="primary" size="small" @click="moveIndex('top')">
<el-tooltip effect="dark" content="上移规则" placement="top"> <el-tooltip effect="dark" content="上移规则" placement="top">
<el-icon><top /></el-icon> <el-icon><top /></el-icon>
@ -36,7 +35,6 @@
><el-icon><bottom /></el-icon ><el-icon><bottom /></el-icon
></el-tooltip> ></el-tooltip>
</el-button> </el-button>
</template>
</div> </div>
<div class="fileBlock"> <div class="fileBlock">
<!-- 左侧原始文件名 --> <!-- 左侧原始文件名 -->
@ -94,11 +92,7 @@ export default {
timer: null, // timer: null, //
}; };
}, },
computed: { computed: {},
showMove() {
return this.fileList.filter((item) => item.checked == true).length == 1;
},
},
async created() { async created() {
this.savePathList = await HttpUtil.get("/file/path"); this.savePathList = await HttpUtil.get("/file/path");
window.isWindows = await HttpUtil.get("/file/isWindows"); window.isWindows = await HttpUtil.get("/file/isWindows");
@ -180,22 +174,30 @@ export default {
}, },
// //
async moveIndex(type) { async moveIndex(type) {
let temp = this.fileList.filter((item) => item.checked == true)[0]; let temps = this.fileList.filter((item) => item.checked == true);
let index = this.fileList.indexOf(temp); if (temps.length == 0) {
let newIndex; this.$message({ type: "warning", message: "未选中文件,无法移动" });
return;
}
if (type == "top") { if (type == "top") {
if (index == 0) { if (this.fileList.indexOf(temps[0]) == 0) {
this.$message({ type: "warning", message: "无法上移" });
return; return;
} }
newIndex = index - 1;
} else { } else {
if (index == this.fileList.length - 1) { if (this.fileList.indexOf(temps[temps.length - 1]) == this.fileList.length - 1) {
this.$message({ type: "warning", message: "无法下移" });
return; return;
} }
newIndex = index + 1; temps = temps.reverse();
} }
for (let i in temps) {
let temp = temps[i];
let index = this.fileList.indexOf(temp);
let newIndex = index + (type == "top" ? -1 : 1);
this.fileList[index] = this.fileList[newIndex]; this.fileList[index] = this.fileList[newIndex];
this.fileList[newIndex] = temp; this.fileList[newIndex] = temp;
}
this.fileList = [...this.fileList]; this.fileList = [...this.fileList];
this.needPreview = true; this.needPreview = true;
if (this.timer != null) { if (this.timer != null) {