43 lines
2.1 KiB
Batchfile
43 lines
2.1 KiB
Batchfile
@echo off
|
|
REM Batch Script for downloading videos with yt-dlp from YouTube and other websites, accepting URL as input via command line.
|
|
|
|
REM Clear any previous download commands to avoid conflicts
|
|
setlocal ENABLEEXTENSIONS
|
|
set LC_ALL=C & SET _='' & setLOCAL ENGLISH
|
|
|
|
REM Accept a video URL as command-line argument (no prompt) and verify its presence
|
|
IF "%~1"=="" (
|
|
ECHO No input provided. Usage: scriptname "https://www.youtube.com/watch?v=VIDEO_ID" & GOTO EndScript
|
|
) ELSE (SET InputUrl=%~1 & ECHO %InputUrl%)
|
|
|
|
REM Define yt-dlp path and format for downloading videos up to 1080p in MKV container with the best audio quality
|
|
set "YT_DL_CMD=yt-dl.exe --format "bestvideo[height<=1080]&bestaudio[ext=mp3,quality=5][codec:bestaudio]"
|
|
|
|
REM Run yt-dlp to download videos and extract the output filename for ffmpeg use
|
|
FOR /F delims== %%A IN ('%YT_DL_CMD%') DO SET "YT_DL_COMMAND=%%A"
|
|
|
|
SET "OUTPUTFILE=downloaded_video.mkv"
|
|
|
|
REM Execute yt-dlp command and pipe the output to ffmpeg for conversion if necessary
|
|
call :DownloadAndConvert "%InputUrl%" "%OutputFile%"
|
|
GOTO EndScript
|
|
|
|
:DownloadAndConvert
|
|
set "VideoUrl=%~1"
|
|
set "OutputFile=%~2"
|
|
REM Inform about processing download...
|
|
echo Processing download of %VideoUrl%...
|
|
%YT_DL_COMMAND% -o "%OutputFile%" "%VideoUrl%" && (
|
|
REM Use ffmpeg to convert audio track if not already in AAC format and output MKV file
|
|
ffmpeg -i "%OutputFile%.mp3" -c:v copy -c:a aac "%OutputFile%.aac" && (
|
|
Echo Conversion to AAC complete. MKV video is ready with audio track in the same folder as MP3 file.
|
|
REM The final .mkv file will be located at "%OutputFile%".mkv
|
|
) || (
|
|
ECHO Failed to convert video, make sure ffmpeg is installed and available in PATH or provide full path for FFMPEG command here.
|
|
)
|
|
GOTO EndScript
|
|
|
|
:EndScript
|
|
REM Documentation of the script can be found below this line
|
|
REM Usage instructions are provided above as a comment when running the batch file from the command prompt.
|
|
REM Ensure yt-dlp and ffmpeg executables are accessible or provide full paths in variables YT_DL_CMD and FFMPEG_COMMAND respectively before execution. |