diff --git a/package-lock.json b/package-lock.json index f643573..43abef3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "fluent-ffmpeg": "^2.1.2", "inquirer": "^8.2.6", "jsoning": "^0.13.23", - "mp3-cutter": "^1.0.6", "open": "^8.4.0", "osu-classes": "^3.0.0", "osu-parsers": "^4.1.3", @@ -912,13 +911,6 @@ "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" }, - "node_modules/mp3-cutter": { - "version": "1.0.6", - "license": "MIT", - "bin": { - "mp3-cutter": "bin/mp3-cutter" - } - }, "node_modules/mute-stream": { "version": "0.0.8", "license": "ISC" diff --git a/package.json b/package.json index a9406bc..7bd26c3 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "fluent-ffmpeg": "^2.1.2", "inquirer": "^8.2.6", "jsoning": "^0.13.23", - "mp3-cutter": "^1.0.6", "open": "^8.4.0", "osu-classes": "^3.0.0", "osu-parsers": "^4.1.3", diff --git a/src/merge/audio.ts b/src/merge/audio.ts index bf7d1bf..d7c9227 100644 --- a/src/merge/audio.ts +++ b/src/merge/audio.ts @@ -2,7 +2,6 @@ import ffmpeg from "fluent-ffmpeg"; import ffmpegInstaller from "@ffmpeg-installer/ffmpeg"; import ffprobe from "@ffprobe-installer/ffprobe"; import { Difficulty } from "../locally/types"; -const MP3Cutter = require("mp3-cutter"); export async function MergeAudioAndExport( firstSong: Difficulty, @@ -10,16 +9,21 @@ export async function MergeAudioAndExport( timecodes: { endOfFirstHalf: number; startOfSecondHalf: number }, pathToExport: string ) { - await MP3Cutter.cut({ - src: `${firstSong.path}/${firstSong.difficulty.general.audioFilename}`, - target: "Temp/FirstPart.mp3", - end: timecodes.endOfFirstHalf / 1000 + 1, // +1s to avoid unsync audio after fading - }); - await MP3Cutter.cut({ - src: `${secondSong.path}/${secondSong.difficulty.general.audioFilename}`, - target: "Temp/SecondPart.mp3", - start: timecodes.startOfSecondHalf / 1000, - }); + await cutMP3Audio( + `${firstSong.path}/${firstSong.difficulty.general.audioFilename}`, + "Temp/FirstPart.mp3", + { + end: timecodes.endOfFirstHalf / 1000 + 1, // +1s to avoid unsync audio after fading + } + ); + + await cutMP3Audio( + `${secondSong.path}/${secondSong.difficulty.general.audioFilename}`, + "Temp/SecondPart.mp3", + { + start: timecodes.startOfSecondHalf / 1000, // +1s to avoid unsync audio after fading + } + ); ffmpeg.setFfmpegPath(ffmpegInstaller.path); ffmpeg.setFfprobePath(ffprobe.path); @@ -47,3 +51,32 @@ export async function MergeAudioAndExport( .run(); }); } + +function cutMP3Audio( + path: string, + output: string, + time: { + start?: number; + end?: number; + } +) { + return new Promise((resolve, reject) => { + ffmpeg() + .input(path) + .outputOptions( + time.start !== undefined + ? `-ss ${time.start || 0}` + : `-t ${time.end || 0}` + ) + .output(output) + .on("error", function (err) { + console.log("An error occurred during cutting: " + err.message); + reject(err); + }) + .on("end", function () { + resolve(undefined); + }) + + .run(); + }); +} diff --git a/src/merge/propmpts.ts b/src/merge/propmpts.ts index ed31d8c..0e6d515 100644 --- a/src/merge/propmpts.ts +++ b/src/merge/propmpts.ts @@ -2,6 +2,7 @@ import Jsoning from "jsoning"; import getLocalizationJson from "../lib/localization/main"; import inquirer from "inquirer"; import open from "open"; +import fs from "fs"; export async function openOsz(config: Jsoning, oszPath: string) { const localization = await getLocalizationJson(config); @@ -17,7 +18,8 @@ export async function openOsz(config: Jsoning, oszPath: string) { ]) .then((options) => { if (options.backToMenu) { - open(oszPath); + fs.copyFileSync(oszPath, `${oszPath}-exp.osz`); + open(`${oszPath}-exp.osz`); } }); }