root/trunk/plagger/lib/Plagger/Plugin/Subscription/2chThreadList.pm

Revision 608 (checked in by youpy, 14 years ago)

Subscription::2chThreadList now can load multiple urls.

Line 
1 package Plagger::Plugin::Subscription::2chThreadList;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use URI;
6 use XML::Feed;
7
8 sub register {
9     my($self, $context) = @_;
10
11     $context->register_hook(
12         $self,
13         'subscription.load' => \&load,
14     );
15 }
16
17 sub load {
18     my($self, $context) = @_;
19
20     my $threadlists = ref($self->conf->{url}) ? $self->conf->{url} : [ $self->conf->{url} ]
21         or $context->error('ThreadList url is missing');
22
23     for my $threadlist (@$threadlists) {
24         my $remote = XML::Feed->parse(URI->new($threadlist)) or $context->error("feed parse error $threadlist");
25         for my $r ($remote->entries) {
26             $context->log(info => "thread: ". $r->link);
27            
28             my $feed = Plagger::Feed->new;
29             $feed->url($r->link);
30             $feed->link($r->link);
31             $feed->title($r->title);
32             $context->subscription->add($feed);
33         }
34     }
35 }
36
37 1;
Note: See TracBrowser for help on using the browser.