// Based on : https://github.com/bjoreman/cuegen // Usage Properties : For mp3Split // https://portableapps.com/apps/music_video/mp3splt-portable const fs = require("fs"); const { isSet } = require("util/types"); const readFile = function (fileName) { return fs.readFileSync(fileName, "utf-8"); }; const makeTwoDigit = function(number) { if (number > 9) { return number; } return `0${ number }`; }; const createTimeCode = function(hhmmss, millis) { let hours = 0; let minutes = 0; let seconds = parseInt(hhmmss.pop(), 10); if (hhmmss.length > 0) { minutes = parseInt(hhmmss.pop(), 10); } if (hhmmss.length > 0) { hours = parseInt(hhmmss.pop(), 10); } const frames = Math.floor(75 * (millis * 0.001)); if(millis){ //console.log(`${ makeTwoDigit((hours * 60) + minutes) }:${ makeTwoDigit(seconds) }:${ makeTwoDigit(frames) }`); return `${ makeTwoDigit((hours * 60) + minutes) }:${ makeTwoDigit(seconds) }:${ makeTwoDigit(frames) }`; }else{ //console.log(`${ makeTwoDigit((hours * 60) + minutes) }:${ makeTwoDigit(seconds) }`); return `${ makeTwoDigit((hours * 60) + minutes) }:${ makeTwoDigit(seconds) }:00`; } }; const createCue = function(input, fileName) { input = input.replace(/\r/g, "\n"); input = input.replace(/\n\n/g, "\n"); const lines = input.split("\n"); const result = []; console.log("Output File : "+fileName); result.push(`FILE "${ fileName }.mp3" MP3`); lines.forEach((line, index) => { if (!line || line.length < 1 || line.indexOf(" ") === -1) { return; } result.push(`\tTRACK ${ makeTwoDigit(index + 1) } AUDIO`); const [time, ...rest] = line.split(" "); const [hhmmss, millis] = time.split("."); const timeParts = hhmmss.split(":"); const title = rest.join(" "); result.push(`\t\tREM NAME "${ title }"`); console.log(hhmmss+"\t"+title); result.push(`\t\tINDEX 01 ${ createTimeCode(timeParts, parseInt(millis, 10)) }`) }); return result.join("\n"); }; const writeCue = function (fileName, output) { fs.writeFileSync(fileName, output); }; const run = function (inFile, outFile) { writeCue(outFile, createCue(readFile(inFile), inFile.split(".")[0])); }; const main = function (args) { console.log("Pastikan filename tanpa tanda \\"); if (args.length < 3) { console.log("Required argument: input file"); console.log("Optional argument: output file") return; } const inputFile = args[2]; const outputFile = args[3] ? args[3] : `${ inputFile.split(".")[0] }.cue`; run(inputFile, outputFile); } main(process.argv);
Mencari Sesuatu ?
Kamis, 21 Juli 2022
JS : CLI tube timestamp file txt to cue
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar