Changeset 282

Show
Ignore:
Timestamp:
03/05/06 02:46:03
Author:
miyagawa
Message:

CustomFeed?::iTunesRecentPlay:

  • Added mizzy to AUTHORS
  • Added me to plugin author, since library.xml parsing code is mine
  • Cleaned up a code for better handling, switch Date::Parse to DateTime?::Format::W3CDTF
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/AUTHORS

    r270 r282  
    1313fuba 
    1414Yuichi Tateno (secondlife) 
     15Gosuke Miyashita 
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/iTunesRecentPlay.pm

    r280 r282  
    33use warnings; 
    44use base qw( Plagger::Plugin ); 
     5use File::Spec; 
    56use Encode; 
    6 use Date::Parse
     7use DateTime::Format::W3CDTF
    78use HTML::Entities; 
    89 
     
    2627sub aggregate { 
    2728    my($self, $context, $args) = @_; 
    28     my $conf = $self->conf; 
    2929 
    3030    my $file = $self->conf->{library_path}; 
    3131    unless ($file) { 
    3232        if ($^O eq 'MSWin32') { 
     33            require File::HomeDir::Windows; 
    3334            my $mymusic = File::HomeDir::Windows->my_win32_folder('My Music'); 
    3435            $file = File::Spec->catfile($mymusic, 'iTunes', 'iTunes Music Library.xml'); 
     
    3637            $file = File::Spec->catfile($ENV{HOME}, 'Music', 'iTunes', 'iTunes Music Library.xml'); 
    3738        } else { 
    38             $context->log(error => "I can't guess library.xml path using your OS name $^O. Specify using --library option."); 
     39            $context->log(error => "I can't guess library.xml path using your OS name $^O."); 
    3940            return; 
    4041        } 
    4142    } 
    4243 
    43     open my $fh, "<:encoding(utf-8)", $file or die "$file: $!"; 
     44    open my $fh, "<:encoding(utf-8)", $file 
     45        or return $class->log(error => "$file: $!"); 
    4446 
    4547    my $feed = Plagger::Feed->new; 
     
    6264            and do { 
    6365                my $entry = Plagger::Entry->new; 
    64                 if( $data->{date} and $data->{artist} and str2time($data->{date}) > time - $conf->{reload_period} ){ 
    65                     for(keys %$data){ 
    66                         $entry->meta->{$_} = $data->{$_}; 
     66 
     67                my $dt = DateTime::Format::W3CDTF->parse_datetime($data->{date}); 
     68                unless ($dt) { 
     69                    $context->log( warn => "Can't parse $data->{date}"); 
     70                    next; 
     71                } 
     72                if( $data->{date} and $data->{artist} and $dt->epoch > time - $self->conf->{reload_period} ){ 
     73                    for my $key (keys %$data){ 
     74                        $entry->meta->{$key} = $data->{$key}; 
    6775                    } 
    6876                    $context->log( info => $data->{artist} . ' ' . $data->{track}); 
     
    115123Gosuke Miyashita, E<lt>gosukenator@gmail.comE<gt> 
    116124 
     125Tatsuhiko Miyagawa 
     126 
    117127=head1 SEE ALSO 
    118128