| 1 | package Plagger::Plugin::Subscription::Bookmarks::Safari; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin::Subscription::Bookmarks ); | ||
| 4 | |||
| 5 | use Mac::Tie::PList; | ||
| 6 | use URI; | ||
| 7 | |||
| 8 | sub load { | ||
| 9 | my($self, $context) = @_; | ||
| 10 | |||
| 11 | my $plist = Mac::Tie::PList->new_from_file($self->conf->{path}); | ||
| 12 | $self->find_feed($context, $plist); | ||
| 13 | } | ||
| 14 | |||
| 15 | sub find_feed { | ||
| 16 | my($self, $context, $plist, @tags) = @_; | ||
| 17 | |||
| 18 | if($plist->{Children}) { | ||
| 19 | push(@tags, $plist->{Title}) if $plist->{Title}; | ||
| 20 | |||
| 21 | for my $child (@{$plist->{Children}}) { | ||
| 22 | $self->find_feed($context, $child, @tags); | ||
| 23 | } | ||
| 24 | } elsif($plist->{URLString}) { | ||
| 25 | my $url = new URI($plist->{URLString}); | ||
| 26 | |||
| 27 | if($url->scheme eq 'feed') { | ||
| 28 | if($url->as_string =~ m|^feed:https|) { | ||
| 29 | $url->scheme(''); | ||
| 30 | } else { | ||
| 31 | $url->scheme('http'); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | my $feed = Plagger::Feed->new; | ||
| 36 | $feed->url($url->as_string); | ||
| 37 | $feed->title($plist->{URIDictionary}->{title}); | ||
| 38 | $feed->tags(\@tags); | ||
| 39 | $context->subscription->add($feed); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; |