From 9d346eadb0ad12279a19c1407b70bb9b3629b607 Mon Sep 17 00:00:00 2001 From: Alex Hetrick Date: Thu, 12 Feb 2026 22:27:27 -0500 Subject: [PATCH] Fix bootstrap script ffmpeg extraction + stabilize Demucs stem filenames --- download-third-party-apps.js | 27 ++++++++++++++++++++------- main-src/processQueue.js | 7 +++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/download-third-party-apps.js b/download-third-party-apps.js index 9b6f0e5..1587524 100644 --- a/download-third-party-apps.js +++ b/download-third-party-apps.js @@ -49,6 +49,11 @@ async function fileExists(filePath) { } async function moveDirChildrenUpAndDeleteDir(dirName) { + if (!(await fileExists(dirName))) { + console.log(`Skipping move; directory does not exist: "${dirName}"`) + return + } + const parentDirName = path.resolve(path.join(dirName, '..')) const fileNames = await fsPromises.readdir(dirName) for (const fileName of fileNames) { @@ -196,14 +201,22 @@ async function main() { ) if (process.platform === 'win32') { - await moveDirChildrenUpAndDeleteDir( - path.join( - `${winOrMac}-extra-files`, - 'ThirdPartyApps', - 'ffmpeg', - 'ffmpeg-8.0-essentials_build' - ) + const ffmpegParentDir = path.join(`${winOrMac}-extra-files`, 'ThirdPartyApps', 'ffmpeg') + const ffmpegDirChildren = await fsPromises.readdir(ffmpegParentDir, { + withFileTypes: true, + }) + const extractedFfmpegDir = ffmpegDirChildren.find( + (entry) => + entry.isDirectory() && + entry.name.startsWith('ffmpeg-') && + entry.name.endsWith('essentials_build') ) + if (!extractedFfmpegDir) { + throw new Error( + `Unable to find extracted ffmpeg directory in "${ffmpegParentDir}" after unzip` + ) + } + await moveDirChildrenUpAndDeleteDir(path.join(ffmpegParentDir, extractedFfmpegDir.name)) } else if (process.platform === 'darwin') { console.log('Moving: ffmpeg and ffprobe') await fsPromises.rename( diff --git a/main-src/processQueue.js b/main-src/processQueue.js index 55a923f..9c94413 100644 --- a/main-src/processQueue.js +++ b/main-src/processQueue.js @@ -218,6 +218,12 @@ async function findDemucsOutputDir(basePath) { return path.join(basePath, entry.name) } } + + const hasFilesInBasePath = entries.some((entry) => entry.isFile()) + if (hasFilesInBasePath) { + return basePath + } + throw new Error('Unable to find Demucs output directory') } @@ -325,6 +331,7 @@ async function _processVideo(video, tmpDir) { `Splitting video "${video.videoId}"; ${jobCount} jobs using model "${demucsModelName}"...` ) const demucsExeArgs = [mediaPath, '-n', demucsModelName, '-j', jobCount] + demucsExeArgs.push('--filename', '{stem}.{ext}') if (getPyTorchBackend() === 'cpu') { console.log('Running with "-d cpu" to force CPU instead of CUDA') demucsExeArgs.push('-d', 'cpu')