Play Youtube (and many other) Media Links from your Browser with One Click

Requirements

  • Install mpv on your computer.
  • Install youtube-dl on your computer. More about that later.
  • Install the Open With addon. It seems to be available only for Mozilla browsers, but I'm pretty sure something similar also exists for chromish browsers.

Setup

Make sure mpv is working with local files.
Regardless of this article, mpv is about the best media (video) player available for Linux.
It will automatically detect if youtube-dl is in your $PATH, and use it to play web URLs.

So now all you have to do is to add an entry to Open With settings to open a link with mpv. Additionally, make sure it appears in the Main context Menu (links).

Platform Independent

First let me say that youtube-dl can do much more than just download youtube videos! With the technique described in this article, I'm using it on a large number of video sites, soundcloud mixes, bandcamp playlists etc. etc.

It is also available for Windows and OS X, and since mpv is also available for Windows and OS X, this How-To is platform independent!

About youtube-dl

While it might be in some distros' repositories, it is better to install & update it manually, because most media sites' API changes are addressed and fixed near-immediately, much faster than any distro developer could react.

For some, it might be best to use the github repo, others might simply want to download the latest version. In both cases, the best way to add it to your $PATH is to make a symlink to the executable.

Supposing $HOME/bin is in your $PATH:

$ ln -s /path/to/youtube-dl-newest-version/youtube-dl ~/bin/

You only have to do this once.

If you are not using the github repo, you can regularly update the binary itself with youtube-dl -U. Do this any time you get errors with downloading something, then try again.
Disclaimer: I have not tried this method because I'm using the github repo.

PS

Any of the three tools described here are very useful by themselves.

Use youtube-dl to download videos and music for later use. You can tell it to download a specified quality, codec, create a folder structure based on metadata etc. etc.

Use Open With to open images or PDFs etc. in external applications.

Use mpv to play all sorts of stuff directly from the command line. You'll be surprised by its versatility - multiple media files are often detected automatically, so it plays them one after the other, to only mention one thing. DVDs' contents are usually interpreted correctly, so it starts playing the feature film immediately.