Skip to content

build yt-dlp batch file from YouTube "Watch Later" playlist HTML

License

Notifications You must be signed in to change notification settings

atloo1/yt-dlp-batch-builder

Repository files navigation

yt-dlp-batch-builder

GitHub Actions Workflow Status Dynamic TOML Badge Dynamic TOML Badge GitHub License GitHub code size in bytes

Docker Checked with mypy Poetry pre-commit Renovate enabled Ruff

Download your YouTube "Watch later" playlist w/ only Docker as a prerequisite.

The yt-dlp-batch-builder container runs a Python parser of the HTML of your "Watch later" playlist. This is used over the API, which requires authentication in a browser, just creating an extra step. yt_dlp_batch.txt results, which is input for the yt-dlp container whose arguments are documented here. Here, 720p videos favoring open codecs & containers (AV1, VP9, Opus, WebM) truncated by SponsorBlock are downloaded. Intermediate files & containers are also cleaned up.

prerequisites

git clone https://github.com/atloo1/yt-dlp-batch-builder.git
cd yt-dlp-batch-builder/

Download your YouTube "Watch later" playlist. Defaults are assumed: C:\Users\$env:USERNAME\Downloads\"Watch later - YouTube.htm" for Windows & ~/Downloads/"Watch later - YouTube.html" for Unix.

run with Docker:

prerequisites

part 1

docker build . -t yt-dlp-batch-builder

part 2: Windows (PowerShell)

programmatic

Rename-Item -Path C:\Users\$env:USERNAME\Downloads\"Watch later - YouTube.htm" -NewName watch_later.html
docker run `
    -v C:\Users\$env:USERNAME\Downloads\watch_later.html:/app/watch_later.html `
    --name yt-dlp-batch-builder `
    yt-dlp-batch-builder `
    --input-filepath watch_later.html `
    --output-filepath yt_dlp_batch.txt
docker cp yt-dlp-batch-builder:/app/yt_dlp_batch.txt C:\Users\$env:USERNAME\Downloads
# optionally edit yt_dlp_batch.txt
docker run `
    -v C:\Users\$env:USERNAME\Downloads\yt_dlp_batch.txt:/downloads/yt_dlp_batch.txt `
    --name yt-dlp `
    jauderho/yt-dlp:latest `
    -a yt_dlp_batch.txt `
    -f "bv[height=720]+ba[acodec=opus][ext=webm]" `
    -o "%(title)s_%(channel)s.%(ext)s" `
    --embed-chapters `
    --embed-subs `
    --exec 'mv {} $(echo {} | tr "[:upper:]" "[:lower:]")' `
    --restrict-filenames `
    --sponsorblock-remove all
docker cp yt-dlp:/downloads/. C:\Users\$env:USERNAME\Videos\youtube
rm C:\Users\$env:USERNAME\Downloads\"Watch later - YouTube_files\" -Recurse
rm C:\Users\$env:USERNAME\Downloads\watch_later.html
rm C:\Users\$env:USERNAME\Downloads\yt_dlp_batch.txt
rm C:\Users\$env:USERNAME\Videos\youtube\yt_dlp_batch.txt

interactive

docker run `
    --name yt-dlp `
    --entrypoint /bin/sh `
    jauderho/yt-dlp:latest `
    -c "sleep infinity"
docker exec -it yt-dlp /bin/sh

part 2: Unix (Bash)

programmatic

mv ~/Downloads/"Watch later - YouTube.html" ~/Downloads/watch_later.html
docker run \
    -v ~/Downloads/watch_later.html:/app/watch_later.html \
    --name yt-dlp-batch-builder \
    yt-dlp-batch-builder \
    --input-filepath watch_later.html \
    --output-filepath yt_dlp_batch.txt
docker cp yt-dlp-batch-builder:/app/yt_dlp_batch.txt ~/Downloads/
# optionally edit yt_dlp_batch.txt
docker run \
    -v ~/Downloads/yt_dlp_batch.txt:/downloads/yt_dlp_batch.txt \
    --name yt-dlp \
    jauderho/yt-dlp:latest \
    -a yt_dlp_batch.txt \
    -f "bv[height=720]+ba[acodec=opus][ext=webm]" \
    -o "%(title)s_%(channel)s.%(ext)s" \
    --embed-chapters \
    --embed-subs \
    --exec 'mv {} $(echo {} | tr "[:upper:]" "[:lower:]")' \
    --restrict-filenames \
    --sponsorblock-remove all
docker cp yt-dlp:/downloads/. ~/Videos/youtube
rm ~/Downloads/watch_later.html
rm ~/Downloads/yt_dlp_batch.txt
rm ~/Videos/youtube/yt_dlp_batch.txt

interactive

docker run \
    --name yt-dlp \
    --entrypoint /bin/sh \
    jauderho/yt-dlp:latest \
    -c "sleep infinity"
docker exec -it yt-dlp /bin/sh

part 3

docker rm yt-dlp-batch-builder yt-dlp

use with Python interpreter:

prerequisites

run

poetry install --without dev
poetry run python -m yt_dlp_batch_builder.main --help

develop

prerequisites

1st time setup

pyenv install 3.9 --skip-existing   # or your choice
pyenv local 3.9   # or your choice
poetry install
poetry run pre-commit install

About

build yt-dlp batch file from YouTube "Watch Later" playlist HTML

Resources

License

Stars

Watchers

Forks