Skip to content

Instantly share code, notes, and snippets.

@erickyun
Last active February 7, 2024 16:11
Show Gist options
  • Save erickyun/e1de5337793ec55c7fdf83a3ad5f6997 to your computer and use it in GitHub Desktop.
Save erickyun/e1de5337793ec55c7fdf83a3ad5f6997 to your computer and use it in GitHub Desktop.
Download only part of a youtube video
@setlocal
@echo off
set /p "URL=Enter URL here: "
set /p "START_TIME=Enter START_TIME here: "
set /p "END_TIME=Enter END_TIME here: "
set /p "END_FILENAME=Enter END_FILENAME here: "
set "VIDEO_URL= "
set "AUDIO_URL= "
FOR /F "usebackq delims=" %%i IN (`yt-dlp -g -f bv+ba -- "%URL%"`) do (
set "line=%%i"
call :part_seturls line
)
ffmpeg -ss "%START_TIME%" -i "%VIDEO_URL%" -to "%END_TIME%" -ss "%START_TIME%" -i "%AUDIO_URL%" -to "%END_TIME%" -map 0 -map 1 -c copy -shortest -y "Downloads\%END_FILENAME%"
ECHO.
ECHO Done!
PAUSE
EXIT
:part_seturls
call set "current_url=%%%~1%%"
if ["%VIDEO_URL:~0,1%"]==[" "] (
set "VIDEO_URL=%current_url%"
) else if ["%AUDIO_URL:~0,1%"]==[" "] (
set "AUDIO_URL=%current_url%"
)
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment