Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade demucs-cxfreeze, improve Unicode support, output to input folder #59

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions download-third-party-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function extract7z(archivePath, outPath) {
}

let winOrMac = null
let macSuffix = ''
let cudaSuffix = ''
let demucsZipOr7z = null
if (process.platform === 'win32') {
Expand All @@ -30,7 +29,6 @@ if (process.platform === 'win32') {
demucsZipOr7z = '7z'
} else if (process.platform === 'darwin') {
winOrMac = 'mac'
macSuffix = '_sierra'
demucsZipOr7z = 'zip'
}

Expand Down Expand Up @@ -101,12 +99,12 @@ async function main() {
path.join('anyos-extra-files', 'Models', 'htdemucs_ft.yaml'),
],
[
`https://github.com/stemrollerapp/demucs-cxfreeze/releases/download/2.0.0/demucs-cxfreeze-2.0.0-${winOrMac}${macSuffix}${cudaSuffix}.${demucsZipOr7z}`,
`https://github.com/stemrollerapp/demucs-cxfreeze/releases/download/release-26a2baeb0058444b3cf87028d9df721d37c78dfb/demucs-cxfreeze-${winOrMac}${cudaSuffix}.${demucsZipOr7z}`,
path.join(
`${winOrMac}-extra-files`,
'ThirdPartyApps',
'demucs-cxfreeze',
`demucs-cxfreeze-2.0.0-${winOrMac}${macSuffix}${cudaSuffix}.${demucsZipOr7z}`
`demucs-cxfreeze-${winOrMac}${cudaSuffix}.${demucsZipOr7z}`
),
],
]
Expand Down Expand Up @@ -168,7 +166,7 @@ async function main() {
`${winOrMac}-extra-files`,
'ThirdPartyApps',
'demucs-cxfreeze',
`demucs-cxfreeze-2.0.0-${winOrMac}${macSuffix}${cudaSuffix}`
`demucs-cxfreeze-${winOrMac}${cudaSuffix}`
)
)

