feat:增加缓存

This commit is contained in:
fanxb 2022-11-09 19:22:42 +08:00
parent 7ed9d0b4a3
commit 3415d69cd8
2 changed files with 16 additions and 1 deletions

2
.gitignore vendored
View File

@ -130,3 +130,5 @@ dist
.yarn/install-state.gz
.pnp.*
cache.json

View File

@ -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 () => {