-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'dev' (#41) from dev into main
Reviewed-on: https://gitea.fleyx.com/fanxb/open-renamer/pulls/41
- Loading branch information
Showing
9 changed files
with
122 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>; | ||
/** | ||
* 插入内容 | ||
*/ | ||
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<String>; | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}]'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters