Last active
April 17, 2019 16:33
-
-
Save asins/c2a54246ced68c0d24b021c09188a362 to your computer and use it in GitHub Desktop.
Revisions
-
asins revised this gist
Apr 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ function setVideoTags(filePath, cb) { '-codec', 'copy', '-metadata', `title=${pathParse.name}`, '-metadata', `album=${ALBUM}`, '-metadata', `author=${AUTHOR}`, path.resolve(distPath, pathParse.base) ]); -
asins created this gist
Apr 17, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ const fs = require('fs'); const path = require('path'); const { spawn } = require( 'child_process' ); const sourcePath = path.resolve('./video/'); const distPath = path.resolve('./new/'); const ALBUM = '我修的可能是假仙'; const AUTHOR = '牛大宝'; let videoFileList; function setVideoTags(filePath, cb) { const pathParse = path.parse(filePath); const ls = spawn( 'ffmpeg', [ '-i', filePath, '-b:a', '65k', '-codec', 'copy', '-metadata', `title=${pathParse.name}`, '-metadata', `album=${ALBUM}`, '-metadata', `composer=${AUTHOR}`, path.resolve(distPath, pathParse.base) ]); // ls.stdout.on( 'data', data => { // console.log( `stdout: ${data}` ); // }); // // ls.stderr.on( 'data', data => { // console.log( `stderr: ${data}` ); // }); ls.on( 'close', code => { console.log( `${filePath}, Code: ${code}` ); cb && cb(); }); } function clearDistDir(directory) { fs.readdir(directory, (err, files) => { if (err) throw err; for (const file of files) { fs.unlink(path.join(directory, file), err => { if (err) throw err; }); } }); } function handleVideo(index) { const videoPath = videoFileList[index]; if(!videoPath) return; // if(index > 2) return; setVideoTags(path.resolve(sourcePath, videoPath), function() { handleVideo(++index); }); } // 遍历文件夹 fs.readdir(sourcePath, function(err, items) { videoFileList = items; clearDistDir(distPath); handleVideo(0); });