Inside Out

Notes on seeking wisdom and crafting software

Download YouTube Videos : The Linux Way !

In this article I will outline a few methods to download YouTube Videos to your system and getting them to play in your favorite player. We will go in a step-wise way :

A. Getting the Video

1. Online Tools
</p>
There are some sites like [KeepVid.com](http://keepvid.com) which
allow users to input a YouTube link and they would give you the
download link. So get the download link from this site and download
the <span style="font-weight:bold;">flv</span> file.

<p>
</span>

2. Firefox Plugin

There is a firefox extensionwhich allows you to download YouTube videos as you watch them. I haven’t tried this. 3. Command Line Tools

</p>
This is the safest and best way (for CLI junkies :-D). Download the
script [YouTube-dl](http://bitbucket.org/rg3/youtube-dl/) (thanks to
Ricardo Garcia Gonzalez for this nice script). Just put that script
in your `~/bin or /usr/bin` directories or somewhere in the
application path.

To download the flv video do this :

`youtube-dl  `

<p>
e.g : youtube-dl http://www.youtube.com/watch?v=D1R-jKKp3NA</code>

B. Playing the video

1. Use VLC Player or MPlayer or Kaffeine to play the flash video. 2. If the above method doesn't work out (It din't in my case)..Then go the difficult way :
</p>
-   Get <span style="font-weight:bold;">ffmpeg</span> for your
    system. SuSE users can get it
    [here](http://packman.links2linux.de/package/ffmpeg).
-   Convert the <span style="font-weight:bold;">flv</span> video to
    <span style="font-weight:bold;">avi</span> (or any other format)
    using ffmpeg :
    </p>
    <p>
    `ffmpeg -i my_flash_video.flv the_avi_file.avi`
-   Now drag and drop the avi file into your favorite video player n
    watch the video :-)

</p>
<p>

Still unsatisfied ?! "Dude I'm a \*nix user. I can't sit and do all these steps to get a simple video playing !!" No probs. We will write a shell script to do all this work for you.

Note : I found the downloader in youtube-dl quite slow. So I tweaked it a bit(I don't know python :-D) to use an external downloader ([axel](http://wilmer.gaast.net/main.php/axel.html) rocks!). Open the file youtube-dl in your favorite editor and change the following lines :

282 # Abort here if in simulate mode

283 if cmdl_opts.simulate:

284     sys.exit()

to the following :

282 # Abort here if in simulate mode

283 if cmdlopts.simulate:

284     condprint(video_data.geturl())

285     sys.exit()

That will make the script output the downloadable video link to the standard output (when run in simulate mode). Now write the shell script :

#!/bin/bash

if [ $# -ne 2 ]

then

echo “Usage : $0 <youtubefilelink> <outputfilewithoutextension>“

echo “e.g : $0 http://www.youtube.com/watch?v=D1R-jKKp3NA stevejobs”

else

outputfile=“.avi”

todnload=youtube-dl -s $1 | tail -n 1 -

echo “Got the file..”$todnload

axel -n 100 $todnload -o $2”.flv” # wget -c $todnload -O $2”.flv” .if you don’t use axel

echo “Download Completed…“

ffmpeg -i $2”.flv” $2$outputfile  # get the avi file

fi

Done. Now paste that code into a file utube in your path. Then run utube as :

utube http://www.youtube.com/watch?v=D1R-jKKp3NA steve_jobs

This will give 2 files steve*jobs.flv and steve*jobs.avi ;)

Just drag the *.avi to kaffeine and enjoy the speech by Steve Jobs !

Technorati Tags: [youtube](http://technorati.com/tag/youtube), [google](http://technorati.com/tag/google), [linux](http://technorati.com/tag/linux), [axel](http://technorati.com/tag/axel), [download](http://technorati.com/tag/download), [videos](http://technorati.com/tag/videos), [shell](http://technorati.com/tag/shell), [cli](http://technorati.com/tag/cli), [command line](http://technorati.com/tag/command%20line), [](http://technorati.com/tag/)