Skip to content

Instantly share code, notes, and snippets.

@airicbear
Last active July 15, 2019 01:55
Show Gist options
  • Save airicbear/529633d180203619d8f89f52e3116eac to your computer and use it in GitHub Desktop.
Save airicbear/529633d180203619d8f89f52e3116eac to your computer and use it in GitHub Desktop.
Downloading YouTube Playlists As Audio

How to download a playlist/song from YouTube

Installation

http://ytdl-org.github.io/youtube-dl/download.html

sudo apt install ffmpeg
sudo apt install id3v2 # For tagging

Note

You may need to attempt the download several times if you are encountering a 403 error.

Download

ogg

youtube-dl --extract-audio --audio-format vorbis -o "%(title)s.%(ext)s" <url>

mp3

youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" <url>

Tagging

id3v2 -a <artist> *
id3v2 -A <album> *
id3v2 -g <genre>
id3v2 -t <title>
id3v2 -T <track-num> <file>
id3v2 -y <year> *

Setting id3 titles to the filename

ogg

for F in *.ogg; do
    id3v2 -t "${F%.*}" "${F}"
done

mp3

for F in *.mp3; do
    id3v2 -t "${F%.*}" "${F}"
done

Converting mp3 files to ogg vorbis

From album

for F in *.mp3; do
    ffmpeg -i "${F}" "${F%.*}.ogg"
done

From artist

for D in *; do
    if [ -d "$D" ]; then
        cd "./$D"
        for F in *.mp3; do
            ffmpeg -i "${F}" "${F%.*}.ogg"
        done
        cd ..
    fi
done

Why do this?

Because apparently the .ogg format are open source and smaller in size compared to the patented .mp3 format.

Downloading Videos

Finding your format

youtube-dl -F <url>

What I Use

youtube-dl -f 248+bestaudio -o "%(title)s.%(ext)s" <url>

Note

If your format does not have audio, you will need to provide the audio format by appending +bestaudio or whatever other format you want e.g. +mp3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment