Using wget to Download Youtube Videos

Today I am going to show you a neat way of downloading Youtube videos using wget. Most Linux distros will come with wget. If you don’t have it, check with your distro for instructions on how to install it. Windows users can get wget here.

First locate the url of the video you want to download.

Hmmm… Here is a good one:

http://youtube.com/watch?v=eBGIQ7ZuuiU

Then open up your terminal and type:

wget -O deleteMeLater.tmp http://www.youtube.com/watch?v=eBGIQ7ZuuiU

This command will quickly download the page’s html.

Since Youtube has other flash objects and related videos we need to find the one we want. Fortunately Youtube uses the same layout for all their videos.

cat deleteMeLater.tmp | grep fullscreenUrl

This gives me the url I need for the video:

var fullscreenUrl = '/watch_fullscreen?fs=1&BASE_YT_URL=http%3A%2F%2Fyoutube.com%2F&vq=None&video_id=eBGIQ7ZuuiU&l=210&sk=QHSGy-6-eiJ6h5qtrj1kR2OJanvL6tLlC&fmt_map=&t=OEgsToPDskIjlCX_1shTRBRDv2UQzVb-&hl=en&plid=AAROOIUyvpMFnjvzAAAAoARsYAg&tk=6J3d54cPnMJP7mUN2BtMkd2OmbgxTvB_GPcrV3ckGUbzd7KVMiH1kA%3D%3D&title=Rick Roll';

We are mostly interested in the video_id= portion of the URL. Finally, to download the video we can use:

wget -O rickroll.flv 'http://www.youtube.com/get_video?video_id=eBGIQ7ZuuiU&l=210&sk=QHSGy-6-eiJ6h5qtrj1kR2OJanvL6tLlC&fmt_map=&t=OEgsToPDskIjlCX_1shTRBRDv2UQzVb-&hl=en&plid=AAROOIUyvpMFnjvzAAAAoARsYAg&tk=6J3d54cPnMJP7mUN2BtMkd2OmbgxTvB_GPcrV3ckGUbzd7KVMiH1kA%3D%3D&title=Rick Roll'

You can change the file name rickroll.flv to anythingYouWant.flv. Wget will save the .flv (flash video) in the current directory.


Was this information useful?


6 Responses to "Using wget to Download Youtube Videos"
  1. [...] If you are using a Linux/FreeBSD machine you can use wget. [...]

  2. someone on August 10th, 2008

    You should script it up to automate the process.

  3. mp4? on November 14th, 2008

    What about getting the .mp4 version by using the original link plus “&fmt=18″ at the end?

    I tried this, but it still downloads the .flv version.

    Any tips on how to make this work???

  4. Mark Sanborn on November 14th, 2008

    I’m pretty sure Youtube only offers flash versions of their videos.

  5. keith on March 6th, 2009

    Why would you pipe cat into a grep?

    Try this:
    grep fullscreenUrl deleteMeLater.tmp

  6. Powerhouse Programs of Linux on April 29th, 2009

    [...] Use wget to Download Youtube Videos [...]