Ubuntu / Linux news and application reviews.

A while back we wrote how to play YouTube videos without Flash with just one click. The second method (my favourite) used to work with any browser but the latest Flash 10.2 breaks it because the cached files are deleted from /tmp (but are still there). With the help of Reddit, I got it working again and with a minor tweak it works with any browser (I've only tested it with Firefox and Chromium).

What is this about really? Using this method to play YouTube videos, you still need Flash installed but all you have to do is start a video in the browser so it's downloaded in the cache but then you can click "pause" (but don't close the tab!), then click a button on your panel (or you can assign a keyboard shortcut or whatever) which will launch that video in VLC or Mplayer.


Here's a video I've recorded showing how this works (I'm using Flash 10.2 in the video):




Setting everything up


The below solution will work with both Adobe Flash 10.2 and older Adobe Flash!

1. Create a file in /usr/local/bin, let's call that file "yt":
sudo gedit /usr/local/bin/yt

2. In the file created at step 1, paste this:

#!/bin/bash

FLASH_TMP=`ls /tmp | grep Flash*`

if [[ $FLASH_TMP ]]; then 
     vlc /tmp/Flash*
else
     if [[ `ps x | awk '/libgcflashplayer.so\ /{print $1}'` ]]; then
          flashvids() { lsof -p `ps x | awk '/libgcflashplayer.so\ /{print $1}'` -n 2>/dev/null | perl -lne '@F = split(/ +/, $_, 9); print "/proc/$F[1]/fd/${\($F[3] =~ /(^\d+)/)[0]}" if $F[4] eq "REG" && $F[8] =~ /\(deleted\)$/'; }
     else
          flashvids() { lsof -p `ps x | awk '/libflashplayer.so\ /{print $1}'` -n 2>/dev/null | perl -lne '@F = split(/ +/, $_, 9); print "/proc/$F[1]/fd/${\($F[3] =~ /(^\d+)/)[0]}" if $F[4] eq "REG" && $F[8] =~ /\(deleted\)$/'; }
     fi

     vlc $(flashvids)
fi

If you want to use Mplayer instead of VLC, replace "vlc" on line 6 and 14 in the code above, with "mplayer". The above code is not the same as in the video I've posted above because I've added support for the old Adobe Flash Player (older then 10.2) too so the script should now work with any Flash version.


Then save the file.

3. Make the file executable:
sudo chmod +x /usr/local/bin/yt

4. Now let's create a launcher for it: right click a Gnome panel, select "Add to panel", add a custom launcher and under "Command", enter this:
/usr/local/bin/yt


That's it! Now when you open a youtube video page in your browser, click pause (don't close the video page!), then click the newly created launcher to play it in VLC or Mplayer.


If you're using Adobe Flash older then 10.2, see the initial post: 2 Ways Of Playing YouTube Videos Without Flash With Just One Click