@echo off setlocal REM -- Strip trailing backslash from %~dp0 to avoid "Illegal characters in path" -- set "ROOT=%~dp0" if "%ROOT:~-1%"=="\" set "ROOT=%ROOT:~0,-1%" REM -- If a local ffmpeg folder exists inside the addon, prepend it to PATH -- REM This ensures the PS1 script's Find-Ffmpeg can discover it even if REM it isn't on the system PATH yet. if exist "%ROOT%\ffmpeg\ffmpeg.exe" ( set "PATH=%ROOT%\ffmpeg;%PATH%" ) REM -- Check for -UseWinRAR flag -- set "PS_ARGS=-NoProfile -ExecutionPolicy Bypass -File "%ROOT%\GeneratePlaylist.ps1" -RootPath "%ROOT%"" if "%1"=="-UseWinRAR" ( set "PS_ARGS=-NoProfile -ExecutionPolicy Bypass -File "%ROOT%\GeneratePlaylist.ps1" -RootPath "%ROOT%" -UseWinRAR" ) if "%1"=="-usewinrar" ( set "PS_ARGS=-NoProfile -ExecutionPolicy Bypass -File "%ROOT%\GeneratePlaylist.ps1" -RootPath "%ROOT%" -UseWinRAR" ) powershell %PS_ARGS% set "ERR=%ERRORLEVEL%" if not "%ERR%"=="0" ( echo. echo GeneratePlaylist failed with exit code %ERR%. echo. echo Trying fallback download method... echo. REM -- Fallback: Use bitsadmin or certutil to download ffmpeg if needed -- REM -- This provides at least some progress output when PowerShell fails -- set "FFMPEG_DIR=%ROOT%\ffmpeg" if not exist "%FFMPEG_DIR%\ffmpeg.exe" ( echo ffmpeg not found. Attempting fallback download... echo. set "DL_DIR=%ROOT%\ffmpeg_download" if not exist "%DL_DIR%" mkdir "%DL_DIR%" REM -- Try bitsadmin (available on most Windows systems) -- where bitsadmin >nul 2>nul if %ERRORLEVEL%==0 ( echo Using bitsadmin to download ffmpeg... echo This may take several minutes depending on your connection. echo. bitsadmin /transfer "ffmpeg_download" /priority normal "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip" "%DL_DIR%\ffmpeg.zip" if exist "%DL_DIR%\ffmpeg.zip" ( echo. echo Download complete. Extracting ffmpeg.zip with PowerShell... powershell -NoProfile -Command "Expand-Archive -LiteralPath '%DL_DIR%\ffmpeg.zip' -DestinationPath '%DL_DIR%\extracted' -Force; $bin = Get-ChildItem '%DL_DIR%\extracted' -Recurse -Directory -Filter 'bin' | Select-Object -First 1; if ($bin) { if (-not (Test-Path '%FFMPEG_DIR%')) { New-Item -ItemType Directory -Path '%FFMPEG_DIR%' -Force | Out-Null }; Copy-Item (Join-Path $bin.FullName 'ffmpeg.exe') '%FFMPEG_DIR%\' -Force -ErrorAction SilentlyContinue; Copy-Item (Join-Path $bin.FullName 'ffprobe.exe') '%FFMPEG_DIR%\' -Force -ErrorAction SilentlyContinue }; Remove-Item '%DL_DIR%\extracted' -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item '%DL_DIR%\ffmpeg.zip' -Force -ErrorAction SilentlyContinue" if exist "%FFMPEG_DIR%\ffmpeg.exe" ( echo ffmpeg installed successfully via fallback. ) else ( echo WARNING: Fallback extraction may not have completed successfully. ) ) else ( echo bitsadmin download failed. ) ) else ( echo bitsadmin not available on this system. echo. echo Please install ffmpeg manually: echo 1. Download from https://www.gyan.dev/ffmpeg/builds/ echo 2. Extract ffmpeg.exe and ffprobe.exe echo 3. Place them in: %FFMPEG_DIR% ) ) echo. echo Trying to generate playlist without PowerShell... echo. REM -- Minimal fallback: just scan Media folder and write AutoPlaylist.lua -- REM -- This works without ffmpeg but uses estimated durations -- if exist "%ROOT%\Media" ( echo Scanning Media folder for audio files... set "OUTFILE=%ROOT%\AutoPlaylist.lua" echo RelationshipsJukeboxAutoPlaylist = {} > "%OUTFILE%" echo RelationshipsJukeboxAutoPlaylist.tracks = { >> "%OUTFILE%" for /r "%ROOT%\Media" %%F in (*.mp3 *.wav *.ogg) do ( setlocal enabledelayedexpansion REM Get the full path of the file set "FULLFILE=%%F" REM Strip the ROOT prefix to get a relative path like \Media\song.mp3 set "RELPATH=!FULLFILE:%ROOT%=!" REM Build the WoW-relative path: Interface\AddOns\RelationshipsJukeBox\Media\song.mp3 REM RELPATH starts with \ (from the remaining path after stripping ROOT) set "FULLPATH=Interface\AddOns\RelationshipsJukeBox!RELPATH!" REM Double all backslashes for Lua string escaping (\\ in source = \ in Lua value) set "FULLPATH=!FULLPATH:\=\\!" set "BASENAME=%%~nF" echo { path = "!FULLPATH!", name = "!BASENAME!", duration = 180 }, >> "%OUTFILE%" endlocal echo Found: %%~nF ) echo } >> "%OUTFILE%" echo. echo Playlist generated (using estimated 180s durations). echo Install ffmpeg for accurate durations and MP3 sanitization. ) else ( echo Media folder not found: %ROOT%\Media ) echo. echo Usage: GeneratePlaylist.bat [-UseWinRAR] echo -UseWinRAR Prefer WinRAR over 7-Zip for archive extraction pause exit /b %ERR% ) echo. echo Playlist entries now include names and durations for Play All / Shuffle. echo Autoplay and Shuffle work even without metadata - estimated durations are used. echo. echo Tip: Run with -UseWinRAR flag to use WinRAR for archive extraction: echo GeneratePlaylist.bat -UseWinRAR pause