Jump to content

Windows batch file program for youtube-dl

So if you haven't heard of this program called "youtube-dl", it's a command line program that allows a user to download youtube videos and do many other things such as extracting the audio only, choosing a format etc. (More info here).

 

Currently I have to manually type in the commands to use it. Now what I want to do, is to create a Windows batch file to automate the process, using some user input and things. I've done programming in C and Java before, but I've never really done batch scripting before so this is new to me.

 

So specifically what I need is to first open a command prompt within the same directory as the youtube-dl.exe, and then issue a simple youtube-dl (built-in) command to check if youtube-dl is up to date. I've actually managed to do this already here:

START cmd.exe /k "cd D:\Personal\Tools & echo Checking for updates... & youtube-dl --update"

That produces this: https://imgur.com/a/5jYYp

 

Now heres where i'm stuck. I now need to create the rest of the program so a user can use the following commands; where they are prompted to enter the video url into the correct place in the youtube-dl commands below. 

 

youtube-dl -F [video url] (This returns a list of all possible video and audio formats on the screen)

youtube-dl -f bestaudio [video url] (This extracts the best audio quality from the youtube video)

youtube-dl f bestvideo [video url] (This extracts the best video quality from the youtube video)

 

I've been reading about this where you can use the set command much like the declaring a variable it seems. But i'm not sure if i should put it after the start command or after. The ordering is another thing thats confusing me.

 

To summrise what i want, is the code i've already done to open a command prompt in the correct directory as to allow youtube-dl to work, and then intereact with the user to add a url within the 3 commands i put earlier.

 

I hope i've been clear enough, if anyone could help me i'd appreciate it.

 

This may also help as to what i want:

 

   
   
Link to comment
Share on other sites

Link to post
Share on other sites

@ECHO OFF
:top
SET /P URL=Please enter the video URL that you would like to use:


ECHO Available operations:

::This prints the list of the three operations

ECHO 1.List all possible formats
ECHO 2.bestaudio 
ECHO 3.bestvideo


::Ask the user to choose the operation they want

SET /P operation=Which operation would you like to do?:
if "%operation%"=="1" goto op1
if "%operation%"=="2" goto op2
if "%operation%"=="3" goto op3


:op1
ECHO List of all possible formats:
youtube-dl -F %URL%
pause
goto top

:op2
ECHO Downloading best audio...
youtube-dl -f bestaudio %URL%
goto top

:op3
ECHO Downloading best video...
youtube-dl -f bestvideo %URL%
goto top

 

This should do what you're asking for. 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 3 weeks later...
On 05/01/2017 at 6:43 PM, elpiop said:

@ECHO OFF
:top
SET /P URL=Please enter the video URL that you would like to use:


ECHO Available operations:

::This prints the list of the three operations

ECHO 1.List all possible formats
ECHO 2.bestaudio 
ECHO 3.bestvideo


::Ask the user to choose the operation they want

SET /P operation=Which operation would you like to do?:
if "%operation%"=="1" goto op1
if "%operation%"=="2" goto op2
if "%operation%"=="3" goto op3


:op1
ECHO List of all possible formats:
youtube-dl -F %URL%
pause
goto top

:op2
ECHO Downloading best audio...
youtube-dl -f bestaudio %URL%
goto top

:op3
ECHO Downloading best video...
youtube-dl -f bestvideo %URL%
goto top

 

This should do what you're asking for. 

Brillant! Thanks a lot. I know this reply is a bit late but I still appreciate it.

   
   
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×