Skip to content

Instantly share code, notes, and snippets.

@milnak
Created August 26, 2022 16:15
Show Gist options
  • Save milnak/deaf6c02ef0a867b8547d8a172a13c23 to your computer and use it in GitHub Desktop.
Save milnak/deaf6c02ef0a867b8547d8a172a13c23 to your computer and use it in GitHub Desktop.
Download playlists or channels from youtube using yt-dlp
@echo off
setlocal
REM Set codepage to UTF-8
chcp 65001 > NUL
echo.
REM Hidden ESC character on next line.
set ESC=
GOTO :MAIN
:DOWNLOAD
set URL=%~1
set TITLE=
for /f "delims=" %%f in ('yt-dlp.exe --playlist-start 1 --playlist-end 1 --print "%%(channel)s/%%(playlist_title)s" "%URL%"') do set TITLE=%%f
REM CMD will barf if a string has an ampersand, so remove that.
set TITLE=%TITLE:&=_%
@REM set TITLE=%TITLE:\=_%
@REM set TITLE=%TITLE:<=_%
@REM set TITLE=%TITLE:>=_%
@REM set TITLE=%TITLE:?=_%
@REM set TITLE=%TITLE:/=_%
@REM set TITLE=%TITLE:"=_%
@REM set TITLE=%TITLE::=_%
@REM set TITLE=%TITLE:|=_%
echo.
echo Playlist: %ESC%[1;33m%TITLE%%ESC%[0m
echo.
yt-dlp.exe --output "%%(channel)s/%%(playlist_title)s/%%(title)s [%%(id)s].%%(ext)s" --no-simulate --print "[%%(playlist_index)d/%%(n_entries+1-)d] %%(title)s" "%URL%"
echo URL: %URL%
GOTO :EOF
:MAIN
REM del /s *.part
REM del /s *.ytdl
call :DOWNLOAD "https://www.youtube.com/channel/UC2TJVZB2ZG0HzJ1tqXpiWfw/videos"
call :DOWNLOAD "https://www.youtube.com/playlist?list=PL_fIcqBeKtp-eYcAkFWs5SZsyyGz9svmF"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment