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
- 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.
- Firefox Plugin
There is a firefox extension which allows you to download YouTube videos as you watch them. I haven’t tried this. - Command Line Tools
This is the safest and best way (for CLI junkies
). Download the script YouTube-dl (thanks to Ricardo Garcia Gonzalez for this nice script). Just put that script in your ~/bin or /usr/bindirectories 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
- Use VLC Player or MPlayer or Kaffeine to play the flash video.
- 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
) 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: youtube, google, linux, axel, download, videos, shell, cli, command line,










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.
wanderlust
February 25, 2007 at 11:50 am
http://www.snatchvid.com/ try this site it works great!
bbb
March 5, 2007 at 11:37 am
[...] [Trovato qui] [...]
Voglia di Linux » Blog Archive » Scaricare video di Youtube
April 9, 2007 at 3:18 am
[...] hier [...]
Computerstammtisch » Blog Archive » Runterladen von Youtube-Videos
April 9, 2007 at 2:38 pm
I use http://www.savetube.com to save youtube videos
marc
May 11, 2007 at 1:09 am
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
David Emerson
July 12, 2007 at 7:05 am
Thanks for the information. I will post an updated version of this script with the changes
arun
July 16, 2007 at 8:54 am
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.
tek1024
February 6, 2008 at 10:49 am
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
arun
February 6, 2008 at 9:58 pm
use Qttube..a linux GUI apps.
Fariz
March 20, 2008 at 5:10 pm
Hi,
you can download youtube videos on
http://www.downloadyoutubevids.com
Here you can also search, watch and download youtue videos.
All in One
Mr.Legend
March 31, 2008 at 2:32 am
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
deadly
May 20, 2008 at 6:56 am
There’s also another way to download youtube videos, and videos from many other sites using the command line in linux. check this out.
urbanvoodoo
August 28, 2008 at 7:12 pm
Forgot to insert the link. sorry.
urbanvoodoo
August 28, 2008 at 7:14 pm
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
jazz
September 19, 2008 at 1:40 am
Great Tutorial!
Flecha
November 4, 2008 at 11:12 pm
[...] a comment » I had posted long back about a bash wrapper over youtube-dl to fetch youtube videos using your own download [...]
Update Download youtube videos in linux « Inside Out
November 10, 2008 at 8:52 am
[...] 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 [...]
How I Save Videos from YouTube « technobody
December 17, 2008 at 12:46 pm
There’s a simple script here that works with new YouTube updates:
http://blog.johnlawrence.net/2008/12/youtube-download-shell-script/
Anne On
January 9, 2009 at 8:17 pm