another youtube-dl post

In my last post, I showed you how to download youtube-dl in linux. The way I showed in that article wrote it to a folder owned by root, and you’d need su or sudo to update it each time.

Now I’ll show you how I typically install youtube-dl, in my own home folder.

I do this for a couple of reasons. The main reason is I don’t need sudo to update it anymore, which was kind of silly.

To download it to your own personal home folder instead of to a folder owned by root, execute the following command:

curl -L https://yt-dl.org/downloads/latest/youtube-dl -o ~/bin/youtube-dl && chmod a+rx ~/bin/youtube-dl

Now you can execute it by typing ~/bin/youtube-dl and update with ~/bin/youtube-dl -U

To prevent having to type the ~/bin/ before it each time, you could add the ~/bin folder to your path in your .bashrc.

youtube-dl

I spend a lot of my time on YouTube, looking up topic that interest me, or trying to learn how to do something, etc. Sometimes, I want to be able to have a copy of the video to watch offline. That’s where youtube-dl comes in.

To install youtube-dl on Linux, you would simply run the following command:

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl && sudo chmod a+rx /usr/local/bin/youtube-dl

Other download instructions can be found at https://ytdl-org.github.io/youtube-dl/download.html

Once you have youtube-dl, you can keep it up to date by running

sudo youtube-dl -U

youtube-dl is pretty powerful, and is also not only limited to youtube, it allows you to download videos from many websites in many formats. And if you also have ffmpeg installed, it can do conversions and join downloaded parts into containers.

I have an alias on my system to allow me to quickly download a 1080p video from youtube:

alias yt1080='youtube-dl -f "bestvideo[height<=1080]+bestaudio" --merge-output-format mkv --prefer-free-formats -i --output "%(title)s.%(ext)s" --write-sub --sub-lang EN --sub-format SRT --add-metadata ' 

Put this into a file in your home directory called .bash_aliases and then run

. ~/.bashrc

You should then be able to type yt1080 <VIDEO_ID> in your terminal to download any video on YouTube.

For instance:

yt1080 https://www.youtube.com/watch?v=dQw4w9WgXcQ

You will now have a locally-downloaded copy of the YouTube video to do with as you wish. This is very handy for archiving YouTube channels, or for being able to watch your favorite tutorial vids offline.