Inside Out

Download YouTube Videos : The Linux Way !

Posted by: arun on: January 29, 2007

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

    There are some sites like 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 flv file.

  2. Firefox Plugin
    There is a firefox extension which allows you to download YouTube videos as you watch them. I haven’t tried this.
  3. Command Line Tools
    This is the safest and best way (for CLI junkies :-D ). Download the script 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
    e.g : youtube-dl http://www.youtube.com/watch?v=D1R-jKKp3NA

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 :
    • Get ffmpeg for your system. SuSE users can get it here.
    • Convert the flv video to avi (or any other format) using ffmpeg :
      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 :-)

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 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 cmdl_opts.simulate:
284     cond_print(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 <youtube_file_link> <output_file_without_extension>"
echo "e.g : $0 http://www.youtube.com/watch?v=D1R-jKKp3NA steve_jobs"
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: , , , , , , , , ,

20 Responses to "Download YouTube Videos : The Linux Way !"

the firefox plugin, if used along with some download manager is quite hassle-free. two clicks, and you’re done.
Downloading videos is very, very useful if you want to watch a video, but can’t due to the slow buffering. downloads complete in max fifteen minutes, much faster than it’ll take to buffer it and watch it.

http://www.snatchvid.com/ try this site it works great!

I use http://www.savetube.com to save youtube videos

excellent!
Thank you!
And thanks especially to Ricardo Garcia Gonzalez for his script.

Rather than modifying the youtube-dl.py script, you can just use the ‘-g’ option:
-g, –get-url print final video URL only

I also find the title option to be useful:
-2, –title-too used with -g, print title too

(It may be that these are recent additions to the script :-)

A few recommendations for your bash script: it’s good to get in the habit of using the newer $(command) syntax for command substitution rather than the old `backtick` syntax. Here’s why:
http://wooledge.org/mywiki/BashFAQ/082

Also, the script seems to be displaying here with “smart quotes” rather than “standard double quotes”. If I was to copy/paste the script as it is, it would not work because of those smart quotes, and that’s the kinda thing that’s really tricky for a newbie to figure out.

On my system (debian etch, using codecs from debian-multimedia.org) mplayer can play the original flv files! no conversions needed – yay!

Cheers,
David

Thanks for the information. I will post an updated version of this script with the changes :-)

Thanks for echoing this script here! It was precisely what I was looking for.

# off-topic:

I just wanted to point out that WordPress by default uses smartquotes — even within <code>blocks</code> — which means that a direct copy+paste of the code block above will fail out in bash. We used to be able to escape smart quotes by disabling certain filters, but that method is deprecated and no longer works (so if you Google it, make sure you limit the date to within the last 6mo).

I won’t spew URLs here, but if you Google “Trials and tribulations of using WordPress to display code syntax”, you’ll come across a post that might help.

I could directly copy/paste the code into VIM. Just make sure you’ve the paste mode enabled with “:set paste”.
Thanks for the pointer, but unfortunately wordpress.com doesn’t allow user plugins. Enjoy the script :-)

use Qttube..a linux GUI apps.

Hi,
you can download youtube videos on
http://www.downloadyoutubevids.com
Here you can also search, watch and download youtue videos.
All in One :-)

http://home.gna.org/clive/
clive is a video extraction tool for user-uploaded video hosts such as Youtube, Google Video, Dailymotion, Guba and Metacafe. It can be chained with 3rd party tools for subsequent video re-encoding and playing and playing.

If you run ubuntu:

sudo apt-get install clive

There’s also another way to download youtube videos, and videos from many other sites using the command line in linux. check this out.

R u lot 4 real,all u do is start download from youtube then press pause.Let the video download then when it has finished go to your temp folder the video will be there.With your web browser still open drag the file from temp 2 where ever u want to save file its that easy.But remember not to close the browser down till you have removed video from temp folder

Great Tutorial!

[...] a comment » I had posted long back about a bash wrapper over youtube-dl to fetch youtube videos using your own download [...]

[...] 4: Enjoy. Note that I did all of this on my Windows laptop, but naturally there is a Linux way. Also, I chose MPEG1 because it was the best quality of video and audio for me, but that might be [...]

There’s a simple script here that works with new YouTube updates:

http://blog.johnlawrence.net/2008/12/youtube-download-shell-script/

youtube-dl has moved! Please update your bookmarks!

The new website is located at http://bitbucket.org/rg3/youtube-dl/

Leave a Reply

Tweet tweet!

Visitor Stats

  • 449,986 Hitz

Disclaimer

All the opinions (text and images) expressed in this website are mine. They do not represent the opinion of any living/non-living individual/groups/institutions, I am associated with.

The comments belong to the ip-address they generate from.

Del.icio.us