From 1f511dddfce2578104e6d25a16b18ffd6dfca741 Mon Sep 17 00:00:00 2001 From: Starbuck Date: Sat, 14 Mar 2020 17:20:50 +0200 Subject: [PATCH 1/3] First commit that adds all the code --- .atom-build.yml | 1 + main.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 12 +++++++++ 3 files changed, 82 insertions(+) create mode 100644 .atom-build.yml create mode 100644 main.js create mode 100644 package.json diff --git a/.atom-build.yml b/.atom-build.yml new file mode 100644 index 0000000..465dbd7 --- /dev/null +++ b/.atom-build.yml @@ -0,0 +1 @@ +cmd: node main.js --dir ""D:\New Folder"" diff --git a/main.js b/main.js new file mode 100644 index 0000000..ea18a71 --- /dev/null +++ b/main.js @@ -0,0 +1,69 @@ +const yargs = require('yargs'); +const exec = require('child_process').execSync; +let directory = "" +const argv = yargs.argv; +if (argv.dir) { + directory = argv.dir +} else { + console.error("Error: No directory specified"); + process.exit(1) +} + + + +// List all files in a directory in Node.js recursively in a synchronous fashion +var walkSync = function(dir, filelist, dirlist) { + var path = path || require('path'); + var fs = fs || require('fs'), + files = fs.readdirSync(dir); + var dirlist = dirlist || []; + filelist = filelist || []; + files.forEach(function(file) { + if (fs.statSync(path.join(dir, file)).isDirectory()) { + dirlist.push(path.join(dir, file)); + let temp = walkSync(path.join(dir, file), filelist, dirlist) + filelist = temp[0]; + dirlist = temp[1]; + + } else { + filelist.push(path.join(dir, file)); + } + }); + return [filelist, dirlist]; +}; + + +let walk = walkSync(directory); +let filesUnfiltered = walk[0]; +let folders = walk[1] +let files = []; +var commands = []; +let otherFiles = []; +files = filesUnfiltered.filter(word => word.slice(-5) == ".flac" || word.slice(-4) == ".wav"); +otherFiles = filesUnfiltered.filter(word => word.slice(-5) != ".flac" && word.slice(-4) != ".wav"); + +for (let j = 0; j < folders.length; j++) { + let folder = folders[j].slice(0, directory.length) + " AAC" + folders[j].slice(directory.length); + exec("if not exist \"" + folder + "\" mkdir \"" + folder + "\""); +} +for (let i = 0; i < files.length; i++) { + let input = "\"" + files[i] + "\""; + let output = "\"" + files[i].slice(0, directory.length) + " AAC" + files[i].slice(directory.length, -4) + "m4a" + "\""; + exec("ffmpeg -i " + input + " -map 0:0 -c:a aac -b:a 285k " + output); + console.log("FFM-Pegging file " + (i + 1) + " out of " + files.length); + console.log(((i / files.length) * 100) + "% complete."); + +} + + + +for (let k = 0; k < otherFiles.length; k++) { + let input = "\"" + otherFiles[k] + "\""; + let output = "\"" + otherFiles[k].slice(0, directory.length) + " AAC" + otherFiles[k].slice(directory.length) + "\""; + exec("ECHO F|xcopy " + input + " " + output + " /H"); + +} + +console.log("Job done sucessfully!"); + +// ffmpeg -i input -c:a aac -b:a 256k output \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..bc18d05 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "library-converter", + "version": "1.0.0", + "description": "Converts music libraries to AAC", + "main": "main.js", + "bin": "main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Shraga The Mighty Sky Worm", + "license": "MIT" +} From ae43228f98884282983aed45b5c50f6352510b19 Mon Sep 17 00:00:00 2001 From: Starbuck Date: Sat, 14 Mar 2020 17:22:41 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 49551cb..88d6901 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # library-converter Converts music libraries to MP4 + +Just run with library-converter.exe --dir "C:\your\music\library" +it will create "C:\your\music\library AAC" and put everything there. none of your actual library is touched. +only converts flac and wav files. From 49581d68df3440aed7cba6ef41ed0c7d72aff6af Mon Sep 17 00:00:00 2001 From: Starbuck Date: Sat, 14 Mar 2020 17:30:18 +0200 Subject: [PATCH 3/3] updated readme again --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 88d6901..f84a7a0 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,5 @@ Converts music libraries to MP4 Just run with library-converter.exe --dir "C:\your\music\library" it will create "C:\your\music\library AAC" and put everything there. none of your actual library is touched. only converts flac and wav files. + +requires ffmpeg. tested with git-2019-12-07-70e292b.