--- clive-2.1.3/clive~ 2009-01-20 13:48:45.000000000 +0200 +++ clive-2.1.3/clive 2009-01-20 13:49:36.000000000 +0200 @@ -85,6 +85,7 @@ IsLastfm => qr|\Qlast.fm\E|i, IsLiveleak => qr|\Qliveleak.com\E|i, IsEvisor => qr|\Qevisor.tv\E|i, + IsDelfi => qr|\Q.delfi.\E|i, #IsMetacafe => qr|\Qmetacafe.com\E|i, ); @@ -333,6 +334,8 @@ ($xurl, $id) = handle_liveleak($response_ref, $response_fh); } elsif ( $url =~ /$re_hosts{IsEvisor}/ ) { ($xurl, $id) = handle_evisor($response_ref); + } elsif ( $url =~ /$re_hosts{IsDelfi}/ ) { + ($xurl, $id) = handle_delfi($response_ref, $response_fh); } # elsif ( $url =~ /$re_hosts{IsMetacafe}/ ) { # ($xurl, $id) = handle_metacafe($response_ref); @@ -712,6 +715,64 @@ return ($xurl, $id); } +sub handle_delfi { + my ($response_ref, $response_fh) = @_; + + my %re = ( + # videobox + # http://www.delfi.ee/news/paevauudised/paevavideo/article.php?id=15218215 + GrabVideoboxURL => qr|flv_url:\s*'(.*?)'|, + # videoproject embed + # http://www.delfi.ee/news/paevauudised/paevavideo/article.php?id=18759038 + GrabVideoSalt => qr|_delfiVideoSalt\s*=\s*"([^"]+)";|, + GrabVideoSite => qr|src="(\S+://[^/]+)/js/embed.js"|, + # videoproject + # http://video.delfi.ee/video/CzurzqNz/ + GrabVideoURL => qr|\.addVariable\('file',\s*'([^']+)'|, + ); + + my ($xurl, $id); + my $videobox_url = $1 if $$response_ref =~ /$re{GrabVideoboxURL}/; + my $video_salt = $1 if $$response_ref =~ /$re{GrabVideoSalt}/; + my $video_site = $1 if $$response_ref =~ /$re{GrabVideoSite}/; + my $video_url = $1 if $$response_ref =~ /$re{GrabVideoURL}/; + + if ($videobox_url) { + $id = $1 if $videobox_url =~ m{/([^/]+)\.flv$}; + $xurl = $videobox_url; + + } elsif ($video_url) { + $xurl = uri_unescape($video_url); + $id = $1 if $xurl =~ m{^\S+://[^/]+/v/(.+?)\.flv}; + + } elsif ($video_salt and $video_site) { + my $url = $video_site . '/video/' . $video_salt . '/'; + print "done.\nfetch page ..." unless $opts{quiet}; + + my $page = ""; + open my $fh, ">", \$page; + + # Disable: header + $curl->setopt(CURLOPT_HEADER, 0); + $curl->setopt(CURLOPT_URL, $url); + $curl->setopt(CURLOPT_WRITEDATA, $fh); + + my $rc = $curl->perform; + close $fh; + + if ($rc == 0) { + # recurse + ($xurl, $id) = handle_delfi(\$page); + } else { + print STDERR "\nerror: " . $curl->strerror($rc) . " (http/$rc)\n"; + } + } else { + print STDERR "error: url not found\n"; + } + + return ($xurl, $id); +} + # Subroutines: Progress # NOTE: the 'dot' progress copies much from wget.