An alternative way to play YouTube videos without using Flash
Published on 2012-12-15. Modified on 2016-07-26.
This tutorial was written when it was only possible to view videos on YouTube via Flash, however the tutorial is still useful if you need to download videos from YouTube, or some other video service, in an easily manner and watch them on your favorite video player.
One way to watch videos from YouTube without installing Flash is to download the video first and then watch them afterwards.
There exists several YouTube downloaders, but one really good open source program which is also in active development is youtube-dl. The source code is located at GitHub.
On Debian you can install youtube-dl with:
# apt install youtube-dl
After you have installed it you need to update it to contain the latest Youtube signatures:
# youtube-dl --update
youtube-dl can download videos from Youtube into a variety of video formats. You just need to make sure that your favorite video player supports the format you choose.
Besides downloading videos from Youtube youtube-dl can also download videos from a lot of other places. Take a look using the command:
$ youtube-dl --list-extractors
In order to determine the available video formats for a specific video you want to download, simple supply the URL of the video in double-quotes. In this example we will look at the available video formats for downloading the new Superman trailer (Man of Steel) located on Youtube at: https://www.youtube.com/watch?v=KVu3gS7iJu4
$ youtube-dl --list-formats "http://www.youtube.com/watch?v=KVu3gS7iJu4" [youtube] Setting language [youtube] KVu3gS7iJu4: Downloading video web page [youtube] KVu3gS7iJu4: Downloading video info web page [youtube] KVu3gS7iJu4: Extracting video information Available formats: 37 : mp4 [1080x1920] 22 : mp4 [720x1280] 35 : flv [480x854] 34 : flv [360x640] 18 : mp4 [360x640] 43 : webm [360x640] 5 : flv [240x400] 17 : mp [brimful]
So as we can see we have a variety of formats to choose from. Often the format itself is a proprietary video format, but some open source video players can display proprietary video formats using an open source alternative. mpv is one of the best open source media players.
Another really good one is VLC. VLC uses the library called Libav Libav is a friendly and community-driven effort to provide its users with a set of portable, functional and high-performance libraries for dealing with multimedia formats of all sorts.
If you want to download the above trailer in MP4 720X1280 you need to use the following command:
$ youtube-dl -f 22 "http://www.youtube.com/watch?v=KVu3gS7iJu4"
-f option specifies what format you want to download the video in. Use the command to see a list of other options available:
$ man youtube-dl
The downloaded video will be saved with the query string as the name of the video plus the extension. So this video gets saved as "KVu3gS7iJu4.mp4"
Now, you can watch the video using mpv or VLC or something else.
$ mpv KVu3gS7iJu4.mp4
Another really great feature of youtube-dl is that is it capable of downloading complete playlists and it can then automatically add numbers and the correct titles to the downloaded filenames.
If you have a playlist you can download every file automatically and add numbers and titles like this:
$ youtube-dl -t -A "http://www.youtube.com/playlist?list=foo"
-t option makes youtube-dl use the title of the video in the filename. The
-A option makes youtube-dl add numbers starting from 00000.
I hope this tutorial helps you in the steps to avoid proprietary software all together!