loukai-app 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +558 -0
- package/bin/loukai.js +32 -0
- package/package.json +243 -0
- package/src/main/appState.js +250 -0
- package/src/main/audioEngine.js +478 -0
- package/src/main/creator/conversionService.js +503 -0
- package/src/main/creator/downloadManager.js +1128 -0
- package/src/main/creator/ffmpegService.js +487 -0
- package/src/main/creator/installLogger.js +51 -0
- package/src/main/creator/keyDetection.js +212 -0
- package/src/main/creator/llmService.js +370 -0
- package/src/main/creator/lrclibService.js +340 -0
- package/src/main/creator/python/crepe_runner.py +189 -0
- package/src/main/creator/python/demucs_runner.py +158 -0
- package/src/main/creator/python/whisper_runner.py +172 -0
- package/src/main/creator/pythonRunner.js +268 -0
- package/src/main/creator/stemBuilder.js +491 -0
- package/src/main/creator/systemChecker.js +474 -0
- package/src/main/handlers/appHandlers.js +45 -0
- package/src/main/handlers/audioHandlers.js +33 -0
- package/src/main/handlers/autotuneHandlers.js +28 -0
- package/src/main/handlers/canvasHandlers.js +84 -0
- package/src/main/handlers/creatorHandlers.js +159 -0
- package/src/main/handlers/editorHandlers.js +98 -0
- package/src/main/handlers/effectsHandlers.js +100 -0
- package/src/main/handlers/fileHandlers.js +45 -0
- package/src/main/handlers/index.js +78 -0
- package/src/main/handlers/libraryHandlers.js +96 -0
- package/src/main/handlers/mixerHandlers.js +64 -0
- package/src/main/handlers/playerHandlers.js +39 -0
- package/src/main/handlers/preferencesHandlers.js +46 -0
- package/src/main/handlers/queueHandlers.js +81 -0
- package/src/main/handlers/rendererHandlers.js +63 -0
- package/src/main/handlers/settingsHandlers.js +42 -0
- package/src/main/handlers/webServerHandlers.js +105 -0
- package/src/main/main.js +2351 -0
- package/src/main/preload.js +252 -0
- package/src/main/settingsManager.js +139 -0
- package/src/main/statePersistence.js +193 -0
- package/src/main/utils/pathValidator.js +112 -0
- package/src/main/webServer.js +2535 -0
- package/src/native/autotune.js +417 -0
- package/src/renderer/adapters/ElectronBridge.js +677 -0
- package/src/renderer/canvas.html +80 -0
- package/src/renderer/components/App.jsx +303 -0
- package/src/renderer/components/AppRoot.jsx +37 -0
- package/src/renderer/components/AudioDeviceSettings.jsx +145 -0
- package/src/renderer/components/EffectsPanelWrapper.jsx +267 -0
- package/src/renderer/components/MixerTab.jsx +233 -0
- package/src/renderer/components/MixerTabWrapper.jsx +31 -0
- package/src/renderer/components/PortalSelect.jsx +239 -0
- package/src/renderer/components/QueueTab.jsx +116 -0
- package/src/renderer/components/RequestsListWrapper.jsx +78 -0
- package/src/renderer/components/ServerTab.jsx +472 -0
- package/src/renderer/components/SongInfoBarWrapper.jsx +77 -0
- package/src/renderer/components/StatusBar.jsx +92 -0
- package/src/renderer/components/TabNavigation.jsx +77 -0
- package/src/renderer/components/TransportControlsWrapper.jsx +69 -0
- package/src/renderer/components/creator/CreateTab.jsx +1236 -0
- package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js +2 -0
- package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js.map +1 -0
- package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js +2 -0
- package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js.map +1 -0
- package/src/renderer/dist/assets/player-DVrqp7N5.js +3 -0
- package/src/renderer/dist/assets/player-DVrqp7N5.js.map +1 -0
- package/src/renderer/dist/assets/songLoaders-BaTgGib4.js +2 -0
- package/src/renderer/dist/assets/songLoaders-BaTgGib4.js.map +1 -0
- package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js +2 -0
- package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js.map +1 -0
- package/src/renderer/dist/js/autoTuneWorklet.js +224 -0
- package/src/renderer/dist/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/dist/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/dist/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/dist/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/dist/renderer.css +1 -0
- package/src/renderer/dist/renderer.js +62 -0
- package/src/renderer/dist/renderer.js.map +1 -0
- package/src/renderer/dist/renderer.woff2 +0 -0
- package/src/renderer/hooks/useKeyboardShortcuts.js +154 -0
- package/src/renderer/index.html +24 -0
- package/src/renderer/index.html.backup +372 -0
- package/src/renderer/js/PlayerInterface.js +267 -0
- package/src/renderer/js/autoTuneWorklet.js +224 -0
- package/src/renderer/js/butterchurnVerify.js +46 -0
- package/src/renderer/js/canvas-app.js +114 -0
- package/src/renderer/js/cdgPlayer.js +685 -0
- package/src/renderer/js/kaiPlayer.js +1200 -0
- package/src/renderer/js/karaokeRenderer.js +3392 -0
- package/src/renderer/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/js/microphoneEngine.js +656 -0
- package/src/renderer/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/js/player.js +232 -0
- package/src/renderer/js/referencePitchTracker.js +130 -0
- package/src/renderer/js/songLoaders.js +334 -0
- package/src/renderer/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/js/webrtcManager.js +511 -0
- package/src/renderer/lib/butterchurn.min.js +6739 -0
- package/src/renderer/lib/butterchurnPresets.min.js +1 -0
- package/src/renderer/lib/cdgraphics-wrapper.js +16 -0
- package/src/renderer/lib/cdgraphics.js +299 -0
- package/src/renderer/public/js/autoTuneWorklet.js +224 -0
- package/src/renderer/public/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/public/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/public/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/public/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/react-entry.jsx +44 -0
- package/src/renderer/styles/tailwind.css +106 -0
- package/src/renderer/utils/qrCodeGenerator.js +98 -0
- package/src/renderer/vite.config.js +31 -0
- package/src/shared/adapters/BridgeInterface.js +195 -0
- package/src/shared/components/EffectsPanel.jsx +177 -0
- package/src/shared/components/LibraryPanel.jsx +701 -0
- package/src/shared/components/LineDetailCanvas.jsx +167 -0
- package/src/shared/components/LyricLine.jsx +505 -0
- package/src/shared/components/LyricRejection.jsx +84 -0
- package/src/shared/components/LyricSuggestion.jsx +80 -0
- package/src/shared/components/LyricsEditorCanvas.jsx +271 -0
- package/src/shared/components/MixerPanel.jsx +94 -0
- package/src/shared/components/PlayerControls.jsx +206 -0
- package/src/shared/components/PortalSelect.jsx +239 -0
- package/src/shared/components/QueueList.jsx +365 -0
- package/src/shared/components/QuickSearch.jsx +126 -0
- package/src/shared/components/RequestsList.jsx +121 -0
- package/src/shared/components/SongEditor.jsx +1362 -0
- package/src/shared/components/SongInfoBar.jsx +81 -0
- package/src/shared/components/ThemeToggle.jsx +106 -0
- package/src/shared/components/Toast.jsx +30 -0
- package/src/shared/components/VisualizationSettings.jsx +243 -0
- package/src/shared/constants.js +95 -0
- package/src/shared/context/BridgeContext.jsx +32 -0
- package/src/shared/contexts/AudioContext.jsx +37 -0
- package/src/shared/contexts/PlayerContext.jsx +66 -0
- package/src/shared/contexts/SettingsContext.jsx +50 -0
- package/src/shared/defaults.js +158 -0
- package/src/shared/formatUtils.js +59 -0
- package/src/shared/formatUtils.test.js +207 -0
- package/src/shared/hooks/useAppState.js +97 -0
- package/src/shared/hooks/useAudioEngine.js +264 -0
- package/src/shared/hooks/usePlayer.js +89 -0
- package/src/shared/hooks/useSettingsPersistence.js +74 -0
- package/src/shared/hooks/useWebRTC.js +118 -0
- package/src/shared/ipcContracts.js +299 -0
- package/src/shared/package.json +3 -0
- package/src/shared/services/creatorService.js +373 -0
- package/src/shared/services/creatorService.test.js +413 -0
- package/src/shared/services/editorService.js +213 -0
- package/src/shared/services/editorService.test.js +219 -0
- package/src/shared/services/effectsService.js +271 -0
- package/src/shared/services/effectsService.test.js +418 -0
- package/src/shared/services/libraryService.js +438 -0
- package/src/shared/services/libraryService.test.js +474 -0
- package/src/shared/services/mixerService.js +172 -0
- package/src/shared/services/mixerService.test.js +399 -0
- package/src/shared/services/playerService.js +221 -0
- package/src/shared/services/playerService.test.js +357 -0
- package/src/shared/services/preferencesService.js +219 -0
- package/src/shared/services/queueService.js +226 -0
- package/src/shared/services/queueService.test.js +430 -0
- package/src/shared/services/requestsService.js +155 -0
- package/src/shared/services/requestsService.test.js +362 -0
- package/src/shared/services/serverSettingsService.js +151 -0
- package/src/shared/services/settingsService.js +257 -0
- package/src/shared/services/settingsService.test.js +295 -0
- package/src/shared/state/StateManager.js +263 -0
- package/src/shared/utils/audio.js +42 -0
- package/src/shared/utils/format.js +32 -0
- package/src/shared/utils/lyricsUtils.js +162 -0
- package/src/test/setup.js +40 -0
- package/src/utils/cdgLoader.js +180 -0
- package/src/utils/m4aLoader.js +333 -0
- package/src/web/App.jsx +578 -0
- package/src/web/adapters/WebBridge.js +428 -0
- package/src/web/components/PlayerSettingsPanel.jsx +231 -0
- package/src/web/components/SongSearch.jsx +180 -0
- package/src/web/dist/assets/index-0H-RnRrV.js +51 -0
- package/src/web/dist/assets/index-0H-RnRrV.js.map +1 -0
- package/src/web/dist/assets/index-DYW2zB0u.css +1 -0
- package/src/web/dist/index.html +15 -0
- package/src/web/index.html +14 -0
- package/src/web/main.jsx +10 -0
- package/src/web/package-lock.json +1765 -0
- package/src/web/pages/SongRequestPage.jsx +619 -0
- package/src/web/styles/tailwind.css +68 -0
- package/src/web/vite.config.js +27 -0
- package/static/fonts/material-icons.woff2 +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Potion of Spirits.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Songflower _Moss Posy_.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Storm of the Eye _Thunder_ - mash0000 - quasi pseudo meta concentrics.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi _ Geiss - Airhandler _Kali Mix_ - Canvas Mix.png +0 -0
- package/static/images/butterchurn-screenshots/An AdamFX n Martin Infusion 2 flexi - Why The Sky Looks Diffrent Today - AdamFx n Martin Infusion - Tack Tile Disfunction B.png +0 -0
- package/static/images/butterchurn-screenshots/Cope - The Neverending Explosion of Red Liquid Fire.png +0 -0
- proton lights __Krash_s beat code_ _Phat_remix02b.png +0 -0
- package/static/images/butterchurn-screenshots/Eo_S_ _ Phat - cubetrace - v2.png +0 -0
- package/static/images/butterchurn-screenshots/Eo_S_ _ Zylot - skylight _Stained Glass Majesty mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - alien fish pond.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - area 51.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - infused with the spiral.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - mindblob _shiny mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - mindblob mix.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - predator-prey-spirals.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - smashing fractals _acid etching mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - truly soft piece of software - this is generic texturing _Jelly_ .png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ Martin - astral projection.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ Martin - cascading decay swing.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ amandio c - piercing 05 - Kopie _2_ - Kopie.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ stahlregen - jelly showoff parade.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi_ fishbrain_ Geiss _ Martin - tokamak witchery.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi_ martin _ geiss - dedicated to the sherwin maxawow.png +0 -0
- package/static/images/butterchurn-screenshots/Fumbling_Foo _ Flexi_ Martin_ Orb_ Unchained - Star Nova v7b.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Cauldron - painterly 2 _saturation remix_.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Reaction Diffusion 2.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Spiral Artifact.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Thumb Drum.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss _ Flexi _ Martin - disconnected.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss_ Flexi _ Stahlregen - Thumbdrum Tokamak _crossfiring aftermath jelly mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/Goody - The Wild Vort.png +0 -0
- package/static/images/butterchurn-screenshots/Idiot - Star Of Annon.png +0 -0
- package/static/images/butterchurn-screenshots/Krash _ Illusion - Spiral Movement.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - QBikal - Surface Turbulence IIb.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - acid wiring.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - charisma.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - liquid arrows.png +0 -0
- package/static/images/butterchurn-screenshots/Milk Artist At our Best - FED - SlowFast Ft AdamFX n Martin - HD CosmoFX.png +0 -0
- package/static/images/butterchurn-screenshots/ORB - Waaa.png +0 -0
- package/static/images/butterchurn-screenshots/Phat_fiShbRaiN_Eo_S_Mandala_Chasers_remix.png +0 -0
- package/static/images/butterchurn-screenshots/Rovastar - Oozing Resistance.png +0 -0
- package/static/images/butterchurn-screenshots/Rovastar _ Loadus _ Geiss - FractalDrop _Triple Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/TonyMilkdrop - Leonardo Da Vinci_s Balloon _Flexi - merry-go-round _ techstyle_.png +0 -0
- package/static/images/butterchurn-screenshots/TonyMilkdrop - Magellan_s Nebula _Flexi - you enter first _ multiverse_.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained - Rewop.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained - Unified Drag 2.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained _ Rovastar - Wormhole Pillars _Hall of Shadows mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - Paint Spill _Music Reactive Paint Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - Star Ornament.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - True Visionary _Final Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/_Aderrasi - Wanderer in Curved Space - mash0000 - faclempt kibitzing meshuggana schmaltz _Geiss color mix_.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - Artifact 01.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - Desert Rose 2.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - untitled.png +0 -0
- package/static/images/butterchurn-screenshots/_Mig_049.png +0 -0
- package/static/images/butterchurn-screenshots/_Mig_085.png +0 -0
- package/static/images/butterchurn-screenshots/_Rovastar _ Geiss - Hurricane Nightmare _Posterize Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _197_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _220_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _431_.png +0 -0
- package/static/images/butterchurn-screenshots/cope _ martin - mother-of-pearl.png +0 -0
- package/static/images/butterchurn-screenshots/fiShbRaiN _ Flexi - witchcraft 2_0.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - bouncing balls _double mindblob neon mix_.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - mom_ why the sky looks different today.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - patternton_ district of media_ capitol of the united abstractions of fractopia.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - swing out on the spiral.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - what is the matrix.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ amandio c - organic _random mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ amandio c - organic12-3d-2_milk.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ fishbrain - neon mindblob grafitti.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ geiss - pogo cubes vs_ tokamak vs_ game of life _stahls jelly 4_5 finish_.png +0 -0
- package/static/images/butterchurn-screenshots/high-altitude basket unraveling - singh grooves nitrogen argon nz_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - The Bridge of Khazad-Dum.png +0 -0
- package/static/images/butterchurn-screenshots/martin - angel flight.png +0 -0
- package/static/images/butterchurn-screenshots/martin - another kind of groove.png +0 -0
- package/static/images/butterchurn-screenshots/martin - bombyx mori.png +0 -0
- package/static/images/butterchurn-screenshots/martin - castle in the air.png +0 -0
- package/static/images/butterchurn-screenshots/martin - chain breaker.png +0 -0
- package/static/images/butterchurn-screenshots/martin - disco mix 4.png +0 -0
- package/static/images/butterchurn-screenshots/martin - extreme heat.png +0 -0
- package/static/images/butterchurn-screenshots/martin - frosty caves 2.png +0 -0
- package/static/images/butterchurn-screenshots/martin - fruit machine.png +0 -0
- package/static/images/butterchurn-screenshots/martin - ghost city.png +0 -0
- package/static/images/butterchurn-screenshots/martin - glass corridor.png +0 -0
- package/static/images/butterchurn-screenshots/martin - infinity _2010 update_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - mandelbox explorer - high speed demo version.png +0 -0
- package/static/images/butterchurn-screenshots/martin - mucus cervix.png +0 -0
- package/static/images/butterchurn-screenshots/martin - reflections on black tiles.png +0 -0
- package/static/images/butterchurn-screenshots/martin - stormy sea _2010 update_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - witchcraft reloaded.png +0 -0
- package/static/images/butterchurn-screenshots/martin _ flexi - diamond cutter _prismaticvortex_com_ - camille - i wish i wish i wish i was constrained.png +0 -0
- package/static/images/butterchurn-screenshots/martin _shadow harlequins shape code_ - fata morgana.png +0 -0
- package/static/images/butterchurn-screenshots/martin_ flexi_ fishbrain _ sto - enterstate _random mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/sawtooth grin roam.png +0 -0
- package/static/images/butterchurn-screenshots/shifter - dark tides bdrv mix 2.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - Rovastar - Sunflower Passion _Enlightment Mix__Phat_edit _ flexi und martin shaders - circumflex in character classes in regular expression.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - heretical crosscut playpen.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - uninitialized variabowl _hydroponic chronic_.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - vector exp 1 - couldn_t not.png +0 -0
- package/static/images/butterchurn-screenshots/yin - 191 - Temporal singularities.png +0 -0
- package/static/images/logo-512.png +0 -0
- package/static/images/logo.png +0 -0
- package/static/loukai-logo.png +0 -0
- package/static/screenshot-generator.html +610 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FFmpeg Service - Audio conversion and processing
|
|
3
|
+
*
|
|
4
|
+
* Provides Node.js wrappers for FFmpeg/FFprobe operations:
|
|
5
|
+
* - Audio info extraction (duration, sample rate, channels)
|
|
6
|
+
* - Format conversion (to WAV for processing)
|
|
7
|
+
* - AAC encoding (for M4A stems)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { spawn, execSync } from 'child_process';
|
|
11
|
+
import { existsSync } from 'fs';
|
|
12
|
+
import { join } from 'path';
|
|
13
|
+
import { platform } from 'os';
|
|
14
|
+
import { getCacheDir } from './systemChecker.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get FFmpeg executable path
|
|
18
|
+
* Checks system PATH first, then cache directory
|
|
19
|
+
*/
|
|
20
|
+
export function getFFmpegPath() {
|
|
21
|
+
// Check system PATH first
|
|
22
|
+
try {
|
|
23
|
+
const plat = platform();
|
|
24
|
+
const checkCmd = plat === 'win32' ? 'where ffmpeg' : 'which ffmpeg';
|
|
25
|
+
const result = execSync(checkCmd, { encoding: 'utf8', timeout: 5000 });
|
|
26
|
+
const path = result.trim().split('\n')[0];
|
|
27
|
+
if (path && existsSync(path)) {
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// Not in PATH, check cache
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Check cache directory
|
|
35
|
+
const cacheDir = getCacheDir();
|
|
36
|
+
const plat = platform();
|
|
37
|
+
const filename = plat === 'win32' ? 'ffmpeg.exe' : 'ffmpeg';
|
|
38
|
+
const cachedPath = join(cacheDir, 'bin', filename);
|
|
39
|
+
|
|
40
|
+
if (existsSync(cachedPath)) {
|
|
41
|
+
return cachedPath;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Default to assuming it's in PATH (will fail if not)
|
|
45
|
+
return 'ffmpeg';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get FFprobe executable path
|
|
50
|
+
*/
|
|
51
|
+
export function getFFprobePath() {
|
|
52
|
+
// Check system PATH first
|
|
53
|
+
try {
|
|
54
|
+
const plat = platform();
|
|
55
|
+
const checkCmd = plat === 'win32' ? 'where ffprobe' : 'which ffprobe';
|
|
56
|
+
const result = execSync(checkCmd, { encoding: 'utf8', timeout: 5000 });
|
|
57
|
+
const path = result.trim().split('\n')[0];
|
|
58
|
+
if (path && existsSync(path)) {
|
|
59
|
+
return path;
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
// Not in PATH, check cache
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Check cache directory
|
|
66
|
+
const cacheDir = getCacheDir();
|
|
67
|
+
const plat = platform();
|
|
68
|
+
const filename = plat === 'win32' ? 'ffprobe.exe' : 'ffprobe';
|
|
69
|
+
const cachedPath = join(cacheDir, 'bin', filename);
|
|
70
|
+
|
|
71
|
+
if (existsSync(cachedPath)) {
|
|
72
|
+
return cachedPath;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return 'ffprobe';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get audio file information using ffprobe
|
|
80
|
+
*
|
|
81
|
+
* @param {string} inputPath - Path to audio file
|
|
82
|
+
* @returns {Promise<Object>} Audio info (duration, sampleRate, channels, codec)
|
|
83
|
+
*/
|
|
84
|
+
export function getAudioInfo(inputPath) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const ffprobe = getFFprobePath();
|
|
87
|
+
|
|
88
|
+
const args = [
|
|
89
|
+
'-v',
|
|
90
|
+
'quiet',
|
|
91
|
+
'-print_format',
|
|
92
|
+
'json',
|
|
93
|
+
'-show_format',
|
|
94
|
+
'-show_streams',
|
|
95
|
+
inputPath,
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const proc = spawn(ffprobe, args, { timeout: 30000 });
|
|
99
|
+
|
|
100
|
+
let stdout = '';
|
|
101
|
+
let stderr = '';
|
|
102
|
+
|
|
103
|
+
proc.stdout.on('data', (data) => {
|
|
104
|
+
stdout += data.toString();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
proc.stderr.on('data', (data) => {
|
|
108
|
+
stderr += data.toString();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
proc.on('close', (code) => {
|
|
112
|
+
if (code !== 0) {
|
|
113
|
+
reject(new Error(`ffprobe failed: ${stderr}`));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const info = JSON.parse(stdout);
|
|
119
|
+
|
|
120
|
+
// Find audio stream
|
|
121
|
+
const audioStream = info.streams?.find((s) => s.codec_type === 'audio');
|
|
122
|
+
|
|
123
|
+
if (!audioStream) {
|
|
124
|
+
reject(new Error('No audio stream found in file'));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Extract ID3/metadata tags (normalize to lowercase keys)
|
|
129
|
+
const rawTags = info.format?.tags || {};
|
|
130
|
+
const tags = {};
|
|
131
|
+
for (const [key, value] of Object.entries(rawTags)) {
|
|
132
|
+
tags[key.toLowerCase()] = value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Count all audio streams and get their metadata
|
|
136
|
+
const audioStreams = info.streams?.filter((s) => s.codec_type === 'audio') || [];
|
|
137
|
+
const streamInfo = audioStreams.map((s, idx) => ({
|
|
138
|
+
index: idx,
|
|
139
|
+
title: s.tags?.title || `track${idx}`,
|
|
140
|
+
codec: s.codec_name,
|
|
141
|
+
channels: s.channels,
|
|
142
|
+
sampleRate: parseInt(s.sample_rate, 10),
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
resolve({
|
|
146
|
+
duration: parseFloat(info.format?.duration || audioStream.duration || 0),
|
|
147
|
+
sampleRate: parseInt(audioStream.sample_rate, 10),
|
|
148
|
+
channels: audioStream.channels,
|
|
149
|
+
codec: audioStream.codec_name,
|
|
150
|
+
bitRate: parseInt(info.format?.bit_rate || audioStream.bit_rate || 0, 10),
|
|
151
|
+
format: info.format?.format_name,
|
|
152
|
+
// ID3 tags
|
|
153
|
+
title: tags.title || '',
|
|
154
|
+
artist: tags.artist || tags.album_artist || '',
|
|
155
|
+
album: tags.album || '',
|
|
156
|
+
tags,
|
|
157
|
+
// Stem detection info
|
|
158
|
+
audioStreamCount: audioStreams.length,
|
|
159
|
+
audioStreams: streamInfo,
|
|
160
|
+
});
|
|
161
|
+
} catch (e) {
|
|
162
|
+
reject(new Error(`Failed to parse ffprobe output: ${e.message}`));
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
proc.on('error', (err) => {
|
|
167
|
+
reject(new Error(`Failed to spawn ffprobe: ${err.message}`));
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Convert audio file to WAV format
|
|
174
|
+
*
|
|
175
|
+
* @param {string} inputPath - Input audio file
|
|
176
|
+
* @param {string} outputPath - Output WAV file path
|
|
177
|
+
* @param {Object} options - Conversion options
|
|
178
|
+
* @param {number} options.sampleRate - Target sample rate (default 44100)
|
|
179
|
+
* @param {number} options.channels - Target channels (default 2 for stereo)
|
|
180
|
+
* @param {Function} onProgress - Progress callback (0-100)
|
|
181
|
+
* @returns {Promise<void>}
|
|
182
|
+
*/
|
|
183
|
+
export function convertToWav(inputPath, outputPath, options = {}, onProgress = null) {
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
const ffmpeg = getFFmpegPath();
|
|
186
|
+
const sampleRate = options.sampleRate || 44100;
|
|
187
|
+
const channels = options.channels || 2;
|
|
188
|
+
|
|
189
|
+
const args = [
|
|
190
|
+
'-y', // Overwrite output
|
|
191
|
+
'-i',
|
|
192
|
+
inputPath,
|
|
193
|
+
'-ar',
|
|
194
|
+
String(sampleRate),
|
|
195
|
+
'-ac',
|
|
196
|
+
String(channels),
|
|
197
|
+
'-f',
|
|
198
|
+
'wav',
|
|
199
|
+
'-progress',
|
|
200
|
+
'pipe:2', // Progress to stderr
|
|
201
|
+
outputPath,
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
const proc = spawn(ffmpeg, args, { timeout: 600000 }); // 10 min timeout
|
|
205
|
+
|
|
206
|
+
let duration = 0;
|
|
207
|
+
let stderr = '';
|
|
208
|
+
|
|
209
|
+
// Parse progress from stderr
|
|
210
|
+
proc.stderr.on('data', (data) => {
|
|
211
|
+
const str = data.toString();
|
|
212
|
+
stderr += str;
|
|
213
|
+
|
|
214
|
+
// Extract duration on first encounter
|
|
215
|
+
if (!duration) {
|
|
216
|
+
const durMatch = str.match(/Duration:\s*(\d+):(\d+):(\d+\.?\d*)/);
|
|
217
|
+
if (durMatch) {
|
|
218
|
+
duration =
|
|
219
|
+
parseInt(durMatch[1], 10) * 3600 +
|
|
220
|
+
parseInt(durMatch[2], 10) * 60 +
|
|
221
|
+
parseFloat(durMatch[3]);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Extract current time for progress
|
|
226
|
+
if (duration && onProgress) {
|
|
227
|
+
const timeMatch = str.match(/out_time_ms=(\d+)/);
|
|
228
|
+
if (timeMatch) {
|
|
229
|
+
const currentMs = parseInt(timeMatch[1], 10);
|
|
230
|
+
const progress = Math.min(100, (currentMs / 1000000 / duration) * 100);
|
|
231
|
+
onProgress(progress);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
proc.on('close', (code) => {
|
|
237
|
+
if (code !== 0) {
|
|
238
|
+
reject(new Error(`FFmpeg conversion failed: ${stderr.slice(-500)}`));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
resolve();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
proc.on('error', (err) => {
|
|
245
|
+
reject(new Error(`Failed to spawn ffmpeg: ${err.message}`));
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Encode audio to AAC for M4A packaging
|
|
252
|
+
*
|
|
253
|
+
* @param {string} inputPath - Input WAV file
|
|
254
|
+
* @param {string} outputPath - Output M4A file path
|
|
255
|
+
* @param {Object} options - Encoding options
|
|
256
|
+
* @param {string} options.bitrate - Target bitrate (default '128k')
|
|
257
|
+
* @param {number} options.sampleRate - Target sample rate (default 44100)
|
|
258
|
+
* @param {Function} onProgress - Progress callback (0-100)
|
|
259
|
+
* @returns {Promise<Object>} Encoding info
|
|
260
|
+
*/
|
|
261
|
+
export function encodeToAAC(inputPath, outputPath, options = {}, onProgress = null) {
|
|
262
|
+
return new Promise((resolve, reject) => {
|
|
263
|
+
const ffmpeg = getFFmpegPath();
|
|
264
|
+
const bitrate = options.bitrate || '128k';
|
|
265
|
+
const sampleRate = options.sampleRate || 44100;
|
|
266
|
+
|
|
267
|
+
const args = [
|
|
268
|
+
'-y',
|
|
269
|
+
'-i',
|
|
270
|
+
inputPath,
|
|
271
|
+
'-c:a',
|
|
272
|
+
'aac',
|
|
273
|
+
'-b:a',
|
|
274
|
+
bitrate,
|
|
275
|
+
'-ar',
|
|
276
|
+
String(sampleRate),
|
|
277
|
+
'-ac',
|
|
278
|
+
'2',
|
|
279
|
+
'-progress',
|
|
280
|
+
'pipe:2',
|
|
281
|
+
outputPath,
|
|
282
|
+
];
|
|
283
|
+
|
|
284
|
+
const proc = spawn(ffmpeg, args, { timeout: 600000 });
|
|
285
|
+
|
|
286
|
+
let duration = 0;
|
|
287
|
+
let stderr = '';
|
|
288
|
+
|
|
289
|
+
proc.stderr.on('data', (data) => {
|
|
290
|
+
const str = data.toString();
|
|
291
|
+
stderr += str;
|
|
292
|
+
|
|
293
|
+
if (!duration) {
|
|
294
|
+
const durMatch = str.match(/Duration:\s*(\d+):(\d+):(\d+\.?\d*)/);
|
|
295
|
+
if (durMatch) {
|
|
296
|
+
duration =
|
|
297
|
+
parseInt(durMatch[1], 10) * 3600 +
|
|
298
|
+
parseInt(durMatch[2], 10) * 60 +
|
|
299
|
+
parseFloat(durMatch[3]);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (duration && onProgress) {
|
|
304
|
+
const timeMatch = str.match(/out_time_ms=(\d+)/);
|
|
305
|
+
if (timeMatch) {
|
|
306
|
+
const currentMs = parseInt(timeMatch[1], 10);
|
|
307
|
+
const progress = Math.min(100, (currentMs / 1000000 / duration) * 100);
|
|
308
|
+
onProgress(progress);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
proc.on('close', (code) => {
|
|
314
|
+
if (code !== 0) {
|
|
315
|
+
reject(new Error(`AAC encoding failed: ${stderr.slice(-500)}`));
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
resolve({
|
|
320
|
+
bitrate,
|
|
321
|
+
sampleRate,
|
|
322
|
+
outputPath,
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
proc.on('error', (err) => {
|
|
327
|
+
reject(new Error(`Failed to spawn ffmpeg: ${err.message}`));
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Extract audio from video file
|
|
334
|
+
*
|
|
335
|
+
* @param {string} inputPath - Input video file
|
|
336
|
+
* @param {string} outputPath - Output audio file path
|
|
337
|
+
* @param {Object} options - Extraction options
|
|
338
|
+
* @param {string} options.format - Output format ('wav', 'mp3', 'aac')
|
|
339
|
+
* @param {number} options.sampleRate - Target sample rate
|
|
340
|
+
* @returns {Promise<void>}
|
|
341
|
+
*/
|
|
342
|
+
export function extractAudio(inputPath, outputPath, options = {}) {
|
|
343
|
+
return new Promise((resolve, reject) => {
|
|
344
|
+
const ffmpeg = getFFmpegPath();
|
|
345
|
+
const format = options.format || 'wav';
|
|
346
|
+
const sampleRate = options.sampleRate || 44100;
|
|
347
|
+
|
|
348
|
+
const args = ['-y', '-i', inputPath, '-vn', '-ar', String(sampleRate), '-ac', '2'];
|
|
349
|
+
|
|
350
|
+
// Add format-specific options
|
|
351
|
+
if (format === 'wav') {
|
|
352
|
+
args.push('-f', 'wav');
|
|
353
|
+
} else if (format === 'mp3') {
|
|
354
|
+
args.push('-c:a', 'libmp3lame', '-b:a', '192k');
|
|
355
|
+
} else if (format === 'aac') {
|
|
356
|
+
args.push('-c:a', 'aac', '-b:a', '192k');
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
args.push(outputPath);
|
|
360
|
+
|
|
361
|
+
const proc = spawn(ffmpeg, args, { timeout: 600000 });
|
|
362
|
+
|
|
363
|
+
let stderr = '';
|
|
364
|
+
|
|
365
|
+
proc.stderr.on('data', (data) => {
|
|
366
|
+
stderr += data.toString();
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
proc.on('close', (code) => {
|
|
370
|
+
if (code !== 0) {
|
|
371
|
+
reject(new Error(`Audio extraction failed: ${stderr.slice(-500)}`));
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
resolve();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
proc.on('error', (err) => {
|
|
378
|
+
reject(new Error(`Failed to spawn ffmpeg: ${err.message}`));
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Check if input file is a video (has video stream)
|
|
385
|
+
*
|
|
386
|
+
* @param {string} inputPath - Path to file
|
|
387
|
+
* @returns {Promise<boolean>}
|
|
388
|
+
*/
|
|
389
|
+
export function isVideoFile(inputPath) {
|
|
390
|
+
const ffprobe = getFFprobePath();
|
|
391
|
+
|
|
392
|
+
return new Promise((resolve) => {
|
|
393
|
+
const args = [
|
|
394
|
+
'-v',
|
|
395
|
+
'quiet',
|
|
396
|
+
'-select_streams',
|
|
397
|
+
'v:0',
|
|
398
|
+
'-show_entries',
|
|
399
|
+
'stream=codec_type',
|
|
400
|
+
'-of',
|
|
401
|
+
'csv=p=0',
|
|
402
|
+
inputPath,
|
|
403
|
+
];
|
|
404
|
+
|
|
405
|
+
const proc = spawn(ffprobe, args, { timeout: 10000 });
|
|
406
|
+
|
|
407
|
+
let stdout = '';
|
|
408
|
+
|
|
409
|
+
proc.stdout.on('data', (data) => {
|
|
410
|
+
stdout += data.toString();
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
proc.on('close', () => {
|
|
414
|
+
resolve(stdout.trim() === 'video');
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
proc.on('error', () => {
|
|
418
|
+
resolve(false);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Extract a specific audio track from an M4A stems file to WAV
|
|
425
|
+
*
|
|
426
|
+
* @param {string} inputPath - Input M4A file with multiple audio streams
|
|
427
|
+
* @param {string} outputPath - Output WAV file path
|
|
428
|
+
* @param {number} trackIndex - Audio track index (0-based)
|
|
429
|
+
* @param {Object} options - Extraction options
|
|
430
|
+
* @param {number} options.sampleRate - Target sample rate (default 44100)
|
|
431
|
+
* @returns {Promise<void>}
|
|
432
|
+
*/
|
|
433
|
+
export function extractStemTrack(inputPath, outputPath, trackIndex, options = {}) {
|
|
434
|
+
return new Promise((resolve, reject) => {
|
|
435
|
+
const ffmpeg = getFFmpegPath();
|
|
436
|
+
const sampleRate = options.sampleRate || 44100;
|
|
437
|
+
|
|
438
|
+
// -map 0:a:{trackIndex} selects the specific audio stream
|
|
439
|
+
const args = [
|
|
440
|
+
'-y',
|
|
441
|
+
'-i',
|
|
442
|
+
inputPath,
|
|
443
|
+
'-map',
|
|
444
|
+
`0:a:${trackIndex}`,
|
|
445
|
+
'-ar',
|
|
446
|
+
String(sampleRate),
|
|
447
|
+
'-ac',
|
|
448
|
+
'2',
|
|
449
|
+
'-f',
|
|
450
|
+
'wav',
|
|
451
|
+
outputPath,
|
|
452
|
+
];
|
|
453
|
+
|
|
454
|
+
console.log(`🎤 Extracting audio track ${trackIndex} to WAV...`);
|
|
455
|
+
const proc = spawn(ffmpeg, args, { timeout: 300000 }); // 5 min timeout
|
|
456
|
+
|
|
457
|
+
let stderr = '';
|
|
458
|
+
|
|
459
|
+
proc.stderr.on('data', (data) => {
|
|
460
|
+
stderr += data.toString();
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
proc.on('close', (code) => {
|
|
464
|
+
if (code !== 0) {
|
|
465
|
+
reject(new Error(`Track extraction failed: ${stderr.slice(-500)}`));
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
console.log(`✅ Track ${trackIndex} extracted successfully`);
|
|
469
|
+
resolve();
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
proc.on('error', (err) => {
|
|
473
|
+
reject(new Error(`Failed to spawn ffmpeg: ${err.message}`));
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export default {
|
|
479
|
+
getFFmpegPath,
|
|
480
|
+
getFFprobePath,
|
|
481
|
+
getAudioInfo,
|
|
482
|
+
convertToWav,
|
|
483
|
+
encodeToAAC,
|
|
484
|
+
extractAudio,
|
|
485
|
+
extractStemTrack,
|
|
486
|
+
isVideoFile,
|
|
487
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installation Logger - Intercepts console.log and sends to UI
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
let logCallback = null;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Set the callback to receive log messages
|
|
9
|
+
*/
|
|
10
|
+
export function setLogCallback(callback) {
|
|
11
|
+
logCallback = callback;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Clear the callback
|
|
16
|
+
*/
|
|
17
|
+
export function clearLogCallback() {
|
|
18
|
+
logCallback = null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Log a message (sends to console AND callback)
|
|
23
|
+
*/
|
|
24
|
+
export function log(...args) {
|
|
25
|
+
// Always log to console
|
|
26
|
+
console.log(...args);
|
|
27
|
+
|
|
28
|
+
// Also send to UI if callback is set
|
|
29
|
+
if (logCallback) {
|
|
30
|
+
const message = args
|
|
31
|
+
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
|
|
32
|
+
.join(' ');
|
|
33
|
+
logCallback(message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Log an error (sends to console AND callback)
|
|
39
|
+
*/
|
|
40
|
+
export function error(...args) {
|
|
41
|
+
// Always log to console
|
|
42
|
+
console.error(...args);
|
|
43
|
+
|
|
44
|
+
// Also send to UI if callback is set
|
|
45
|
+
if (logCallback) {
|
|
46
|
+
const message = args
|
|
47
|
+
.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg)))
|
|
48
|
+
.join(' ');
|
|
49
|
+
logCallback('❌ ' + message);
|
|
50
|
+
}
|
|
51
|
+
}
|