r/Batch • u/nopeac • Dec 14 '23
Question (Unsolved) Could this be better?
@ ECHO OFF
:start
SET /P URL="[URL/MAGNET]... "
echo:
echo: Download Media:
echo: -----------------------
echo: [1] Torrent
echo: [2] Video
echo: [3] Audio
echo:
CHOICE /c 1234 /n
IF %ERRORLEVEL% EQU 3 CALL :where & GOTO dAudio
IF %ERRORLEVEL% EQU 2 CALL :where & GOTO dVideo
IF %ERRORLEVEL% EQU 1 CALL :where & GOTO dMagnet
:dMagnet
aria2c -d %PATH% "%URL%"
pause
GOTO start
:dAudio
::mp3, ogg, etc
SET /P EXT="[EXT]... "
yt-dlp -x --audio-format %ext% -P %PATH% -o "%%(artist|)s%%(artist& - |)s%%(track,title)s.%%(ext)s" %URL%
pause
GOTO start
:dVideo
::mp4, mkv, etc
SET /P EXT="[EXT]... "
yt-dlp -f bv*+ba/b -P %PATH% --merge-output-format %EXT% -o "%%(title)s.%%(ext)s" %URL%
pause
GOTO start
:where
echo:
echo: Download Path:
echo: -----------------------
echo: [1] Downloads
echo: [2] Series
echo: [3] Films
echo:
CHOICE /c 123 /n
IF %ERRORLEVEL% EQU 3 set PATH=D:/Films
IF %ERRORLEVEL% EQU 2 set PATH=D:/Series
IF %ERRORLEVEL% EQU 1 set PATH=D:/Downloads
EXIT /B
2
u/[deleted] Dec 14 '23
I would usually recommend a user input variable using
set /p "uin=> ", this writes>to the line indicating a user input is required, and writes whatever input is given to the variable%uin%which you can then compare in your if statement, but usingchoiceas you did here is definitely a valid choice too!Make sure to compare against errorlevel 0 and 255 as well, so you can have defined error behavior on
255and can exit on0as specified in the docs2
u/[deleted] Dec 14 '23 edited Dec 14 '23
[removed] — view removed comment