root/plagger/trunk/lib/Plagger/Plugin/CustomFeed/GoogleVideo.pm

Revision 84, 2.9 kB (checked in by miya, 4 years ago)

modify pod

  • Property svn:executable set to *
Line 
1 package Plagger::Plugin::CustomFeed::GoogleVideo;
2 use strict;
3 use warnings;
4 use base qw( Plagger::Plugin );
5
6 use Plagger::UserAgent;
7 use XML::Simple;
8
9 sub register {
10     my($self, $context) = @_;
11     $context->register_hook(
12         $self,
13         'subscription.load' => \&load,
14         'aggregator.aggregate.googlevideo' => \&aggregate,
15     );
16 }
17
18 sub load {
19     my($self, $context) = @_;
20
21     my $feed = Plagger::Feed->new;
22     $feed->type('googlevideo');
23     $context->subscription->add($feed);
24 }
25
26 sub aggregate {
27     my($self, $context, $args) = @_;
28
29     my $q = $self->conf->{query};
30     $q =~ s/\s/\+/g;
31
32     my $ua = Plagger::UserAgent->new;
33     my $res = $ua->fetch("http://video.google.com/videofeed?type=search&q=$q&output=rss");
34     $context->log( error => $res->http_response->status_line ) if $res->is_error;
35
36     my $rss = XMLin( $res->content );
37
38     my $feed = Plagger::Feed->new;
39     my $channel = $rss->{channel};
40     $feed->type('GoogleVideo');
41     $feed->title($channel->{title});
42     $feed->link($channel->{link});
43     $feed->image({
44         url        => $channel->{image}->{url},
45         thumb_link => $channel->{image}->{url},
46         width      => $channel->{image}->{width},
47         height     => $channel->{image}->{height},
48     });
49     $feed->description($channel->{description});
50
51     my %type = (
52         flav => 0,
53         wmv  => 1,
54         ipod => 2,
55         psp  => 3,
56     );
57
58     for my $item (@{$rss->{channel}->{item}}){
59         my $entry = Plagger::Entry->new;
60         $entry->title($item->{title});
61         $entry->body($item->{description});
62         $entry->id($item->{guid});
63         $entry->link($item->{link});
64         $entry->date( Plagger::Date->parse('Mail', $item->{pubDate}) );
65         $entry->icon({
66             url        => $item->{'media:group'}->{'media:thumbnail'}->{url},
67             thumb_link => $item->{'media:group'}->{'media:thumbnail'}->{url},
68             width      => $item->{'media:group'}->{'media:thumbnail'}->{width},
69             height     => $item->{'media:group'}->{'media:thumbnail'}->{height},
70         });
71
72         if(ref($item->{'media:group'}->{'media:content'}) eq 'ARRAY'){
73             $entry->meta->{enclosure}->{url} = $item->{'media:group'}->{'media:content'}->[$type{$self->conf->{type}}]->{url};
74             $entry->meta->{enclosure}->{type} = $item->{'media:group'}->{'media:content'}->[$type{$self->conf->{type}}]->{type};
75         }
76         $feed->add_entry($entry);
77     }
78     $context->update->add($feed);
79 }
80
81 1;
82 __END__
83
84 =head1 NAME
85
86 Plagger::Plugin::CustomFeed::GoogleVideo - Get Google Video search result
87
88 =head1 SYNOPSIS
89
90   - module: CustomFeed::GoogleVideo
91     config:
92       query: nba allstar
93       type: ipod
94
95 =head1 DESCRIPTION
96
97 This plugin fetches the result of Google Video search.
98
99 =head1 CONFIG
100
101 =over 4
102
103 =item query
104
105 Search query strings.
106
107 =item type
108
109 Choose a type of video file from flav, wmv, ipod or psp.
110
111 =back
112
113 =head1 AUTHOR
114
115 Gosuke Miyashita
116
117 =head1 SEE ALSO
118
119 L<Plagger>
120
121 =cut
122
Note: See TracBrowser for help on using the browser.