Expand All @@ -178,7 +176,7 @@ async function main() {
`${winOrMac}-extra-files`,
'ThirdPartyApps',
'ffmpeg',
'ffmpeg-6.0-essentials_build'
'ffmpeg-7.0-essentials_build'
)
)
} else if (process.platform === 'darwin') {
Expand Down
10 changes: 10 additions & 0 deletions main-src/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ async function handleGetOutputPath() {
return processQueue.getOutputPath()
}

async function handleGetLocalFileOutputToContainingDir() {
return processQueue.getLocalFileOutputToContainingDir()
}

async function handleBrowseOutputPath() {
const response = await dialog.showOpenDialog(mainWindow, {
title: 'Select folder to store output stems',
Expand All @@ -140,6 +144,10 @@ async function handleBrowseOutputPath() {
return null
}

async function handleSetLocalFileOutputToContainingDir(event, value) {
return processQueue.setLocalFileOutputToContainingDir(value)
}

async function handleGetOutputFormat() {
return processQueue.getOutputFormat()
}
Expand Down Expand Up @@ -276,7 +284,9 @@ function main() {
ipcMain.handle('openChat', handleOpenChat)
ipcMain.handle('disableDonatePopup', handleDisableDonatePopup)
ipcMain.handle('getOutputPath', handleGetOutputPath)
ipcMain.handle('getLocalFileOutputToContainingDir', handleGetLocalFileOutputToContainingDir)
ipcMain.handle('browseOutputPath', handleBrowseOutputPath)
ipcMain.handle('setLocalFileOutputToContainingDir', handleSetLocalFileOutputToContainingDir)
ipcMain.handle('getOutputFormat', handleGetOutputFormat)
ipcMain.handle('setOutputFormat', handleSetOutputFormat)
ipcMain.handle('getPyTorchBackend', handleGetPyTorchBackend)
Expand Down
6 changes: 6 additions & 0 deletions main-src/preload.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ contextBridge.exposeInMainWorld('disableDonatePopup', () =>
ipcRenderer.invoke('disableDonatePopup')
)
contextBridge.exposeInMainWorld('getOutputPath', () => ipcRenderer.invoke('getOutputPath'))
contextBridge.exposeInMainWorld('getLocalFileOutputToContainingDir', () =>
ipcRenderer.invoke('getLocalFileOutputToContainingDir')
)
contextBridge.exposeInMainWorld('browseOutputPath', () => ipcRenderer.invoke('browseOutputPath'))
contextBridge.exposeInMainWorld('setLocalFileOutputToContainingDir', (value) =>
ipcRenderer.invoke('setLocalFileOutputToContainingDir', value)
)
contextBridge.exposeInMainWorld('getOutputFormat', () => ipcRenderer.invoke('getOutputFormat'))
contextBridge.exposeInMainWorld('setOutputFormat', (outputFormat) =>
ipcRenderer.invoke('setOutputFormat', outputFormat)
Expand Down
41 changes: 33 additions & 8 deletions main-src/processQueue.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const childProcess = require('child_process')
const treeKill = require('tree-kill')
const ytdl = require('@distube/ytdl-core')
const sanitizeFilename = require('sanitize-filename')
const { BrowserWindow, powerSaveBlocker } = require('electron')
const { app, BrowserWindow, powerSaveBlocker } = require('electron')

let statusUpdateCallback = null,
donateUpdateCallback = null
Expand Down Expand Up @@ -65,6 +65,7 @@ const CHILD_PROCESS_ENV = {
PATH: process.env.PATH,
TEMP: process.env.TEMP,
TMP: process.env.TMP,
LANG: null, // Will be set when ready to split, since we can only check system locale after `app` is ready
}
if (PATH_TO_THIRD_PARTY_APPS) {
// Override the system's PATH with the path to our own bundled third-party apps
Expand Down Expand Up @@ -130,6 +131,7 @@ function spawnAndWait(videoId, cwd, command, args) {

curProgressStemIdx = 0

CHILD_PROCESS_ENV.LANG = `${(app.getSystemLocale() || 'en-US').replace('-', '_')}.UTF-8` // Set here instead of when CHILD_PROCESS_ENV defined, because app must be ready before we can read the system locale
curChildProcess = childProcess.spawn(command, args, {
cwd,
env: CHILD_PROCESS_ENV,
Expand Down Expand Up @@ -224,11 +226,15 @@ async function _processVideo(video, tmpDir) {
throw new Error(`Invalid mediaSource: ${video.mediaSource}`)
}

setVideoStatusAndPath(video.videoId, {
step: 'processing',
progress: 0,
stemIdx: 0,
}, null)
setVideoStatusAndPath(
video.videoId,
{
step: 'processing',
progress: 0,
stemIdx: 0,
},
null
)
const jobCount = getJobCount()
console.log(
`Splitting video "${video.videoId}"; ${jobCount} jobs using model "${DEMUCS_MODEL_NAME}"...`
Expand All @@ -237,6 +243,10 @@ async function _processVideo(video, tmpDir) {
if (module.exports.getPyTorchBackend() === 'cpu') {
console.log('Running with "-d cpu" to force CPU instead of CUDA')
demucsExeArgs.push('-d', 'cpu')
} else if (process.platform === 'darwin') {
// Maybe need to apply https://github.com/facebookresearch/demucs/pull/575/files instead, in case MPS is not available on Intel Macs ??
console.log('Running with "-d mps" to force MPS instead of CPU/CUDA')
demucsExeArgs.push('-d', 'mps')
}

const demucsStemsFiletype = module.exports.getOutputFormat()
Expand Down Expand Up @@ -283,8 +293,15 @@ async function _processVideo(video, tmpDir) {
)
}

const outputFolderName = sanitizeFilename(`${video.title}-${video.videoId}`)
const outputBasePath = path.join(module.exports.getOutputPath(), outputFolderName)
const outputFolderName =
video.mediaSource === 'youtube'
? sanitizeFilename(`${video.title}-${video.videoId}`)
: sanitizeFilename(video.title)
const outputBasePathContainingFolder =
video.mediaSource === 'local' && module.exports.getLocalFileOutputToContainingDir()
? path.dirname(mediaPath)
: module.exports.getOutputPath()
const outputBasePath = path.join(outputBasePathContainingFolder, outputFolderName)
await fs.mkdir(outputBasePath, { recursive: true })
console.log(`Copying all stems to "${outputBasePath}"`)
const outputPaths = {
Expand Down Expand Up @@ -455,10 +472,18 @@ module.exports.getOutputPath = () => {
return path.join(os.homedir(), 'Music', 'StemRoller')
}

module.exports.getLocalFileOutputToContainingDir = () => {
return electronStore.get('localFileOutputToContainingDir') || false
}

module.exports.setOutputPath = (outputPath) => {
electronStore.set('outputPath', outputPath)
}

module.exports.setLocalFileOutputToContainingDir = (value) => {
electronStore.set('localFileOutputToContainingDir', value)
}

module.exports.getOutputFormat = () => {
if (electronStore) {
const outputFormat = electronStore.get('outputFormat')
Expand Down
Loading