root/trunk/plagger/lib/Plagger/Plugin/Subscription/Odeo.pm

Revision 733 (checked in by miyagawa, 14 years ago)

add Odeo aggregation example

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Subscription::Odeo;
2 use strict;
3 use base qw( Plagger::Plugin::Subscription::OPML );
4
5 use Plagger::UserAgent;
6 use URI::Escape;
7 use HTML::Entities;
8
9 sub register {
10     my($self, $context) = @_;
11
12     $context->register_hook(
13         $self,
14         'subscription.load' => \&load,
15     );
16 }
17
18 sub load {
19     my($self, $context) = @_;
20
21     my $account = $self->conf->{account}
22         or $context->error("config 'account' is missing");
23
24     my $uri = URI->new("http://www.odeo.com/profile/$account/opml.xml");
25     $context->log(debug => "Fetch remote OPML from $uri");
26
27     my $response = Plagger::UserAgent->new->get($uri);
28     unless ($response->is_success) {
29         $context->error("Fetch $uri failed: ". $response->status_line);
30     }
31
32     my $xml = $response->content;
33
34     # fix Odeo's bad OPML
35     $xml =~ s{<outline text="(.*?)" type="link" url="(http://.*?)" count="(\d+)"/>}{
36         my($title, $url, $count) = ($1, $2, $3);
37
38         $title = uri_unescape($title);
39         $title =~ s/\r\n//g;
40         $title =~ tr/\+/ /;
41         $title = encode_html($title);
42         $url   = encode_html($url);
43
44         qq(<outline text="$title" type="rss" xmlUrl="$url" count="$count"/>)
45     }eg;
46
47     $self->load_opml($context, \$xml);
48 }
49
50 sub encode_html {
51     HTML::Entities::encode($_[0], q("<>&));
52 }
53
54 1;
55
56 __END__
57
58 =head1 NAME
59
60 Plagger::Plugin::Subscription::Odeo - Odeo Subscription via OPML
61
62 =head1 SYNOPSIS
63
64   - module: Subscription::Odeo
65     config:
66       account: TatsuhikoMiyagawa
67
68 =head1 DESCRIPTION
69
70 This plugin creates Subscription by fetching Odeo
71 L<http://www.odeo.com/> OPML by HTTP.
72
73 =head1 NOTE
74
75 We should probably better use C<rss.xml> or C<pcast.xml> they provide and
76 synchronizes enclosures as well, ala Bloglines Subscription plugin.
77
78 =head1 AUTHOR
79
80 Tatsuhiko Miyagawa
81
82 =head1 SEE ALSO
83
84 L<Plagger>, L<Plagger::Plugin::Subscription::OPML>
85
86 =cut
87
Note: See TracBrowser for help on using the browser.