Skip to content

Split any YouTube song into stems

TypeScript

fix: fetch bundled ffmpeg for source checkouts

Chrise83e5a069f9c
diff --git a/scripts/run.cjs b/scripts/run.cjs
index b49d107..7ee2eb3 100644
--- a/scripts/run.cjs
+++ b/scripts/run.cjs
@@ -86,6 +86,38 @@ const STEPS = {
'dist:all': [['electron-vite', 'build'], ['electron-builder', '--mac', '--win']]
}
+function ffmpegBin() {
+ return IS_WIN
+ ? path.join(ROOT, 'extras', 'ffmpeg-win', 'ffmpeg.exe')
+ : path.join(ROOT, 'extras', 'ffmpeg-mac', 'ffmpeg')
+}
+
+/* the app shells out to a bundled ffmpeg. CI fetches it before packaging, so
+ released builds are fine, but a source checkout never gets one — dev starts
+ happily and then fails at split time with "Something went wrong with the
+ built-in audio tools". Fetch it on demand with the same scripts CI runs. */
+function ensureFfmpeg() {
+ if (fs.existsSync(ffmpegBin())) return
+ const manual = IS_WIN
+ ? 'powershell -ExecutionPolicy Bypass -File scripts/fetch-ffmpeg.ps1'
+ : 'bash scripts/fetch-ffmpeg.sh'
+ console.log('> fetching bundled ffmpeg (one time)')
+ const r = IS_WIN
+ ? spawnSync(
+ 'powershell',
+ ['-ExecutionPolicy', 'Bypass', '-File', path.join('scripts', 'fetch-ffmpeg.ps1')],
+ { cwd: ROOT, stdio: 'inherit' }
+ )
+ : spawnSync('bash', [path.join('scripts', 'fetch-ffmpeg.sh')], {
+ cwd: ROOT,
+ stdio: 'inherit'
+ })
+ if (r.status !== 0 || !fs.existsSync(ffmpegBin())) {
+ console.error(`Could not fetch ffmpeg. Fetch it manually, then re-run:\n ${manual}`)
+ process.exit(r.status || 1)
+ }
+}
+
function resolveBin(name) {
const ext = IS_WIN ? '.cmd' : ''
const local = path.join(ROOT, 'node_modules', '.bin', name + ext)
@@ -113,6 +145,10 @@ function runSteps(steps) {
}
}
+// commands that produce or run the app need the bundled ffmpeg present;
+// typecheck and plain build do not
+const NEEDS_FFMPEG = new Set(['dev', 'dist', 'dist:win', 'dist:all'])
+
function main() {
const cmd = process.argv[2]
const steps = STEPS[cmd]
@@ -139,6 +175,8 @@ function main() {
process.exit(r.status ?? 1)
}
+ if (NEEDS_FFMPEG.has(cmd)) ensureFfmpeg()
+
runSteps(steps)
}