Search code examples
batch-fileffmpegyoutube-dl

Youtube-dl cannot read various set on batch script


I created an batch-script that positioned with youtube-dl and ffmpeg. I set several set to put URL and Video/Audio ID. Here my script that I simplified

@echo off
cd /d %root%\YT
color 0a
title Youtube Downloader
setlocal enableDelayedExpansion
set q=^"
color 0a

:submenu
echo Please enter URL.
set /p f1="URL: " 
echo Checking ID...
youtube-dl -F %f1%
ping localhost -n 2 >nul
goto menu

:menu
echo.
echo Script created by UrbaseR
echo ___________________________________________________________
echo.
echo                          MENU
echo ___________________________________________________________
echo OS Windows - %ComputerName%
echo.
echo M E N U
echo Press 1 to Download Best version 
echo Press 2 to Download Custom version + convert
echo Press 3 to Exit

set /p you=">"
if %you%==1 goto 1
if %you%==2 goto 2
if %you%==3 goto 3

cls
echo *********************************
echo Sorry invalid number!
echo *********************************
ping localhost -n 2 >nul
goto menu

:1
echo Downloading...
youtube-dl -f best %f1%
echo.
echo Done
ping localhost -n 2 >nul
cls
goto submenu

:2
set /p id1="Insert Video ID: "
set /p id2="Insert Audio ID: "
echo Downloading Video..
youtube-dl -f %id1% -ciw -o "vid.%(ext)s" -v --write-sub %f1%
echo.
echo Video Done
ping localhost -n 2 >nul
echo Downloading Audio..
youtube-dl -f %id2% -ciw -o "aud.%(ext)s" -v %f1%
echo.
echo Audio Done
ping localhost -n 2 >nul
echo Converting Video
ffmpeg -i "vid.%(ext)s" -i "aud.%(ext)s" -c:v copy -c:a aac -strict experimental "input.mkv"
echo Converting Done
ping localhost -n 4 >nul
cls
goto submenu

:3
exit

First and third option execute successfully. Second option will appear the message like this:

Usage: youtube-dl [OPTIONS] URL [URL...] youtube-dl: error: You must provide at least one URL.

Type youtube-dl --help to see a list of all options.

Note: Since I stuck on first and second stage of youtube-dl, ffmpeg may not work (I have not tested it yet).

Can you help me?


Solution

  • After re-fix the script is pretty much done.

    @echo off
    cd /d %root%\YT
    color 0a
    title Youtube Downloader
    setlocal enableDelayedExpansion
    set q=^"
    color 0a
    
    :submenu
    echo Please enter URL.
    set /p f1="URL: " 
    cls
    echo Checking ID...
    youtube-dl -F %f1%
    ping localhost -n 2 >nul
    goto menu
    
    :menu
    echo.
    echo.
    echo Script created by UrbaseR
    echo ___________________________________________________________
    echo.
    echo                          MENU
    echo ___________________________________________________________
    echo OS Windows - %ComputerName%
    echo.
    echo M E N U
    echo Press 1 to Download Best version (default ver)
    echo Press 2 to Download Custom version + Convert
    echo Press 3 to Exit
    echo.
    echo URL: %f1%
    
    set /p you=">"
    if %you%==1 goto 1
    if %you%==2 goto 2
    if %you%==3 goto 3
    
    cls
    echo *********************************
    echo Sorry invalid number!
    echo *********************************
    ping localhost -n 2 >nul
    goto menu
    
    :1
    echo Downloading...
    youtube-dl -f best %f1%
    echo.
    echo Done
    ping localhost -n 2 >nul
    cls
    goto submenu
    
    :2
    set /p id1="Insert Video ID: "
    set /p id2="Insert Audio ID: "
    set ida="v.data"
    set idb="a.data"
    set "f2="
    set "f3="
    cls
    echo Downloading Video..
    youtube-dl -f %id1% -ciw --o %ida% -v --write-sub %f1%
    echo.
    echo Video Done
    ping localhost -n 2 >nul
    cls
    echo Downloading Audio..
    youtube-dl -f %id2% -ciw -o %idb% -v %f1%
    echo.
    echo Audio Done
    ping localhost -n 2 >nul
    cls
    echo Note Default title is: input.mkv
    echo.
    set /p f2="Enter Video Title: "
    if not defined f2 set "f2=input"
    set /p f3="Format Video: "
    if not defined f3 set "f3=mkv"
    echo Converting Video..
    ffmpeg -i %ida% -i %idb% -c:v copy -c:a aac -strict experimental "%f2%.%f3%"
    echo Converting Done
    del /q %ida%
    del /q %idb%
    ping localhost -n 4 >nul
    cls
    goto submenu
    
    :3
    exit
    

    Feel free to use the script.

    Note: Be sure to have youtube-dl.exe and ffmpeg.exe on same folder, video will also saved on same folder .