feat:增加缓存
This commit is contained in:
parent
7ed9d0b4a3
commit
3415d69cd8
2
.gitignore
vendored
2
.gitignore
vendored
@ -130,3 +130,5 @@ dist
|
|||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
|
||||||
|
cache.json
|
15
index.js
15
index.js
@ -1,11 +1,17 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const cmd = require('child_process');
|
const cmd = require('child_process');
|
||||||
|
|
||||||
|
const cachePath = './cache.json';
|
||||||
const hardTypeSet = new Set(["none", "qsv", "cuda"]);
|
const hardTypeSet = new Set(["none", "qsv", "cuda"]);
|
||||||
const supportVideoTypeSet = new Set(["mkv", "mp4"]);
|
const supportVideoTypeSet = new Set(["mkv", "mp4"]);
|
||||||
const replaceTextArr = ['h264', 'H264', 'x264', 'X264'];
|
const replaceTextArr = ['h264', 'H264', 'x264', 'X264'];
|
||||||
|
let cache = {};
|
||||||
|
if (fs.existsSync(cachePath)) {
|
||||||
|
cache = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {*} basePath 处理路径
|
* @param {*} basePath 处理路径
|
||||||
@ -29,10 +35,16 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType)
|
|||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.statSync(filePath).isDirectory()) {
|
if (fs.statSync(filePath).isDirectory()) {
|
||||||
//如果为文件夹递归处理
|
//如果为文件夹递归处理
|
||||||
await deal(filePath, maxBitRate, changeName, hardType);
|
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))) {
|
if (!supportVideoTypeSet.has(name.substring(name.lastIndexOf(".") + 1))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -91,6 +103,7 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType)
|
|||||||
if (!changeName) {
|
if (!changeName) {
|
||||||
fs.moveSync(newFilePath, filePath);
|
fs.moveSync(newFilePath, filePath);
|
||||||
}
|
}
|
||||||
|
await fs.writeFile(cachePath, JSON.stringify(cache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(async () => {
|
(async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user