diff --git a/index.js b/index.js index 6607b61..baa2de7 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ const crypto = require('crypto'); const cmd = require('shelljs'); +const videoPath = "Z:\\"; +const ignoreName = ["download", "冰海战记 (2019)"]; const cachePath = './cache.json'; const hardTypeSet = new Set(["none", "qsv", "cuda"]); const supportVideoTypeSet = new Set(["mkv", "mp4"]); @@ -21,7 +23,7 @@ function saveFile () { if (fs.existsSync(cachePath)) { cache = JSON.parse(fs.readFileSync(cachePath, 'utf-8')); } - await deal("Z:\\userData\\视频", 3000, true, "cuda"); + await deal(videoPath, 5000, true, "cuda"); if (timer) { clearInterval(timer); } @@ -47,6 +49,9 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType) let fileList = fs.readdirSync(basePath); for (let i in fileList) { let name = fileList[i]; + if (ignoreName.includes(name)) { + continue; + } let filePath = path.join(basePath, name); if (!fs.existsSync(filePath)) { continue; @@ -81,8 +86,8 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType) continue; } let is10Bit = res.streams.filter(item => item.bits_per_raw_sample === '10').length > 0; - let originBitRate = Math.round(parseInt(bitRate) / 1000); - bitRate = originBitRate > maxBitRate ? maxBitRate : originBitRate * 0.7; + let originBitRate = Math.round(parseInt(bitRate) / 1000) * 0.7; + bitRate = originBitRate > maxBitRate ? maxBitRate : originBitRate; let newName = null; replaceTextArr.forEach(item => { @@ -105,7 +110,9 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType) console.log("转换倍率:" + cmdRes.stderr.substring(index - 20)); } if (!fs.existsSync(newFilePath) || fs.statSync(newFilePath).size <= 10000 || cmdRes.stderr.indexOf('Error') > -1) { - throw new Error("未知错误,文件转换失败"); + console.error("未知错误,文件转换失败"); + fs.removeSync(newFilePath); + continue; } if (changeName) { //字幕,nfo文件重命名