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

Revision 121, 1.5 kB (checked in by miya, 3 years ago)

Add CustomFeed::Xmltv

  • Property svn:executable set to *
Line 
1 package Plagger::Plugin::CustomFeed::Xmltv;
2 use strict;
3 use warnings;
4 use base qw( Plagger::Plugin );
5
6 use XML::Simple;
7 use DateTime::Format::Strptime;
8
9 sub register {
10     my($self, $context) = @_;
11     $context->register_hook(
12         $self,
13         'subscription.load' => \&load,
14     );
15 }
16
17 sub load {
18     my($self, $context) = @_;
19     my $feed = Plagger::Feed->new;
20     $feed->aggregator(sub { $self->aggregate(@_) });
21     $context->subscription->add($feed);
22 }
23
24 sub aggregate {
25     my($self, $context, $args) = @_;
26
27     my $feed = Plagger::Feed->new;
28     $feed->type('xmltv');
29     $feed->title('xmltv');
30
31     my $tv = `tv_grab_jp`;
32     my $xml = XMLin($tv);
33     for (@{$xml->{programme}}){
34         my $entry = Plagger::Entry->new;
35
36         # ¥«¥Æ¥Ž¥ê
37         my $category;
38         if(ref($_->{category}) eq 'ARRAY'){
39             for (@{$_->{category}}){
40                 if($_->{lang} eq 'ja_JP'){
41                     $entry->add_tag($_->{content});
42                 }
43             }
44         }
45
46         # ¥¿¥€¥È¥ë
47         my $title;
48         if(ref($_->{title}) eq 'ARRAY'){
49             for (@{$_->{title}}){
50                 if($_->{lang} eq 'ja_JP'){
51                     $entry->title($_->{content});
52                 }
53             }
54         }
55         else {
56             $entry->title($_->{title}->{content});
57         }
58
59         # »þ¹ï
60         my $format = DateTime::Format::Strptime->new(pattern => '%Y%m%d%H%M%s %z');
61         $entry->date( Plagger::Date->parse($format, $_->{start}) );
62
63         $feed->add_entry($entry);
64     }
65
66     $context->update->add($feed);
67 }
68
69 1;
Note: See TracBrowser for help on using the browser.