Downloading YouTube Videos and Audio using youtube-dl
youtube-dl is a command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+, and it is not platform specific. It should work on your Unix box, on Windows or on macOS. It is released to the public domain, which means you can modify it, redistribute it or use it however you like.
Introduction
At one point going to sketchy Youtube downloader websites just became too much with all the ADs and overall suspicious pop ups you would get while trying to either download an mp3 or mp4 from YouTube.
Gone are these days though, while this tool in particular has been around for awhile it has it’s perks.
- One, you no longer have to use sketchy websites.
- Two, you can look like a hacker man running the basic syntax to download YouTube videos.
So now the question you’re probably asking is; How do I use it?
Easy, if you are like me and just want to have a copy and paste-able way to do either YouTube MP3’s or MP4’s I have two commands which can assist with that.
This assumes you have already installed youtube-dl from the command line on your computer and installed all dependencies. For documentation on installation go here: https://github.com/ytdl-org/youtube-dl#installation
Downloading YouTube MP4
So maybe you are a data hoarder and want to save a video from YouTube before it gets taken down OR you have a favorite music video you’d like to have a personal copy of. I got you, here is the basic syntax to run to download an MP4.
In the terminal you would run the following syntax.
1
youtube-dl --format mp4 <insert YouTube link here>
An example of how this looks is the following screenshot of this running:
Downloading a full defcon 31 conference talk
Downloading YouTube MP3
This can come in handy if you have a song that may not be found else where and can be only found on YouTube and you desperately need to download it for safe keeping. Totally understandable by the way.
You would run this command:
1
youtube-dl -x --audio-format mp3 --prefer-ffmpeg <insert YouTube link here>
Example of this running for a looped intro of The Weeknd - Is There Someone Else:
Downloading a Is There Someone Else Looped Intro
Issues
One of the issues I’ve had recently with using this tool is when pasting my YouTube link into the end of the command, the link inserts with a couple of back slashes:
Pasted link formats link with additional back slashes upon paste
The following syntax is incorrect and is only shown here for demonstration.
1
youtube-dl --format mp4 "https://www.youtube.com/watch\?v\=G0JKdFjWkLA\&list\=RDlbbDOdDYXWg\&index\=2"
Due to this, the command may not run correctly. To fix this, you would simply remove any of the \
in the youtube link and try again. It would then look like this:
1
youtube-dl --format mp4 "https://www.youtube.com/watch?v=G0JKdFjWkLA&list=RDlbbDOdDYXWg&index=2"
By removing all \
from the link, the video OR audio will be able to download just fine. :)
Conclusion
While I am sure there are plenty of ways to craft you syntax to work for certain use cases. This guide should be for those who just want to get started with basic downloads of MP3 and MP4s.
Thank you for reading and perhaps following along. See you in the next one!
GitHub Repo and Installation Guides
youtube-dl GitHub Repo: https://github.com/ytdl-org/youtube-dl#installation
Install youtube-dl on Windows: https://www.youtube.com/watch?v=XebaoWchKxI
Install youtube-dl on MacOS: https://techwiser.com/how-to-install-youtube-dl-on-mac/