I end up rewatching some YouTube videos fairly often it seems. If I am researching something and want to use it for instructions, or looking at a new trail, I find myself looking at a video at least a few times. But the ads on YouTube have gotten so annoying that I wanted a way around them, and I also thought it’d be nice to have a local copy of some of these in case they every get pulled for some reason. Enter YouTube-Dl.
Youtube-DL is a free command line utility to download videos from YouTube featuring a CRAPTON of flexibility and options. Seriously an overwhelming staggering amount. When I was getting started I found this page useful as it provided additional examples of some commands.
Here are a few commands I found particularly useful. By default YouTube-Dl will pull the highest quality audo and video streams, which is usually fine. However sometimes this will result in a separate audio download and a separate video download that you then have to mux together with something like ffmpeg. I didnt want to fuss with that. So instead you can run
youtube-dl -F https://www.youtube.com/example that will show you something like this:
This shows you all of the available video formats and audio streams. Notice that #299 for example is a 1920×1080 video only file. It would have a separate audio stream you’d have to combine later. I dont want to do this so I usually go with format #22 if available.
If you do want the best available quality and you do want to merge to some other format you can try something like:
youtube-dl -f bestvideo+bestaudio https://www.youtube.com/example
You can also play around with the -o Output Template parameter to get titles, file locations, dates, etc all programmatically assigned. Check out the documentation here.
For me the command I use tends to be something like this:
youtube-dl -o '/home/username/Downloads/Videos/%(title)s.%(ext)s' --write-description --write-annotations --write-thumbnail -f 22 https://www.youtube.com/example
Now once I have the videos I want to make them available for me in Plex. To do so I add a new library of “Other Videos”.
The final results with the metadata, thumbnail, and video added to your library looks something like this:
Some other random notes on this:
- Every once in a while the thumbnail will be a dot wbem or something like that. Just change it to a jpg.
- You can also output to mp4, aav, and a few other video formats I believe. Check the documentation.
- The program also has the ability to download whole playlists if you’d like, really handy for some of the longer online instructional videos out there.