Search code examples
batch-fileyoutube-dl

batch file for making query to use with youtube-dl


I want to build a batch program to work with youtube-dl, and I want to ask some questions (choice command I think it should be) and depending on answers to build query which will be executed by main youtube-dl command.

Example:

echo Do you want to extract audio from this clip? (y/n)

echo Write subtitle file? (y/n)

And do this at the end:

youtube-dl -x --write-sub  some link

I hope I was clear, english is not my first language. Thanks


Solution

  • Try this:

    @echo off
    setlocal
    
    :Input
    set opt1=
    set opt2=
    set /p opt1=Do you want to extract audio from this clip (y/n) 
    if not defined opt1 goto :Invalid
    if .%opt1% EQU . goto :Invalid
    echo %opt1%|findstr /i /r /c:"y" /c:"n">nul||goto :Invalid
    set /p opt2=Write subtitle file (y/n) 
    if not defined opt2 goto :Invalid
    if .%opt1% EQU . goto :Invalid
    echo %opt2%|findstr /i /r /c:"y" /c:"n">nul||goto :Invalid
    if /i %opt1% EQU Y set opts=-x
    if /i %opt2% EQU Y set opts=%opts% --write-sub
    echo youtube-dl %opts% some link
    goto :eof
    
    :Invalid
    Echo You have entered an invalid option. Please enter only y or n
    goto :Input