Changeset 720

Show
Ignore:
Timestamp:
05/13/06 03:58:24
Author:
miyagawa
Message:
  • new module Filter::FetchEnclosure?
  • $enclosure->auto_set_type($type) falls back to URL extension if $type isn't set
  • $enclosure->url is now URI object
  • Added $enclosure->media_type, $enclosure->sub_type, $enclosure->filename
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Enclosure.pm

    r719 r720  
    11package Plagger::Enclosure; 
    22use strict; 
     3 
    34use base qw( Class::Accessor::Fast ); 
     5__PACKAGE__->mk_accessors(qw( url length type )); 
    46 
    5 __PACKAGE__->mk_accessors(qw( url length type )); 
     7sub auto_set_type { 
     8    my($self, $type) = @_; 
     9 
     10    if (defined $type) { 
     11        return $self->type($type); 
     12    } 
     13 
     14    require MIME::Types; 
     15 
     16    # no type is set in XML ... set via URL extension 
     17    my $ext  = ( $self->url->path =~ /\.(\w+)/ )[0]; 
     18    my $mime = MIME::Types->new->mimeTypeOf($ext) or return; 
     19 
     20    $self->type($mime->type); 
     21
     22 
     23sub media_type { 
     24    my $self = shift; 
     25    ( split '/', $self->type )[0] || 'unknown'; 
     26
     27 
     28sub sub_type { 
     29    my $self = shift; 
     30    ( split '/', $self->type )[1] || 'unknown'; 
     31
     32 
     33sub filename { 
     34    my $self = shift; 
     35    (split '/', $self->url->path)[-1]; 
     36
    637 
    7381; 
  • trunk/plagger/lib/Plagger/Plugin/Aggregator/Simple.pm

    r719 r720  
    141141        if ($remote->format =~ /^RSS / && $e->{entry}->{enclosure}) { 
    142142            my $enclosure = Plagger::Enclosure->new; 
    143             $enclosure->url($e->{entry}->{enclosure}->{url}); 
     143            $enclosure->url( URI->new($e->{entry}->{enclosure}->{url}) ); 
    144144            $enclosure->length($e->{entry}->{enclosure}->{length}); 
    145             $enclosure->type($e->{entry}->{enclosure}->{type}); 
     145            $enclosure->auto_set_type($e->{entry}->{enclosure}->{type}); 
    146146            $entry->add_enclosure($enclosure); 
    147147        } elsif ($remote->format eq 'Atom') { 
    148148            for my $link ( grep { $_->rel eq 'enclosure' } $e->{entry}->link ) { 
    149149                my $enclosure = Plagger::Enclosure->new; 
    150                 $enclosure->url($link->href); 
     150                $enclosure->url( URI->new($link->href) ); 
    151151                $enclosure->length($link->length); 
    152                 $enclosure->type($link->type); 
     152                $enclosure->auto_set_type($link->type); 
    153153                $entry->add_enclosure($enclosure); 
    154154            }