Cleanup
This commit is contained in:
parent
6943753fd6
commit
b20bd0087c
1 changed files with 31 additions and 46 deletions
45
bin/index.js
45
bin/index.js
|
@ -22,11 +22,8 @@ if (!inputList[0]) {
|
|||
//Parse file inputs (n Drag n drop or arguments)
|
||||
let filePaths = [], fileNames = [], fileTypes = []
|
||||
let presetIndexArg = undefined
|
||||
//if preset argument go through list from 2 and add argument
|
||||
if (inputList[0] == "-preset") {
|
||||
presetIndexArg = inputList[1]
|
||||
|
||||
for (let i = 2; i < inputList.length; i++) {
|
||||
for (let i = 0; i < inputList.length; i++) {
|
||||
let file
|
||||
file = path.resolve(inputList[i])
|
||||
|
||||
|
@ -38,41 +35,32 @@ if (inputList[0] == "-preset") {
|
|||
|
||||
fileTypes.push(file[file.length - 1])
|
||||
fileNames.push(file[0])
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < inputList.length; i++) {
|
||||
let file
|
||||
file = path.resolve(inputList[i])
|
||||
|
||||
filePaths.push(file)
|
||||
|
||||
file = file.split("\\")
|
||||
file = file[file.length - 1]
|
||||
file = file.split(".")
|
||||
|
||||
fileTypes.push(file[file.length - 1])
|
||||
fileNames.push(file[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main()
|
||||
|
||||
async function main(menu = false) {
|
||||
//check if ffmpeg and ffprobe exist
|
||||
//get settings
|
||||
let settings = new SettingsManager()
|
||||
await settings.start(__dirname)
|
||||
await checkFF()
|
||||
//check if ffmpeg and ffprobe exist
|
||||
try {
|
||||
const check = await checkFF()
|
||||
} catch (reject) {
|
||||
process.exit()
|
||||
}
|
||||
const ui = new UI(settings.settings, settings.currentSetting, settings.settingsFile, filePaths?.length)
|
||||
|
||||
//file checks
|
||||
let isListEncodable = true
|
||||
|
||||
if (menu) { savesettings = await ui.startMenu(); isListEncodable = false }
|
||||
if (menu) {
|
||||
isListEncodable = false
|
||||
savesettings = await ui.startMenu()
|
||||
}
|
||||
|
||||
//check if all files exist
|
||||
if (isListEncodable) {
|
||||
for (let i = 0; i < filePaths.length; i++) {
|
||||
if (!fs.existsSync(filePaths[i])) {
|
||||
term.italic(`${filePaths[i]}`).bold.red(" <- Path or File doesn't exist\n")
|
||||
|
@ -81,7 +69,7 @@ async function main(menu = false) {
|
|||
term.inputField(function () { process.exit() })
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//check if all files are valid formats
|
||||
if (isListEncodable) {
|
||||
for (let i = 0; i < filePaths.length; i++) {
|
||||
|
@ -97,15 +85,14 @@ async function main(menu = false) {
|
|||
term.inputField(function () { process.exit() })
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//start encoding all
|
||||
if (isListEncodable) {
|
||||
let encoder = []
|
||||
console.log(`Encoding with "${settings.currentSetting.name}" preset...`)
|
||||
console.log(`Encoding to ${settings.settings.size_limit / 8000} Mb...`)
|
||||
for (let i = 0; i < filePaths.length; i++) {
|
||||
const fileType = fileTypes[i].toLowerCase()
|
||||
encoder.push(new Encoder(settings.settings, settings.currentSetting, presetIndexArg))
|
||||
encoder.push(new Encoder(settings.settings))
|
||||
|
||||
if (fileType == "jpg" || fileType == "png" || fileType == "webp") {
|
||||
ui.newBar(await encoder[i].encodePicture(filePaths[i], fileNames[i]))
|
||||
|
@ -139,7 +126,6 @@ async function checkFF() {
|
|||
term.blue.underline("https://ffmpeg.org/download.html\n")
|
||||
term.grey("press enter to exit...")
|
||||
term.inputField(function () {
|
||||
process.exit()
|
||||
reject()
|
||||
})
|
||||
}
|
||||
|
@ -154,7 +140,6 @@ async function checkFF() {
|
|||
term.blue.underline("https://ffmpeg.org/download.html\n")
|
||||
term.grey("press enter to exit...\n")
|
||||
term.inputField(function () {
|
||||
process.exit()
|
||||
reject()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue