From f83bb9902e385f719487571018f693f005576fe9 Mon Sep 17 00:00:00 2001 From: fanxb Date: Fri, 2 Dec 2022 17:37:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E=E9=9B=86=E6=95=B0?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/bo/rules/AutoRule.ts | 29 +++++++- openRenamerFront/public/index.html | 2 +- .../src/components/rules/AutoRule.vue | 48 ++++++++++---- openRenamerFront/src/views/home/Home.vue | 66 ++++++++++--------- 4 files changed, 98 insertions(+), 47 deletions(-) diff --git a/openRenamerBackend/entity/bo/rules/AutoRule.ts b/openRenamerBackend/entity/bo/rules/AutoRule.ts index adc1243..75799aa 100644 --- a/openRenamerBackend/entity/bo/rules/AutoRule.ts +++ b/openRenamerBackend/entity/bo/rules/AutoRule.ts @@ -4,6 +4,9 @@ import path from 'path'; 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([' ', '[', '.', '(', '(']); export default class InsertRule implements RuleInterface { @@ -19,6 +22,7 @@ export default class InsertRule implements RuleInterface { * 后面追加 */ endAdd: string; + eNumWidth: number; constructor(data: any) { this.type = data.type; @@ -52,11 +56,34 @@ export default class InsertRule implements RuleInterface { } 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) { file.realName = file.realName + this.frontAdd + getStr + this.endAdd; file.name = file.realName + file.expandName; } - } } \ No newline at end of file diff --git a/openRenamerFront/public/index.html b/openRenamerFront/public/index.html index 478ac5f..cb46efa 100644 --- a/openRenamerFront/public/index.html +++ b/openRenamerFront/public/index.html @@ -1,5 +1,5 @@ - + diff --git a/openRenamerFront/src/components/rules/AutoRule.vue b/openRenamerFront/src/components/rules/AutoRule.vue index a7ad2e8..bdd1a8c 100644 --- a/openRenamerFront/src/components/rules/AutoRule.vue +++ b/openRenamerFront/src/components/rules/AutoRule.vue @@ -2,20 +2,18 @@
识别类型:
- 季号识别 - - - - - 剧名/电影名识别 - + {{ item.label }} +
+
+
集数宽度:
+ +
前面追加:
@@ -34,9 +32,29 @@ export default { components: { InfoFilled }, data() { return { - message1: '通过识别文件夹名称获取季号,放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的', - message2: - "如果父文件夹包含season字段,那么会从父文件夹的父文件夹名称中取剧名,否则将从父文件夹名称中取电影名。规则为从开头开始取,直到遇见第一个空格/./[等符号", + radioList: [ + { + label: "季号识别", + message: '通过识别文件夹名称获取季号,放在插入文本最后,可识别"s1","s01","season 01","season01"等以s或season开头后接数字的', + code: "season", + }, + { + label: "集数识别", + message: "通过提取文件名称来提取集数,支持 E数字/e数字/(数字)/(数字)/.数字/-数字/纯数字 。优先级依次递减,如果存在多组纯数字,选择第一组", + code: "eNum", + }, + { + label: "剧名/电影名识别", + message: + "如果父文件夹包含season字段,那么会从父文件夹的父文件夹名称中取剧名,否则将从父文件夹名称中取电影名。规则为从开头开始取,直到遇见第一个空格/./[等符号", + code: "name", + }, + { + label: "分辨率识别", + message: "通过文件名提取出分辨率,支持 数字P/数字p/1k/1K/2k/2K/4k/4K", + code: "resolution", + }, + ], ruleObj: { type: "auto", message: "", @@ -44,6 +62,7 @@ export default { type: "", frontAdd: "", endAdd: "", + eNumWidth: 2, }, }, }; @@ -60,7 +79,10 @@ export default { this.$message({ message: "请选择识别类型", type: "warning" }); 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) { this.ruleObj.message += `前缀添加:${this.ruleObj.data.frontAdd}`; } diff --git a/openRenamerFront/src/views/home/Home.vue b/openRenamerFront/src/views/home/Home.vue index 8fde389..35c0b37 100644 --- a/openRenamerFront/src/views/home/Home.vue +++ b/openRenamerFront/src/views/home/Home.vue @@ -25,18 +25,16 @@
反选 删除 - + + + + + + + +
@@ -94,11 +92,7 @@ export default { timer: null, //修改顺序计时器 }; }, - computed: { - showMove() { - return this.fileList.filter((item) => item.checked == true).length == 1; - }, - }, + computed: {}, async created() { this.savePathList = await HttpUtil.get("/file/path"); window.isWindows = await HttpUtil.get("/file/isWindows"); @@ -180,22 +174,30 @@ export default { }, //移动文件顺序 async moveIndex(type) { - let temp = this.fileList.filter((item) => item.checked == true)[0]; - let index = this.fileList.indexOf(temp); - let newIndex; - if (type == "top") { - if (index == 0) { - return; - } - newIndex = index - 1; - } else { - if (index == this.fileList.length - 1) { - return; - } - newIndex = index + 1; + let temps = this.fileList.filter((item) => item.checked == true); + if (temps.length == 0) { + this.$message({ type: "warning", message: "未选中文件,无法移动" }); + return; + } + if (type == "top") { + if (this.fileList.indexOf(temps[0]) == 0) { + this.$message({ type: "warning", message: "无法上移" }); + return; + } + } else { + if (this.fileList.indexOf(temps[temps.length - 1]) == this.fileList.length - 1) { + this.$message({ type: "warning", message: "无法下移" }); + return; + } + 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[newIndex] = temp; } - this.fileList[index] = this.fileList[newIndex]; - this.fileList[newIndex] = temp; this.fileList = [...this.fileList]; this.needPreview = true; if (this.timer != null) {