From 3415d69cd816e288b175f37965b4549c8dcfe96e Mon Sep 17 00:00:00 2001 From: fanxb Date: Wed, 9 Nov 2022 19:22:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ index.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ceaea36..ddd9bb5 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,5 @@ dist .yarn/install-state.gz .pnp.* + +cache.json \ No newline at end of file diff --git a/index.js b/index.js index 8752804..5ed2d11 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,17 @@ const fs = require('fs-extra'); const path = require('path'); +const crypto = require('crypto'); const cmd = require('child_process'); + +const cachePath = './cache.json'; const hardTypeSet = new Set(["none", "qsv", "cuda"]); const supportVideoTypeSet = new Set(["mkv", "mp4"]); const replaceTextArr = ['h264', 'H264', 'x264', 'X264']; - +let cache = {}; +if (fs.existsSync(cachePath)) { + cache = JSON.parse(fs.readFileSync(cachePath, 'utf-8')); +} /** * * @param {*} basePath 处理路径 @@ -29,10 +35,16 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType) if (!fs.existsSync(filePath)) { continue; } + if (fs.statSync(filePath).isDirectory()) { //如果为文件夹递归处理 await deal(filePath, maxBitRate, changeName, hardType); } + const md5Str = crypto.createHash('md5').update(filePath).digest('hex'); + if (cache[md5Str]) { + continue; + } + cache[md5Str] = true; if (!supportVideoTypeSet.has(name.substring(name.lastIndexOf(".") + 1))) { continue; } @@ -91,6 +103,7 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType) if (!changeName) { fs.moveSync(newFilePath, filePath); } + await fs.writeFile(cachePath, JSON.stringify(cache)); } } (async () => {