Settings update
This commit is contained in:
parent
b20bd0087c
commit
ca2700a20a
1 changed files with 34 additions and 29 deletions
43
lib/ui.js
43
lib/ui.js
|
@ -20,14 +20,12 @@ class UI {
|
|||
}, cliProgress.Presets.shades_grey)
|
||||
|
||||
this.settings = settings
|
||||
this.currentSetting = currentSetting
|
||||
this.settingsFile = settingsFile
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {Number} duration Duration of the encoded media
|
||||
* @param {String} filename name of the encoding file
|
||||
* @param {Boolean} isTwoPass is the encoded media two pass
|
||||
* @returns
|
||||
*/
|
||||
async newBar(encoderOutput) {
|
||||
|
@ -36,7 +34,6 @@ class UI {
|
|||
let isTwoPass = encoderOutput[2]
|
||||
this.bars.push({
|
||||
"bar": this.multibar.create(duration, 0, { speed: "N/A" }),
|
||||
"isTwoPass": isTwoPass,
|
||||
"isPastHalf": false,
|
||||
"filename": filename,
|
||||
"duration": duration,
|
||||
|
@ -61,16 +58,11 @@ class UI {
|
|||
const arr = currentTime.split(":")
|
||||
let seconds = Number.parseFloat(arr[0] * 3600 + arr[1] * 60 + (+arr[2])) // converting to s
|
||||
|
||||
//If 2 pass divide bar into two parts to show both in progress in one progress
|
||||
if (this.bars[barIndex].isTwoPass) {
|
||||
if (seconds / 2 >= (this.bars[barIndex].duration - 0.2) / 2) this.bars[barIndex].isPastHalf = true
|
||||
|
||||
if (this.bars[barIndex].isPastHalf) this.bars[barIndex].bar.update(Math.round(seconds * 50) / 100 + (this.bars[barIndex].duration / 2), { filename: `${this.bars[barIndex].filename}.webm` })
|
||||
else this.bars[barIndex].bar.update(Math.round(seconds * 50) / 100, { filename: `${this.bars[barIndex].filename}.webm` })
|
||||
}
|
||||
else {
|
||||
this.bars[barIndex].bar.update(Math.round(seconds * 100) / 100, { filename: `${this.bars[barIndex].filename}.webm` })
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
const currentTime = chunk.split("time=")[1]?.split(" ")[0]
|
||||
|
@ -100,23 +92,36 @@ class UI {
|
|||
async startMenu() {
|
||||
await this.#menu()
|
||||
}
|
||||
async #menu() {
|
||||
let menu = []
|
||||
for (let i = 0; i < this.settings.presets.length; i++) {
|
||||
menu.push(`${i}. ${this.settings.presets[i].name}`)
|
||||
}
|
||||
this.term.grey("How to convert: 8mb [optional: -preset {Index}] [filename.extension(s)]\n")
|
||||
#menu() {
|
||||
return new Promise(resolve => {
|
||||
const menu = ["8 Megabytes", "50 Megabytes (Nitro Classic)", "100 Megabytes (Nitro)"]
|
||||
this.term.grey("How to convert: 8mb [filename.extension(s)]\n")
|
||||
this.term.grey("examples: \n")
|
||||
this.term.italic.grey(" 8mb -preset 0 file.mp3 file4.mov img.jpg\n")
|
||||
this.term.italic.grey(" 8mb file34.wav file2.mp3\n\n")
|
||||
this.term.yellow("Hello! This menu is for selecting performance/speed preset.\n")
|
||||
this.term.yellow("Currently using ").bgMagenta(`"${this.settings.presets[this.settings.currentSetting].name}"`).yellow(" preset\n")
|
||||
this.term.yellow("Hello! This menu is for selecting filesize limit (if using discord nitro)\n")
|
||||
this.term.yellow("Currently using ").bgMagenta(`${this.settings.size_limit / 8000} Mb`).yellow(" filesize limit\n")
|
||||
this.term.singleColumnMenu(menu, (error, response) => {
|
||||
this.settings.currentSetting = response.selectedIndex
|
||||
this.term.green("\n Using").green.bold(` ${this.settings.presets[this.settings.currentSetting].name} `).green("setting\n")
|
||||
switch (response.selectedIndex) {
|
||||
case 0:
|
||||
this.settings.size_limit = 64000
|
||||
break
|
||||
case 1:
|
||||
this.settings.size_limit = 400000
|
||||
break
|
||||
case 2:
|
||||
this.settings.size_limit = 800000
|
||||
break
|
||||
default:
|
||||
this.settings.size_limit = 64000
|
||||
break
|
||||
}
|
||||
this.term.green("\n Using").green.bold(` ${this.settings.size_limit / 8000} Mb `).green("setting\n")
|
||||
fs.writeFileSync(path.resolve(this.settingsFile, "settings.json"), JSON.stringify(this.settings))
|
||||
this.term.grey("Press enter to exit...")
|
||||
this.term.inputField(() => { process.exit() })
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue