You're viewing a comment by Trizen and its responses.

September 22, 2011, 20:45

Update code (the above code has been broken by Youtube changes)

#!/usr/bin/perl -w

#################### Coded by TRIZEN under the GPL. ####################
use strict;use LWP::UserAgent;use URI::Escape('uri_unescape');my $lwp=new
LWP::UserAgent;foreach $_(@ARGV){($_) = m[[=/]?([\w-]{11})] or next;my $c
=uri_unescape(my $t = $lwp->get("http://www.youtube.com/get_video_info?&"
."video_id=$_&el=detailpage&ps=default&eurl=&gl=US&hl=en")->content);do{#
$t=uri_unescape $1;$t=~tr[\+/][ ];print"** $t\n"}if$t=~/&title=([^&]+)/;#
$lwp->show_progress(1),$lwp->mirror(uri_unescape(($c=~/map=url=([^&]+)&/)
),"$t.mp4")unless -e "$t.mp4";$lwp->show_progress(0)}# Youtube Downloader

Comment Responses

September 25, 2011, 08:45

Awesome. Thanks for posting these!

September 26, 2011, 16:11

My pleasure. I came back with few shorter youtube-downloaders.

For Perl>=5.14.1
use LWP;use URI::Escape;$u=\&uri_unescape;for(@ARGV){($y,$_)=m[(.+m)/.+[=/]([\w-]{11})] or next;&$u(($l=new LWP::UserAgent)->
get("$y/get_video_info?&video_id=$_")->content)=~/ap=url=([^&]+).+&title=([^&]+)/;$l->mirror(&$u($1),&$u("$2.mp4"=~y#+/# #r))}

For all versions of Perl
use LWP;use URI::Escape;$u=\&uri_unescape;for(@ARGV){($y,$_)=m[(.+m)/.+[=/]([\w-]{11})] or next;&$u(($l=new LWP::UserAgent)->get(
"$y/get_video_info?&video_id=$_")->content)=~/ap=url=([^&]+).+&title=([^&]+)/;$l->mirror(&$u($1),do{$t=&$u($2);$t=~y#+/# #;"$t.mp4"})}

One-liner version:
perl -MLWP -MURI::Escape -e '$u=\&uri_unescape;for(@ARGV){($y,$_)=m[(.+m)/.+[=/]([\w-]{11})] or next;&$u(($l=new LWP::UserAgent)->get("$y/get_video_info?&video_id=$_")->content)=~/ap=url=([^&]+).+&title=([^&]+)/;$l->mirror(&$u($1),do{$t=&$u($2);$t=~y#+/# #;"$t.mp4"})}'

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type first 3 letters of your name: (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.