feat:优化季识别
This commit is contained in:
parent
11f28f12fa
commit
9a55460f11
@ -1,6 +1,7 @@
|
|||||||
import RuleInterface from "./RuleInterface";
|
import RuleInterface from "./RuleInterface";
|
||||||
import FileObj from "../../vo/FileObj";
|
import FileObj from "../../vo/FileObj";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {getSeason} from "../../../util/MediaUtil";
|
||||||
|
|
||||||
|
|
||||||
let pattern = new RegExp(/s(eason)?(\d+)/);
|
let pattern = new RegExp(/s(eason)?(\d+)/);
|
||||||
@ -35,14 +36,12 @@ export default class InsertRule implements RuleInterface {
|
|||||||
deal(file: FileObj): void {
|
deal(file: FileObj): void {
|
||||||
//识别到的内容
|
//识别到的内容
|
||||||
let getStr = null;
|
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 (this.type === 'season') {
|
||||||
if (patternRes && patternRes[2]) {
|
getStr = season;
|
||||||
getStr = patternRes[2];
|
|
||||||
}
|
|
||||||
} else if (this.type === 'name') {
|
} else if (this.type === 'name') {
|
||||||
let originName = null;
|
let originName = null;
|
||||||
if (patternRes && patternRes[2]) {
|
if (season && season.length > 0) {
|
||||||
//说明是剧集,取父文件夹的父文件夹名称
|
//说明是剧集,取父文件夹的父文件夹名称
|
||||||
originName = path.basename(path.resolve(file.path, '..'));
|
originName = path.basename(path.resolve(file.path, '..'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,98 +1,95 @@
|
|||||||
import RuleInterface from "./RuleInterface";
|
import RuleInterface from "./RuleInterface";
|
||||||
import FileObj from "../../vo/FileObj";
|
import FileObj from "../../vo/FileObj";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {getSeason} from "../../../util/MediaUtil";
|
||||||
|
|
||||||
|
|
||||||
let pattern = new RegExp(/s(eason)?(\d+)/);
|
|
||||||
export default class InsertRule implements RuleInterface {
|
export default class InsertRule implements RuleInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入内容
|
* 插入内容
|
||||||
*/
|
*/
|
||||||
insertContent: string;
|
insertContent: string;
|
||||||
/**
|
/**
|
||||||
* 操作类别,front:前缀,backend:后缀,at:位置,replace:替换当前文件名
|
* 操作类别,front:前缀,backend:后缀,at:位置,replace:替换当前文件名
|
||||||
*/
|
*/
|
||||||
type: string;
|
type: string;
|
||||||
/**
|
/**
|
||||||
* 当type为at,时的位置,从1开始
|
* 当type为at,时的位置,从1开始
|
||||||
*/
|
*/
|
||||||
atInput: number;
|
atInput: number;
|
||||||
/**
|
/**
|
||||||
* 当type为at,时的方向,true:从右到左,false:从左到右
|
* 当type为at,时的方向,true:从右到左,false:从左到右
|
||||||
*/
|
*/
|
||||||
atIsRightToleft: boolean;
|
atIsRightToleft: boolean;
|
||||||
/**
|
/**
|
||||||
* 忽略拓展名,true:忽略,false:不忽略
|
* 忽略拓展名,true:忽略,false:不忽略
|
||||||
*/
|
*/
|
||||||
ignorePostfix: boolean;
|
ignorePostfix: boolean;
|
||||||
/**
|
/**
|
||||||
自动识别季号
|
自动识别季号
|
||||||
*/
|
*/
|
||||||
autoSeason: boolean;
|
autoSeason: boolean;
|
||||||
/**
|
/**
|
||||||
后缀过滤是否开启
|
后缀过滤是否开启
|
||||||
*/
|
*/
|
||||||
endFilter: boolean;
|
endFilter: boolean;
|
||||||
/**
|
/**
|
||||||
有效后缀
|
有效后缀
|
||||||
*/
|
*/
|
||||||
validEnd: Array<String>;
|
validEnd: Array<String>;
|
||||||
|
|
||||||
constructor(data: any) {
|
constructor(data: any) {
|
||||||
this.insertContent = data.insertContent;
|
this.insertContent = data.insertContent;
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
this.atInput = data.atInput;
|
this.atInput = data.atInput;
|
||||||
this.atIsRightToleft = data.atIsRightToleft;
|
this.atIsRightToleft = data.atIsRightToleft;
|
||||||
this.ignorePostfix = data.ignorePostfix;
|
this.ignorePostfix = data.ignorePostfix;
|
||||||
this.autoSeason = data.autoSeason;
|
this.autoSeason = data.autoSeason;
|
||||||
this.endFilter = data.endFilter;
|
this.endFilter = data.endFilter;
|
||||||
this.validEnd = data.validEnd;
|
this.validEnd = data.validEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
deal(file: FileObj): void {
|
deal(file: FileObj): void {
|
||||||
if (this.endFilter && file.expandName.length > 0 && this.validEnd.indexOf(file.expandName.substring(1)) == -1) {
|
if (this.endFilter && file.expandName.length > 0 && this.validEnd.indexOf(file.expandName.substring(1)) == -1) {
|
||||||
//拓展名不符,跳过
|
//拓展名不符,跳过
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let str = this.ignorePostfix ? file.realName : file.name;
|
let str = this.ignorePostfix ? file.realName : file.name;
|
||||||
let season = '';
|
let season = '';
|
||||||
|
|
||||||
if (this.autoSeason) {
|
if (this.autoSeason) {
|
||||||
let patternRes = path.basename(file.path).replace(/[ ]+/, "").toLocaleLowerCase().match(pattern);
|
season = getSeason(path.basename(file.path));
|
||||||
if (patternRes && patternRes[2]) {
|
}
|
||||||
season = patternRes[2];
|
switch (this.type) {
|
||||||
}
|
case "front":
|
||||||
}
|
str = this.insertContent + season + str;
|
||||||
switch (this.type) {
|
break;
|
||||||
case "front":
|
case "backend":
|
||||||
str = this.insertContent + season + str;
|
str = str + this.insertContent + season;
|
||||||
break;
|
break;
|
||||||
case "backend":
|
case "at":
|
||||||
str = str + this.insertContent + season;
|
let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1;
|
||||||
break;
|
str = str.substring(0, index) + this.insertContent + season + str.substring(index);
|
||||||
case "at":
|
break;
|
||||||
let index = this.atIsRightToleft ? str.length - this.atInput + 1 : this.atInput - 1;
|
case "replace":
|
||||||
str = str.substring(0, index) + this.insertContent + season + str.substring(index);
|
str = this.insertContent + season;
|
||||||
break;
|
break;
|
||||||
case "replace":
|
}
|
||||||
str = this.insertContent + season;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this.ignorePostfix) {
|
if (this.ignorePostfix) {
|
||||||
file.realName = str;
|
file.realName = str;
|
||||||
} else {
|
} else {
|
||||||
file.expandName = path.extname(str);
|
file.expandName = path.extname(str);
|
||||||
if (file.expandName.length > 0) {
|
if (file.expandName.length > 0) {
|
||||||
file.realName = str.substring(0, str.lastIndexOf("."));
|
file.realName = str.substring(0, str.lastIndexOf("."));
|
||||||
} else {
|
} else {
|
||||||
file.realName = str;
|
file.realName = str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file.name = file.realName + file.expandName;
|
file.name = file.realName + file.expandName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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']);
|
const videoSet = new Set(["flv", 'avi', 'wmv', 'dat', 'vob', 'mpg', 'mpeg', 'mp4', '3gp', '3g2', 'mkv', 'rm', 'rmvb', 'mov', 'qt', 'ogg', 'ogv', 'oga', 'mod']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,3 +35,23 @@ export function isNfo(str: string) {
|
|||||||
}
|
}
|
||||||
return "nfo" == str;
|
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 "";
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user