60 lines
2 KiB
JavaScript
Executable file
60 lines
2 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
import parseFrames from './src/parseFrames.js'
|
|
import splitSections from './src/splitSections.js'
|
|
import concatenateVideos from './src/concatenateVideos.js'
|
|
import fs from 'fs'
|
|
import readline from 'readline'
|
|
import getArgument from './src/getArgument.js'
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
})
|
|
|
|
global.__dirname = import.meta.url.replace('file://', '').split('/').slice(0, -1).join('/')
|
|
|
|
let filename = getArgument('i')
|
|
if (!filename) {
|
|
console.log('Run `node index.js <file to edit>` to edit a file.')
|
|
console.log('Made by hazysu, inspired by ytp+')
|
|
process.exit()
|
|
}
|
|
try {
|
|
filename = fs.realpathSync(process.cwd()+'/'+filename)
|
|
} catch (error) {
|
|
console.log(`${process.cwd()+'/'+filename} does not exist.`)
|
|
}
|
|
let outFile = getArgument('o')
|
|
if (!outFile) {
|
|
console.log('Please specify the output filename.')
|
|
process.exit()
|
|
}
|
|
outFile = process.cwd()+'/'+outFile
|
|
|
|
global.birdgenAssetPath = __dirname+'/'
|
|
if (fs.existsSync(__dirname+'/profiles')) {
|
|
let profiles = fs.readdirSync(__dirname+'/profiles')
|
|
console.log('Profiles: ', profiles.join(', '))
|
|
rl.question('Which profile would you like to use? ', (profile) => {
|
|
if (!profile||profile=='') throw new Error(`Didn't choose a profile.`)
|
|
if (!profiles.find(e => e===profile)) throw new Error(`${profile} is not an existing profile.`)
|
|
global.birdgenAssetPath = `${__dirname}/profiles/${profile}/`
|
|
start()
|
|
rl.close()
|
|
})
|
|
} else {
|
|
start()
|
|
}
|
|
|
|
async function start() {
|
|
let startTime = Date.now()
|
|
let sectionData = await parseFrames(filename)
|
|
let splitData = await splitSections(sectionData, filename)
|
|
// await fs.promises.writeFile('split.json', JSON.stringify(splitData))
|
|
// let splitData = JSON.parse(await fs.promises.readFile('split.json'))
|
|
// console.log(splitData)
|
|
await concatenateVideos(splitData.filenames, outFile)
|
|
console.log(`Took ${Math.ceil((Date.now()-startTime)/1000)} seconds to complete.`)
|
|
process.exit()
|
|
}
|