diff --git a/Dockerfile b/Dockerfile index f383b4c..8d9f636 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM node:lts-buster-slim WORKDIR /app COPY ./openRenamerBackend /app -RUN chmod 777 -R /app +RUN chmod 777 -R /app && npm install -g pnpm typescript --registry https://registry.npmmirror.com ENV PORT 80 CMD ["bash", "start.sh"] diff --git a/build.sh b/build.sh index 4ff9096..88ac01e 100644 --- a/build.sh +++ b/build.sh @@ -13,4 +13,4 @@ rm -rf openRenamerBackend/node_modules #docker build -t fleyx/open-renamer:$0 --push . # 多平台打包并推送 docker buildx build -t fleyx/open-renamer:$1 --platform linux/amd64,linux/arm64 --push . -docker buildx build -t fleyx/open-renamer:latset --platform linux/amd64,linux/arm64 --push . +docker buildx build -t fleyx/open-renamer:latest --platform linux/amd64,linux/arm64 --push . diff --git a/openRenamerBackend/entity/bo/rules/AutoRule.ts b/openRenamerBackend/entity/bo/rules/AutoRule.ts index 7ab9eec..ced71e4 100644 --- a/openRenamerBackend/entity/bo/rules/AutoRule.ts +++ b/openRenamerBackend/entity/bo/rules/AutoRule.ts @@ -1,6 +1,7 @@ import RuleInterface from "./RuleInterface"; import FileObj from "../../vo/FileObj"; import path from 'path'; +import {getSeason} from "../../../util/MediaUtil"; let pattern = new RegExp(/s(eason)?(\d+)/); @@ -35,14 +36,12 @@ export default class InsertRule implements RuleInterface { deal(file: FileObj): void { //识别到的内容 let getStr = null; - let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern); + let season = getSeason(path.basename(file.path)); if (this.type === 'season') { - if (patternRes && patternRes[2]) { - getStr = patternRes[2]; - } + getStr = season; } else if (this.type === 'name') { let originName = null; - if (patternRes && patternRes[2]) { + if (season && season.length > 0) { //说明是剧集,取父文件夹的父文件夹名称 originName = path.basename(path.resolve(file.path, '..')); } else { diff --git a/openRenamerBackend/entity/bo/rules/InsertRule.ts b/openRenamerBackend/entity/bo/rules/InsertRule.ts index 965f11a..951dc8e 100644 --- a/openRenamerBackend/entity/bo/rules/InsertRule.ts +++ b/openRenamerBackend/entity/bo/rules/InsertRule.ts @@ -1,98 +1,95 @@ import RuleInterface from "./RuleInterface"; import FileObj from "../../vo/FileObj"; import path from 'path'; +import {getSeason} from "../../../util/MediaUtil"; -let pattern = new RegExp(/s(eason)?(\d+)/); export default class InsertRule implements RuleInterface { - /** - * 插入内容 - */ - insertContent: string; - /** - * 操作类别,front:前缀,backend:后缀,at:位置,replace:替换当前文件名 - */ - type: string; - /** - * 当type为at,时的位置,从1开始 - */ - atInput: number; - /** - * 当type为at,时的方向,true:从右到左,false:从左到右 - */ - atIsRightToleft: boolean; - /** - * 忽略拓展名,true:忽略,false:不忽略 - */ - ignorePostfix: boolean; - /** - 自动识别季号 - */ - autoSeason: boolean; - /** - 后缀过滤是否开启 - */ - endFilter: boolean; - /** - 有效后缀 - */ - validEnd: Array; + /** + * 插入内容 + */ + insertContent: string; + /** + * 操作类别,front:前缀,backend:后缀,at:位置,replace:替换当前文件名 + */ + type: string; + /** + * 当type为at,时的位置,从1开始 + */ + atInput: number; + /** + * 当type为at,时的方向,true:从右到左,false:从左到右 + */ + atIsRightToleft: boolean; + /** + * 忽略拓展名,true:忽略,false:不忽略 + */ + ignorePostfix: boolean; + /** + 自动识别季号 + */ + autoSeason: boolean; + /** + 后缀过滤是否开启 + */ + endFilter: boolean; + /** + 有效后缀 + */ + validEnd: Array; - constructor(data: any) { - this.insertContent = data.insertContent; - this.type = data.type; - this.atInput = data.atInput; - this.atIsRightToleft = data.atIsRightToleft; - this.ignorePostfix = data.ignorePostfix; - this.autoSeason = data.autoSeason; - this.endFilter = data.endFilter; - this.validEnd = data.validEnd; - } + constructor(data: any) { + this.insertContent = data.insertContent; + this.type = data.type; + this.atInput = data.atInput; + this.atIsRightToleft = data.atIsRightToleft; + this.ignorePostfix = data.ignorePostfix; + this.autoSeason = data.autoSeason; + this.endFilter = data.endFilter; + this.validEnd = data.validEnd; + } - deal(file: FileObj): void { - if (this.endFilter && file.expandName.length > 0 && this.validEnd.indexOf(file.expandName.substring(1)) == -1) { - //拓展名不符,跳过 - return; - } - let str = this.ignorePostfix ? file.realName : file.name; - let season = ''; + deal(file: FileObj): void { + if (this.endFilter && file.expandName.length > 0 && this.validEnd.indexOf(file.expandName.substring(1)) == -1) { + //拓展名不符,跳过 + return; + } + let str = this.ignorePostfix ? file.realName : file.name; + let season = ''; - if (this.autoSeason) { - let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern); - if (patternRes && patternRes[2]) { - season = patternRes[2]; - } - } - switch (this.type) { - case "front": - str = this.insertContent + season + str; - break; - case "backend": - str = str + this.insertContent + season; - break; - case "at": - let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1; - str = str.substring(0, index) + this.insertContent + season + str.substring(index); - break; - case "replace": - str = this.insertContent + season; - break; - } + if (this.autoSeason) { + season = getSeason(path.basename(file.path)); + } + switch (this.type) { + case "front": + str = this.insertContent + season + str; + break; + case "backend": + str = str + this.insertContent + season; + break; + case "at": + let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1; + str = str.substring(0, index) + this.insertContent + season + str.substring(index); + break; + case "replace": + str = this.insertContent + season; + break; + } - if (this.ignorePostfix) { - file.realName = str; - } else { - file.expandName = path.extname(str); - if (file.expandName.length > 0) { - file.realName = str.substring(0, str.lastIndexOf(".")); - } else { - file.realName = str; - } - } + if (this.ignorePostfix) { + file.realName = str; + } else { + file.expandName = path.extname(str); + if (file.expandName.length > 0) { + file.realName = str.substring(0, str.lastIndexOf(".")); + } else { + file.realName = str; + } + } - file.name = file.realName + file.expandName; - } + file.name = file.realName + file.expandName; + } } \ No newline at end of file diff --git "a/openRenamerBackend/sqls/v005_\346\226\260\345\242\236\346\216\250\350\215\220\350\247\204\345\210\231.sql" "b/openRenamerBackend/sqls/v005_\346\226\260\345\242\236\346\216\250\350\215\220\350\247\204\345\210\231.sql" index d740f93..6155813 100644 --- "a/openRenamerBackend/sqls/v005_\346\226\260\345\242\236\346\216\250\350\215\220\350\247\204\345\210\231.sql" +++ "b/openRenamerBackend/sqls/v005_\346\226\260\345\242\236\346\216\250\350\215\220\350\247\204\345\210\231.sql" @@ -1 +1 @@ -INSERT INTO application_rule (createdDate, updatedDate, name, comment, content, defaults) VALUES (1669648328180, 1678279879110, '推荐剧集模板', '此模板为系统创建12121212', '[{"type":"delete","message":"删除:全部删除","data":{"type":"deleteAll","start":{"type":"location","value":"1"},"end":{"type":"location","value":"1"},"ignorePostfix":true},"checked":false},{"type":"auto","message":"自动识别:\"剧名/电影名识别\";","data":{"type":"name","frontAdd":"","endAdd":"","eNumWidth":2},"checked":false},{"type":"auto","message":"自动识别:\"季号识别\";前缀添加:.s","data":{"type":"season","frontAdd":".s","endAdd":"","eNumWidth":2},"checked":false},{"type":"auto","message":"自动识别:\"集数识别\";集数宽度:3;前缀添加:e","data":{"type":"eNum","frontAdd":"e","endAdd":"","eNumWidth":3},"checked":false},{"type":"auto","message":"自动识别:\"分辨率识别\";前缀添加:.","data":{"type":"resolution","frontAdd":".","endAdd":"","eNumWidth":2},"checked":false}]', 0); +INSERT INTO application_rule (createdDate, updatedDate, name, comment, content ) VALUES (1669648328180, 1678279879110, '推荐剧集模板', '此模板为系统创建12121212', '[{"type":"delete","message":"删除:全部删除","data":{"type":"deleteAll","start":{"type":"location","value":"1"},"end":{"type":"location","value":"1"},"ignorePostfix":true},"checked":false},{"type":"auto","message":"自动识别:\"剧名/电影名识别\";","data":{"type":"name","frontAdd":"","endAdd":"","eNumWidth":2},"checked":false},{"type":"auto","message":"自动识别:\"季号识别\";前缀添加:.s","data":{"type":"season","frontAdd":".s","endAdd":"","eNumWidth":2},"checked":false},{"type":"auto","message":"自动识别:\"集数识别\";集数宽度:3;前缀添加:e","data":{"type":"eNum","frontAdd":"e","endAdd":"","eNumWidth":3},"checked":false},{"type":"auto","message":"自动识别:\"分辨率识别\";前缀添加:.","data":{"type":"resolution","frontAdd":".","endAdd":"","eNumWidth":2},"checked":false}]'); diff --git a/openRenamerBackend/start.sh b/openRenamerBackend/start.sh index f47d44f..551806c 100644 --- a/openRenamerBackend/start.sh +++ b/openRenamerBackend/start.sh @@ -1 +1 @@ -npm install -g pnpm typescript --registry https://registry.npmmirror.com && pnpm install --registry https://registry.npmmirror.com && tsc && node dist/index.js +pnpm install --registry https://registry.npmmirror.com && tsc && node dist/index.js diff --git a/openRenamerBackend/util/MediaUtil.ts b/openRenamerBackend/util/MediaUtil.ts index 236d751..addaf96 100644 --- a/openRenamerBackend/util/MediaUtil.ts +++ b/openRenamerBackend/util/MediaUtil.ts @@ -1,3 +1,4 @@ +const path = require("path") const videoSet = new Set(["flv", 'avi', 'wmv', 'dat', 'vob', 'mpg', 'mpeg', 'mp4', '3gp', '3g2', 'mkv', 'rm', 'rmvb', 'mov', 'qt', 'ogg', 'ogv', 'oga', 'mod']); /** @@ -33,4 +34,24 @@ export function isNfo(str: string) { return false; } return "nfo" == str; +} + +let pattern1 = new RegExp(/s(eason)?\.?(\d+)/); +let pattern2 = new RegExp(/(\d+)/); + +/** + * 识别季号 + * @param str + */ +export function getSeason(name: string) { + name = name.replace(/[ ]+/, "").toLocaleLowerCase(); + let patternRes = name.match(pattern1); + if (patternRes && patternRes[2]) { + return patternRes[2]; + } + patternRes = name.match(pattern2); + if (patternRes && patternRes[1]) { + return patternRes[1]; + } + return ""; } \ No newline at end of file diff --git a/openRenamerFront/src/App.vue b/openRenamerFront/src/App.vue index 111aaf4..819a446 100644 --- a/openRenamerFront/src/App.vue +++ b/openRenamerFront/src/App.vue @@ -40,19 +40,19 @@ export default { name: "Home", data() { return { - version: 1.3, + version: 1.4, latestVersion: null, activeIndex: location.pathname, }; }, + async beforeCreate() { + window.token = localStorage.getItem("token"); + window.isWindows = await httpUtil.get("/file/isWindows"); + }, async created() { //获取最新版本 let config = await httpUtil.get("https://s3.fleyx.com/picbed/openRenamer/config.json"); this.latestVersion = config.version; - window.token = localStorage.getItem("token"); - window.isWindows = await httpUtil.get("/file/isWindows"); - console.log(this.$route); - console.log(this.activeIndex); }, async mounted() { console.log(this.$route); diff --git a/openRenamerFront/src/views/home/Home.vue b/openRenamerFront/src/views/home/Home.vue index 79154d6..26e2006 100644 --- a/openRenamerFront/src/views/home/Home.vue +++ b/openRenamerFront/src/views/home/Home.vue @@ -22,7 +22,7 @@
- 反选 + {{ allChecked ? "不选" : "全选" }} 一键选择 @@ -120,7 +120,11 @@ export default { showNameEditDialog: false //显示编辑文件弹窗 }; }, - computed: {}, + computed: { + allChecked() { + return this.fileList.length > 0 && this.fileList.filter(item => item.checked).length === this.fileList.length; + } + }, async created() { this.savePathList = await HttpUtil.get("/file/path"); window.isWindows = await HttpUtil.get("/file/isWindows"); @@ -214,9 +218,9 @@ export default { this.showNameEditDialog = false; await this.showResult(); }, - //反选 selectAllFiles() { - this.fileList.forEach((item) => (item.checked = !item.checked)); + let checked = !this.allChecked; + this.fileList.forEach((item) => (item.checked = checked)); }, //检查规则和文件 checkRuleAndFile() {