Andrew's website

Where am I? / Computers and software / GNU/Linux howtos / Playing Youtube videos on GNU/Linux

Latest version of yplay script, updated 05/02/2008 for changes on Youtube.com pages.

This article was originally published in December 2006. I have slightly updated it to bring it up to date.

Of course there is now the option of using the Gnash player (the Free Software flash player), if you can get it to compile and install which doesn't seem possible at the moment on gNewSense.

December 20th 2007

Playing Youtube videos on GNU/Linux

It will come as quite a surprise to many people that it is possible to play Youtube.com videos on GNU/Linux. It is a testimony to Free Software developers that this is possible at all.

The Free Software programme ffmeg can play flv video files which are streamed by Youtube using proprietary Adobe Flash software. I got his information from a comment by Alan Pope ( popey ) on the Freenode #gnewsense IRC channel. It set me to wondering how this could be utilised on gNewSense.

I've ended up putting together a BASH script to download and play or save the flv video files. I've also put in an option to convert the video to Theora which is a much more friendly format.

This is a quite crude BASH script and I am certain that when more experienced scripters look at it they will see all sorts of ways to improve it. However, it does work, and I am personally using it when people direct me towards videos on Youtube.com.

Of course, I still mention to them that hosting videos on a website that depends upon proprietary formats is not really a good idea.

ytplay

This is now version 0.2-1 of this script.

Updated 05/02/2008 for changes on Youtube.com pages.

I updated the original script with some security features to prevent the possibility of a local attack using symlinks.

Matthew Flaschen then added a neat way to watch embedded Youtube videos and also amended the save routine to save output files relative to the directory the script was started in.

Installation.

These instructions apply to installing ytplay on gNewSense GNU/Linux, it should also broadly apply to other GNU/Linux distributions though you may have to use a different packaging system to install the necessary programmes.

There's not really much installation needed.

First, you need to make sure that you have the ffmeg and ffmpeg2theora packages installed:

sudo apt-get install ffmpeg ffmpeg2theora

Then all you need to do is to copy the file "ytplay" onto your computer and make it executable.

Personally, I copied the file into my /usr/local/bin directory, so that it can be invoked from any directory. Use the command:

sudo cp ytplay /usr/local/bin

then make it executable:

sudo chmod 755 /usr/local/bin/ytplay

Now you can use the ytplay command where ever you are in Terminal.

Usage

It is very simple to use this script.

To play a Youtube video, go to the page where the video is on Youtube.com and copy it's URL.

ytplay http://www.youtube.com/watch?code_from_youtube

to save the Youtube video to your desktop, use the following

ytplay http://www.youtube.com/watch?code_from_youtube -o file_type file_name

File type is either flv or theora. File name is what you would like to call the downloaded file. You do not need to add the .flv or .ogg extentions as these will be added automatically.

Unfortunately, the Youtube web pages may change their format at any time meaning that this script will have to be adapted.

Download

Download the ytplay script here.
designed with quanta plus Valid HTML 4.01 Strict Valid CSS!