Archive

Archive for May, 2019

download a YouTube playlist for offline view and keep the videos numbered

Problem
You want to download a YouTube playlist. youtube-dl can do that, fine. However, if the playlist contains the videos in chronological order, then you may want to watch them offline in the same order too. On YouTube, the videos are ordered and they are also numbered, but if you download them with youtube-dl, you lose the numbers and you lose the original order.

Solution
Good news: youtube-dl has a command-line option for this. When downloading a playlist, I use the following Bash script:

#!/usr/bin/env bash

URL="https://www.youtube.com/playlist?list=<playlist_id_here>"

youtube-dl -o "%(playlist_index)s - %(title)s.%(ext)s" \
           --ignore-errors \
           --download-archive downloaded.txt \
           -f 22 \
           "$URL"

It’ll download the videos in .mp4 format (that’s format 22).

Categories: bash Tags: ,