diff --git a/openRenamerBackend/entity/vo/FileObj.ts b/openRenamerBackend/entity/vo/FileObj.ts index 4246849..473cb2f 100644 --- a/openRenamerBackend/entity/vo/FileObj.ts +++ b/openRenamerBackend/entity/vo/FileObj.ts @@ -1,55 +1,71 @@ import * as pathUtil from "path"; +import {isVideo, isSub, isNfo} from "../../util/MediaUtil" + export default class FileObj { - /** - * 文件名 - */ - name: string; - /** - 原始名字 - */ - originName: string; - /** - * 拓展名 - */ - expandName: string; - /** - * 去掉拓展名后的名字 - */ - realName: string; - /** - * 所属路径 - */ - path: string; - /** - * 是否文件夹 - */ - isFolder: boolean; - /** - * 重命名错误原因 - */ - errorMessage: string; - /** - * 创建时间ms - */ - createdTime: number; - /** - * 更新时间ms - */ - updatedTime: number; + /** + * 文件名 + */ + name: string; + /** + 原始名字 + */ + originName: string; + /** + * 拓展名 + */ + expandName: string; + /** + * 去掉拓展名后的名字 + */ + realName: string; + /** + * 所属路径 + */ + path: string; + /** + * 是否文件夹 + */ + isFolder: boolean; + /** + * 文件大小 + */ + size: number; + /** + * 重命名错误原因 + */ + errorMessage: string; + /** + * 创建时间ms + */ + createdTime: number; + /** + * 更新时间ms + */ + updatedTime: number; + /** + * 是否广告文件 + */ + isAdFile: boolean; - constructor(name: string, path, isFolder, createdTime, updatedTime) { - this.name = name; - this.originName = name; - this.expandName = pathUtil.extname(name); - if (this.expandName.length > 0) { - this.realName = name.substring(0, name.lastIndexOf(".")); - } else { - this.realName = name; - } - this.path = path; - this.isFolder = isFolder; - this.createdTime = createdTime; - this.updatedTime = updatedTime; - } + constructor(name: string, path, isFolder, size: number, createdTime, updatedTime) { + this.name = name; + this.originName = name; + this.expandName = pathUtil.extname(name); + if (this.expandName.length > 0) { + this.realName = name.substring(0, name.lastIndexOf(".")); + let end = this.expandName.toLowerCase().replace(".", ""); + if (isVideo(end)) { + this.isAdFile = size < 5 * 1024 * 1024; + } else this.isAdFile = !(isSub(end) || isNfo(end)); + } else { + this.realName = name; + } + this.path = path; + this.isFolder = isFolder; + this.size = size; + this.createdTime = createdTime; + this.updatedTime = updatedTime; + + } } \ No newline at end of file diff --git a/openRenamerBackend/service/FileService.ts b/openRenamerBackend/service/FileService.ts index fde1eb3..9467a05 100644 --- a/openRenamerBackend/service/FileService.ts +++ b/openRenamerBackend/service/FileService.ts @@ -42,12 +42,12 @@ class FileService { if (fileList[index].startsWith('.')) { if (showHidden) { (stat.isDirectory() ? folderList : files).push( - new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.birthtime.getTime(), stat.mtime.getTime()), + new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.size, stat.birthtime.getTime(), stat.mtime.getTime()), ); } } else { (stat.isDirectory() ? folderList : files).push( - new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.birthtime.getTime(), stat.mtime.getTime()), + new FileObj(fileList[index], pathStr, stat.isDirectory(), stat.size, stat.birthtime.getTime(), stat.mtime.getTime()), ); } } catch (e) { @@ -82,7 +82,7 @@ class FileService { let filePath = path.join(file.path, file.name); let temp = (await fs.readdir(filePath)).map(item => { let stat = fs.statSync(path.join(filePath, item)); - return new FileObj(item, filePath, stat.isDirectory(), stat.birthtime.getTime(), stat.mtime.getTime()); + return new FileObj(item, filePath, stat.isDirectory(), stat.size, stat.birthtime.getTime(), stat.mtime.getTime()); }); await FileService.readDirRecursion(res, temp, depth + 1); } diff --git a/openRenamerBackend/util/MediaUtil.ts b/openRenamerBackend/util/MediaUtil.ts index 4303aca..236d751 100644 --- a/openRenamerBackend/util/MediaUtil.ts +++ b/openRenamerBackend/util/MediaUtil.ts @@ -1,23 +1,36 @@ const videoSet = new Set(["flv", 'avi', 'wmv', 'dat', 'vob', 'mpg', 'mpeg', 'mp4', '3gp', '3g2', 'mkv', 'rm', 'rmvb', 'mov', 'qt', 'ogg', 'ogv', 'oga', 'mod']); + /** * 判断文件后缀是否为视频类型 * @param str 文件后缀 */ export function isVideo(str: string) { - if (!str) { - return false; - } - return videoSet.has(str.toLowerCase()); + if (!str) { + return false; + } + return videoSet.has(str.toLowerCase()); } const subSet = new Set(['sub', 'sst', 'son', 'srt', 'ssa', 'ass', 'smi', 'psb', 'pjs', 'stl', 'tts', 'vsf', 'zeg']); + /** * 判断文件是否为字幕文件 * @param str 文件后缀 */ export function isSub(str: string) { - if (!str) { - return false; - } - return subSet.has(str.toLowerCase()); + if (!str) { + return false; + } + return subSet.has(str.toLowerCase()); +} + +/** + * 判断文件是否为字幕文件 + * @param str 文件后缀 + */ +export function isNfo(str: string) { + if (!str) { + return false; + } + return "nfo" == str; } \ No newline at end of file diff --git a/openRenamerFront/src/views/home/Home.vue b/openRenamerFront/src/views/home/Home.vue index dfe8ad0..79154d6 100644 --- a/openRenamerFront/src/views/home/Home.vue +++ b/openRenamerFront/src/views/home/Home.vue @@ -24,7 +24,7 @@