Watch Later, Offline.

Streamlining Offline Youtube Viewing with Youtube-DL and Python

I watch a lot of Youtube, and have since I joined the site in 2007.

If you’re usage habits are similar to mine, you have a couple dozen videos sitting in your “Watch Later” playlist waiting to be viewed. That’s great, because Youtube gives you a handy way to save the content you’re interested in, but don’t have time to watch when you see it.

What’s not so great is that if you want to consume this content offline, there aren’t many good options of doing so. In the past, there were desktop applications, such as TubeSock, that could download Youtube videos for offline viewing. However, these apps would often break, and now feel quite antiquated. The best of these services that still seams to work is Keepvid, but even this feels rather rough around the edges and you can only download 1 video at a time.

Enter Youtube-dl, an awesome Python command-line program / library that allows downloading video from a multitude of online content platforms. Personally, I really only watch videos on Youtube, but the rest of this article could easily apply to any of these services.

The great thing about Youtube-dl is its versatility. It can intelligently recognize and download playlists, extract audio from videos, recode videos using FFMPEG, and a variety of other handy functions. It’s primarily a CLI tool, but also works as a library, which allows for Python scripts to leverage it’s features.

Before I found Youtube-dl, if I wanted to download videos to watch while traveling, I’d have to manually copy and paste each link into something like TubeSock or Keepvid. However, using Youtube-dl I was able to write a python script to automatically sync my Watch Later playlist to a folder on my computer! Youtube-dl handles the Google login and allows me pull down the playlist (Watch Later is, inexplicably, always private).

The wonders of automation…

What’s better is that logging options in Youtube-dl allow me to see which infer which videos have been removed from the playlist, allowing me to delete stale video files to keep the sync folder from growing too large.

It’s probably a bit strange that I’m so excited about this, but this is such a perfect example of using an open-sourced library and Python scripting to solve an annoyance (albeit slight) that I’ve had for years.


Using Watch_Later_Sync.py:

1. If you don’t already have the youtube-dl python package installed, run:
sudo pip install youtube-dl 
2. Run:

python watch_later_sync.py
in the project directory. The script will prompt you for your Youtube login credentials (including 2-factor authentication code if you have this enabled) in order to access your private Watch Later Playlist.
3. The script will download videos into the current directory.
4. Running the script subsequent times will delete any videos not in the Watch Later Playlist while downloading new video that have been added since the last sync.

If you have any questions about how to use the script, feel free to make an issue on the Github repo. I hope you enjoy this tool as much as I have!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.