root/trunk/plagger/assets/plugins/Filter-FindEnclosures/youtube.pl

Revision 2042 (checked in by mizzy, 12 years ago)

assets/plugins/Filter-FindEnclosures/youtube.pl: follow the changes of html.Thanks for yusukebe.

Line 
1 # author: mizzy
2 use Plagger::Util qw( decode_content );
3
4 sub handle {
5     my ($self, $url) = @_;
6     $url =~ qr!http://(?:(?:au|br|ca|fr|de|us|hk|ie|it|jp|mx|nl|nz|pl|es|tw|gb|www)\.)?youtube\.com/(?:watch(?:\.php)?)?\?v=.+!;
7 }
8
9 sub find {
10     my ($self, $args) = @_;
11     my $url = $args->{url};
12
13     my $ua = Plagger::UserAgent->new;
14
15     my $res = $ua->fetch($url);
16     return if $res->is_error;
17
18         if ((my $verify_url = $res->http_response->request->uri) =~ /\/verify_age\?/) {
19             $res = $ua->post($verify_url, { action_confirm => 'Confirm' });
20             return if $res->is_error;
21
22             $res = $ua->fetch($url);
23             return if $res->is_error;
24
25             $args->{content} = decode_content($res);
26         }
27
28     if ($args->{content} =~ /video_id=([^&]+)&.+?&t=([^&]+)/gms){
29         my $enclosure = Plagger::Enclosure->new;
30         $enclosure->url("http://youtube.com/get_video?video_id=$1&t=$2");
31         $enclosure->type('video/flv');
32         $enclosure->filename("$1.flv");
33         return $enclosure;
34     }
35
36     return;
37 }
Note: See TracBrowser for help on using the browser.