Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/theme.php on line 623
Niklas blog » Blog Archive » Downloading YouTube movie clips to your local hard drive

Niklas blog

Just another WordPress weblog

Downloading YouTube movie clips to your local hard drive

August 10th, 2006 in Uncategorized

Deprecated: Function split() is deprecated in /home/therning/public_html/niklas/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 466

Deprecated: Function split() is deprecated in /home/therning/public_html/niklas/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 466

Deprecated: Function split() is deprecated in /home/therning/public_html/niklas/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 466

I tried to watch this YouTube clip the other day but found that my flash player had a hard time synching the audio and video. Very annoying! And as far as I can see YouTube doesn’t provide a download link to let me download the movie and play it directly from my hard drive. I really wanted to see this clip but couldn’t stand the audio lagging behind. I figured there must be a way to hack that flash thing they are using to play the movie. It turned out to be quite easy!

First I downloaded the flash animation embedded in the page. You’ll find the URL of the SWF file in the text field labelled Embed to the right of the movie or you could have a look at the page’s HTML code. Then I used wget to download this URL:

wget 'http://www.youtube.com/v/3CiW838wNiM'

Watching the output from wget one can see that this URL actually does a redirect to another URL:

Location: /p.swf?video_id=3CiW838wNiM&eurl=&iurl=http%3A//sjl-static5.sjl.youtube.com/vi/3CiW838wNiM/2.jpg
&t=OEgsToPDskJAsFn4X26z0PYTiD7rKU DG

After wget downloaded the p.swf file (this is a flash animation file) I used flare to decompile it and had a look at the ActionScript code. The code had a number of URL strings and after reading Macromedia’s docs on the NetStream class I knew I had found the URL I was looking for. Here’s how I downloaded the movie above which I wanted to watch:

wget 'http://www.youtube.com/get_video?video_id=3CiW838wNiM&t=OEgsToPDskKC-YjD-y9Yr3q63ZzBUd1A'

The t parameter comes from the redirect URL we got as a response to the first wget. This appears to be some kind of ticket or something and seems to change over time.

After executing this wget command I had an FLV movie file on my hard drive which I could watch using mplayer without any audio problems!

2 Responses to “Downloading YouTube movie clips to your local hard drive”

  • Magnus
    August 30th, 2006 at 13:48

    This Linux.com article mentions a tool called youtube-dl.

  • Alan
    August 24th, 2008 at 01:11

    Nice writing. You are on my RSS reader now so I can read more from you down the road.