Download & Watch YouTube Videos On Your Computer

Here’s mytube, a script that downloads the YouTube videos you specify in a config file.

  • Downloading the videos specified in the config file (on the left). Once the videos have been downloaded, the script detects this and does not attempt to download the videos again.

All code can be found on my GitHub.

https://github.com/zjrubin/mytube


Background

I’ve been using YouTube for many years. On occasion, there’s a video that I’ve watched in the past that I want to rewatch. However, I’m sometimes unable to find these videos on YouTube again. These videos could have titles that are not easily searchable, they may have been made private or removed by the creator, or perhaps YouTube itself took down these videos for copyright or other reasons. I wrote this script so that when I find a YouTube video that I will likely want to watch again in the future, I can just download the video locally and maintain a record of it in a configuration file.

The Config File

The config file – mytube_config.yml – is included in the repository. There are currently two types of entries that the config file can parse: video entries and collection entries.

  • A video entry consists of the video URL, the directory it should be downloaded to, and optionally a name for the downloaded video file. If a name isn’t specified, the name of the video on YouTube is used.

A video entry

  • A collection entry consists of a list of video URLs (and optional video names) and one common directory where all the videos in the list should be downloaded to.

A collection entry

You can specify a combination of video and collection entries within the config file. You can also leave comments in the config file if you begin your comment with a # character.

The default example entries in mytube_config.yml

Setup

The repository includes the file README.md that has information on how to setup and run the script. Please refer to this README for the most up-to-date information on how to setup and run this script.

README.md

Script Behavior

When you run the script, it will parse all the entries in the config file. One entry at a time, it will check if the video has already been downloaded to specified directory. If the video file exists locally, the script will not attempt to download it again and will move on to the next entry. If the video file does not exist locally, the script will download the video at the specified URL. The script is currently set to download the highest resolution .mp4 version of the video available on YouTube.

  • Since all the videos have been downloaded, the script does not attempt to download them again. You can see one of the videos that was downloaded as I play the beginning of it here.