1- const os = require ( 'os' )
2- const fs = require ( 'fs/promises' )
3- const { createWriteStream } = require ( 'fs' )
4- const { pipeline } = require ( 'stream/promises' )
5- const path = require ( 'path' )
6- const childProcess = require ( 'child_process' )
7- const treeKill = require ( 'tree-kill' )
8- const sanitizeFilename = require ( 'sanitize-filename' )
9- const { app, BrowserWindow, powerSaveBlocker } = require ( 'electron' )
10- const { fetchYtStream } = require ( './fetchYtStream.cjs' )
1+ import os from 'os'
2+ import fs from 'fs/promises'
3+ import { createWriteStream } from 'fs'
4+ import { pipeline } from 'stream/promises'
5+ import path from 'path'
6+ import childProcess from 'child_process'
7+ import treeKill from 'tree-kill'
8+ import sanitizeFilename from 'sanitize-filename'
9+ import { app , BrowserWindow , powerSaveBlocker } from 'electron'
10+ import { fetchYtStream } from './fetchYtStream.js'
1111
1212let statusUpdateCallback = null ,
1313 donateUpdateCallback = null
@@ -19,9 +19,9 @@ let curProgressFtStemIdx = null
1919function getPathToThirdPartyApps ( ) {
2020 if ( process . env . NODE_ENV === 'dev' ) {
2121 if ( process . platform === 'win32' ) {
22- return path . resolve ( path . join ( __dirname , '..' , 'win-extra-files' , 'ThirdPartyApps' ) )
22+ return path . resolve ( path . join ( import . meta . dirname , '..' , 'win-extra-files' , 'ThirdPartyApps' ) )
2323 } else if ( process . platform === 'darwin' ) {
24- return path . resolve ( path . join ( __dirname , '..' , 'mac-extra-files' , 'ThirdPartyApps' ) )
24+ return path . resolve ( path . join ( import . meta . dirname , '..' , 'mac-extra-files' , 'ThirdPartyApps' ) )
2525 } else {
2626 return null
2727 }
@@ -37,7 +37,7 @@ function getPathToThirdPartyApps() {
3737function getPathToModels ( ) {
3838 if ( process . env . NODE_ENV === 'dev' ) {
3939 if ( process . platform === 'win32' || process . platform === 'darwin' ) {
40- return path . resolve ( path . join ( __dirname , '..' , 'anyos-extra-files' , 'Models' ) )
40+ return path . resolve ( path . join ( import . meta . dirname , '..' , 'anyos-extra-files' , 'Models' ) )
4141 } else {
4242 return null
4343 }
@@ -252,11 +252,11 @@ function getFfmpegCompressionArguments(filetype) {
252252}
253253
254254async function _processVideo ( video , tmpDir ) {
255- const demucsModelName = module . exports . getModelName ( )
256- const demucsStemsFiletype = module . exports . getOutputFormat ( )
255+ const demucsModelName = getModelName ( )
256+ const demucsStemsFiletype = getOutputFormat ( )
257257 const compressionArgs = getFfmpegCompressionArguments ( demucsStemsFiletype )
258- const needsPrefix = module . exports . getPrefixStemFilenameWithSongName ( )
259- const needsOriginal = module . exports . getPreserveOriginalAudio ( )
258+ const needsPrefix = getPrefixStemFilenameWithSongName ( )
259+ const needsOriginal = getPreserveOriginalAudio ( )
260260
261261 const beginTime = Date . now ( )
262262 console . log ( `BEGIN downloading/processing video "${ video . videoId } " - "${ video . title } "` )
@@ -295,7 +295,7 @@ async function _processVideo(video, tmpDir) {
295295 `Splitting video "${ video . videoId } "; ${ jobCount } jobs using model "${ demucsModelName } "...`
296296 )
297297 const demucsExeArgs = [ mediaPath , '-n' , demucsModelName , '-j' , jobCount ]
298- if ( module . exports . getPyTorchBackend ( ) === 'cpu' ) {
298+ if ( getPyTorchBackend ( ) === 'cpu' ) {
299299 console . log ( 'Running with "-d cpu" to force CPU instead of CUDA' )
300300 demucsExeArgs . push ( '-d' , 'cpu' )
301301 } else if ( process . platform === 'darwin' ) {
@@ -385,9 +385,9 @@ async function _processVideo(video, tmpDir) {
385385 updateProgressRaw ( video . videoId , 0.99 )
386386
387387 const outputBasePathContainingFolder =
388- video . mediaSource === 'local' && module . exports . getLocalFileOutputToContainingDir ( )
388+ video . mediaSource === 'local' && getLocalFileOutputToContainingDir ( )
389389 ? path . dirname ( mediaPath )
390- : module . exports . getOutputPath ( )
390+ : getOutputPath ( )
391391 const outputBasePath = path . join ( outputBasePathContainingFolder , outputFolderName )
392392 await fs . mkdir ( outputBasePath , { recursive : true } )
393393 console . log ( `Copying all stems to "${ outputBasePath } "` )
@@ -436,7 +436,7 @@ async function processVideo(video) {
436436 } catch ( err ) {
437437 console . trace ( err )
438438
439- const status = module . exports . getVideoStatus ( video . videoId )
439+ const status = getVideoStatus ( video . videoId )
440440 if ( status === null ) {
441441 console . log ( 'Task was canceled by user.' )
442442 } else {
@@ -456,7 +456,7 @@ async function processVideo(video) {
456456 }
457457
458458 // Will filter out the current (completed) video
459- module . exports . setItems ( curItems )
459+ setItems ( curItems )
460460
461461 if ( powerSaveBlockId !== null ) {
462462 try {
@@ -471,9 +471,9 @@ async function processVideo(video) {
471471 }
472472}
473473
474- module . exports . setItems = async ( items ) => {
474+ export const setItems = async ( items ) => {
475475 items = items . filter ( ( video ) => {
476- let status = module . exports . getVideoStatus ( video . videoId )
476+ let status = getVideoStatus ( video . videoId )
477477 if ( status === null ) {
478478 status = { step : 'queued' }
479479 setVideoStatusAndPath ( video . videoId , status , null )
@@ -552,12 +552,12 @@ function setVideoStatusAndPath(videoId, status, path) {
552552 } )
553553}
554554
555- module . exports . setElectronStore = ( store ) => {
555+ export const setElectronStore = ( store ) => {
556556 electronStore = store
557557 loadVideosDb ( )
558558}
559559
560- module . exports . getOutputPath = ( ) => {
560+ export const getOutputPath = ( ) => {
561561 if ( electronStore ) {
562562 const outputPath = electronStore . get ( 'outputPath' )
563563 if ( outputPath ) {
@@ -567,7 +567,7 @@ module.exports.getOutputPath = () => {
567567 return path . join ( os . homedir ( ) , 'Music' , 'StemRoller' )
568568}
569569
570- module . exports . getModelName = ( ) => {
570+ export const getModelName = ( ) => {
571571 if ( electronStore ) {
572572 const modelName = electronStore . get ( 'modelName' )
573573 if ( modelName ) {
@@ -577,39 +577,39 @@ module.exports.getModelName = () => {
577577 return 'htdemucs'
578578}
579579
580- module . exports . getLocalFileOutputToContainingDir = ( ) => {
580+ export const getLocalFileOutputToContainingDir = ( ) => {
581581 return electronStore . get ( 'localFileOutputToContainingDir' ) || false
582582}
583583
584- module . exports . getPrefixStemFilenameWithSongName = ( ) => {
584+ export const getPrefixStemFilenameWithSongName = ( ) => {
585585 return electronStore . get ( 'prefixStemFilenameWithSongName' ) || false
586586}
587587
588- module . exports . getPreserveOriginalAudio = ( ) => {
588+ export const getPreserveOriginalAudio = ( ) => {
589589 return electronStore . get ( 'preserveOriginalAudio' ) || false
590590}
591591
592- module . exports . setOutputPath = ( outputPath ) => {
592+ export const setOutputPath = ( outputPath ) => {
593593 electronStore . set ( 'outputPath' , outputPath )
594594}
595595
596- module . exports . setModelName = ( name ) => {
596+ export const setModelName = ( name ) => {
597597 electronStore . set ( 'modelName' , name )
598598}
599599
600- module . exports . setLocalFileOutputToContainingDir = ( value ) => {
600+ export const setLocalFileOutputToContainingDir = ( value ) => {
601601 electronStore . set ( 'localFileOutputToContainingDir' , value )
602602}
603603
604- module . exports . setPrefixStemFilenameWithSongName = ( value ) => {
604+ export const setPrefixStemFilenameWithSongName = ( value ) => {
605605 electronStore . set ( 'prefixStemFilenameWithSongName' , value )
606606}
607607
608- module . exports . setPreserveOriginalAudio = ( value ) => {
608+ export const setPreserveOriginalAudio = ( value ) => {
609609 electronStore . set ( 'preserveOriginalAudio' , value )
610610}
611611
612- module . exports . getOutputFormat = ( ) => {
612+ export const getOutputFormat = ( ) => {
613613 if ( electronStore ) {
614614 const outputFormat = electronStore . get ( 'outputFormat' )
615615 if ( outputFormat ) {
@@ -619,11 +619,11 @@ module.exports.getOutputFormat = () => {
619619 return 'wav'
620620}
621621
622- module . exports . setOutputFormat = ( outputFormat ) => {
622+ export const setOutputFormat = ( outputFormat ) => {
623623 electronStore . set ( 'outputFormat' , outputFormat )
624624}
625625
626- module . exports . getPyTorchBackend = ( ) => {
626+ export const getPyTorchBackend = ( ) => {
627627 if ( electronStore ) {
628628 const backend = electronStore . get ( 'pyTorchBackend' )
629629 if ( backend ) {
@@ -633,27 +633,27 @@ module.exports.getPyTorchBackend = () => {
633633 return 'auto'
634634}
635635
636- module . exports . setPyTorchBackend = ( backend ) => {
636+ export const setPyTorchBackend = ( backend ) => {
637637 electronStore . set ( 'pyTorchBackend' , backend )
638638}
639639
640- module . exports . getVideoStatus = ( videoId ) => {
640+ export const getVideoStatus = ( videoId ) => {
641641 if ( videoId in videosDb ) {
642642 return videosDb [ videoId ] . status
643643 } else {
644644 return null
645645 }
646646}
647647
648- module . exports . getVideoPath = ( videoId ) => {
648+ export const getVideoPath = ( videoId ) => {
649649 if ( videoId in videosDb ) {
650650 return videosDb [ videoId ] . path
651651 } else {
652652 return null
653653 }
654654}
655655
656- module . exports . deleteVideoStatusAndPath = ( videoId ) => {
656+ export const deleteVideoStatusAndPath = ( videoId ) => {
657657 if ( videoId in videosDb ) {
658658 const nulledEntry = videosDb [ videoId ]
659659 for ( const i in nulledEntry ) {
@@ -670,24 +670,24 @@ module.exports.deleteVideoStatusAndPath = (videoId) => {
670670 }
671671}
672672
673- module . exports . isBusy = ( ) => {
673+ export const isBusy = ( ) => {
674674 return (
675675 curItems . filter ( ( video ) => {
676- const status = module . exports . getVideoStatus ( video . videoId )
676+ const status = getVideoStatus ( video . videoId )
677677 return status . step === 'processing' || status . step === 'downloading'
678678 } ) . length > 0
679679 )
680680}
681681
682- module . exports . registerStatusUpdateCallback = ( callback ) => {
682+ export const registerStatusUpdateCallback = ( callback ) => {
683683 statusUpdateCallback = callback
684684}
685685
686- module . exports . registerDonateUpdateCallback = ( callback ) => {
686+ export const registerDonateUpdateCallback = ( callback ) => {
687687 donateUpdateCallback = callback
688688}
689689
690- module . exports . deleteTmpFolders = async ( ) => {
690+ export const deleteTmpFolders = async ( ) => {
691691 const tmpBasePath = os . tmpdir ( )
692692 const items = await fs . readdir ( tmpBasePath )
693693 for ( const itemName of items ) {
0 commit comments