@echo off
setlocal

set "SCRIPT_DIR=%~dp0"
call "%SCRIPT_DIR%_loadpaths.cmd"
set "OUTDIR=%IPLAYER_DIR%"

if "%~1"=="" (
  echo Usage: gaudn BBC_URL_OR_PID
  exit /b 1
)

if not exist "%OUTDIR%" mkdir "%OUTDIR%"

get_iplayer --audio-only --pid-recursive --output "%OUTDIR%" "%~1"
if errorlevel 1 exit /b %ERRORLEVEL%

rem Uncomment the next line to tidy downloaded names and arrange Show\Series N folders automatically.
rem powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%iplayerfixer.ps1" -SourceDir "%OUTDIR%" -LibraryRoot "%OUTDIR%" -Move
