diff -pruN slimrat-0.9.2.orig/plugins/YouTube.pm slimrat-0.9.2/plugins/YouTube.pm --- slimrat-0.9.2.orig/plugins/YouTube.pm 2008-12-31 13:13:29.000000000 +0100 +++ slimrat-0.9.2/plugins/YouTube.pm 2008-12-31 13:23:34.000000000 +0100 @@ -5,8 +5,7 @@ package YouTube; use Term::ANSIColor qw(:constants); $Term::ANSIColor::AUTORESET = 1; -use LWP::UserAgent; -my $ua = LWP::UserAgent->new; +use LWP::Simple; #use WWW::Mechanize; #my $mech = WWW::Mechanize->new(agent => 'SlimRat' ); ############## @@ -15,16 +14,18 @@ my $ua = LWP::UserAgent->new; # -1: dead # 0: don't know sub check { - my $res = $ua->get(shift); - return 1 if ($res->is_success && $res->content()!~m#<div class="errorBox">#); + my $res = get($_); + return 1 if (defined $res && $res!~m#<div class="errorBox">#); return -1; } sub download { - my $paramChar = '[\w\d-_]'; - my ($v) = shift =~ m#\Wv=($paramChar+)#; - my ($t) = $ua->head("http://www.youtube.com/v/$v";)->{_previous}->header('location') =~ m#\Wt=($paramChar+)#; - return "http://www.youtube.com/get_video.php?video_id=$v&t=$t";; + my $content = get($_); + $content =~ /swfArgs.*"video_id"\s*:\s*"(.*?)".*"t"\s*:\s*"(.*?)".*/; + #$content =~ /"video_id"\s*:\s*"(.*?)"\s*,.*,\s*"t"\s*:\s*"(.*?)",/; + my $video_id = $1; + my $t = $2; + return "http://www.youtube.com/get_video?video_id=$video_id&t=$t";; } Plugin::register(__PACKAGE__,"^[^/]+//[^.]*\.?youtube\.com/watch[?]v=.+");