22 Dec 2010

Download youtube videos - Perl

Perl one-liner to download youtube videos

perl -MWWW::Mechanize -e '$m = WWW::Mechanize->new; $_=shift; ($i) = /v=(.+)/; s/%(..)/chr(hex($1))/ge for (($u) = $m->get($_)->content =~ /l_map": .+(?:%2C)?5%7C(.+?)"/); $m->get($u, ":content_file" => "$i.flv")'

Use it as following:

$ perl ... http://www.youtube.com/watch?v=ID

It will save the video to a file named "ID.flv".

It was written by Peteris Krumins (peter@catonmat.net).
His blog is at http://www.catonmat.net -- good coders code, great reuse.

No comments:

Post a Comment