Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Last active January 1, 2024 06:01
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CapsAdmin/c55ef9bd20f012ae2e79fa3e838fa0f1 to your computer and use it in GitHub Desktop.
Save CapsAdmin/c55ef9bd20f012ae2e79fa3e838fa0f1 to your computer and use it in GitHub Desktop.
This makes it possible to run spleeter without having to install pyton and pip on windows. See http://github.com/deezer/spleeter for more info on what spleeter is. Usage is `.\spleeter.cmd separate -p spleeter:5stems -o amen .\amenbrother.wav`
@echo off & PowerShell -nologo -noprofile -noninteractive Invoke-Expression ('$args=(''%*'').split('' '');'+'$PSScriptRoot=(''%~dp0'');$env:GOLUWA_CURRENT_DIRECTORY=(''%cd%'');'+((Get-Content -Raw '%~dp0%~n0%~x0' ) -Replace '^.*goto :EOF')); & goto :EOF
# ^^^^^
# this is some magic to execute the rest of this cmd as powershell
# so we can run it from explorer with double click or cmd easily
function Download($url, $location) {
Write-Host -NoNewline "'$url' >> '$location' ... "
(New-Object System.Net.WebClient).DownloadFile($url, "$location")
Write-Host "OK"
}
# download standalone python
if(!(Test-Path "./python.zip")) {
Download "https://www.python.org/ftp/python/3.7.5/python-3.7.5-embed-amd64.zip" "./python.zip"
}
# extract python
if(!(Test-Path "./python/python.exe")) {
Expand-Archive -LiteralPath "./python.zip" -DestinationPath "./python"
}
# download ffmpeg
if(!(Test-Path "./ffmpeg.zip")) {
Download "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2023-03-21-12-45/ffmpeg-N-110057-g1e406692e5-win64-gpl.zip" "./ffmpeg.zip"
if(!(Test-Path "./ffmpeg.zip")) {
print "unable to download ffmpeg.zip"
exit
}
}
# extract ffmpeg
if(!(Test-Path "./ffmpeg/bin/ffmpeg.exe")) {
Expand-Archive -LiteralPath "./ffmpeg.zip" -DestinationPath "./ffmpeg"
# the zip we download has a subfolder, so take that and move its content one level up
Get-ChildItem -Path ".\ffmpeg\*\" -Recurse | Move-Item -Destination ".\ffmpeg\"
if(!(Test-Path "./ffmpeg/bin/ffmpeg.exe")) {
print "cannot find ffmpeg.exe inside archive"
exit
}
}
# get pip for our standalone python
if(!(Test-Path "./python/Scripts/pip.exe")) {
cd python
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
./python.exe get-pip.py
cd ../
}
# remove python37._pth as it overrides PYTHONPATH (this was very confusing)
if(Test-Path "./python/python37._pth") {
Remove-Item python/python37._pth
}
# make ffprobe available, otherwise the ffmpeg-python library won't work properly
$env:Path+=";.\ffmpeg\bin\"
$env:PYTHONPATH="$(Get-Location)\python\Lib\site-packages\"
# download ffmpeg with pip
if(!(Test-Path "./python/Lib/site-packages/ffmpeg")) {
.\python\python.exe -m pip -v install ffmpeg-python
}
# finally download spleeter with pip
if(!(Test-Path "./python/Lib/site-packages/spleeter")) {
.\python\python.exe -m pip -v install spleeter
}
# pass all args form this cmd to python.exe with spleeter so we can run it as .\spleeter.cmd
.\python\python.exe -m spleeter $args
@vkharatmal
Copy link

Damn buddy!!! you are lifesaver!! I wasnt able to run it due to some errors but this works perfectly fine with just one command!Hats off buddy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment