Changeset 10

Show
Ignore:
Timestamp:
10/14/06 22:15:08
Author:
yohei
Message:

Use date based file name.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plagger/trunk/my-plugins/Filter-FetchEnclosure-Mplayer/Mplayer.pm

    r9 r10  
    2525        $context->log(error => q{config 'type' is not set.}); 
    2626    } 
     27    my $file_name_base = $args->{entry}->date->strftime('%Y%m%d-%H%M'); 
    2728 
    2829    for my $enclosure ($args->{entry}->enclosures) { 
     
    4142        } 
    4243 
    43         my $path_base   = File::Spec->catfile($feed_dir, $args->{entry}->digest); 
    44         my $output_path = "$path_base.wav"; 
    45          
     44        my $stream_url     = ($self->_get_stream_urls_for($enclosure))[0]; 
     45        my $enclosure_num  = 0; 
     46        my $file_name      = "$file_name_base-$enclosure_num"; 
     47        my $file_path_base = File::Spec->catfile($feed_dir, "$file_name"); 
     48        my $output_path    = "$file_path_base.wav";  
     49 
    4650        # Check existence of fetched data 
    4751        my $fetched_extension = $self->conf->{consider_fetched} || 'mp3'; 
    48         my $fetched_data_path = "$path_base.$fetched_extension"; 
     52        my $fetched_data_path = "$file_path_base.$fetched_extension"; 
    4953        if (-e $fetched_data_path || -e $output_path) { 
    5054            my $length = -s _; 
     55            $ enclosure->url($enclosure->url); 
    5156            $enclosure->length($length); 
    5257            $enclosure->type('audio/x-wav'); 
     
    5560            next; 
    5661        } 
    57  
    58         my $stream_url = $self->_get_stream_url_for($enclosure); 
    5962 
    6063        $context->log(info => "fetch $stream_url to $output_path"); 
     
    7982            $enclosure->type('audio/x-wav'); 
    8083            $enclosure->local_path($output_path); 
    81             $context->log(info => "Dumping to $output_path is done [$length]"); 
     84 
     85            $context->log(info => "Dumping to $output_path is done."); 
    8286        } 
    8387        else { 
     
    8993} 
    9094 
    91 sub _get_stream_url_for { 
     95sub _get_stream_urls_for { 
    9296    my ($self, $enclosure) = @_; 
    9397 
    94     my $stream_url
     98    my @stream_urls
    9599     
    96100    # TODO support multi stream addresses 
     
    98102        my $res = $self->{ua}->fetch($enclosure->url) 
    99103            or Plagger->context->log; 
    100         $res->content =~ m!((?:http|mms)://.*?\.(?:wsx|wma|asf))!; 
    101         $stream_url = $1
     104        @stream_urls  
     105            = $res->content =~ m!((?:http|mms)://.*?\.(?:wmv|wsx|wma|asf))!g
    102106    } 
    103107    elsif ($enclosure->type =~ /realaudio/) { 
    104108        my $res = $self->{ua}->fetch($enclosure->url) 
    105109            or Plagger->context->log; 
    106         $res->content =~ m!(rtsp://.*?\.(?:rm|smi))!; 
    107         $stream_url = $1
     110        @stream_urls 
     111            = $res->content =~ m!(rtsp://.*?\.(?:rm|smi))!g
    108112    } 
    109113 
    110114    Plagger->context->log(warn => "Cannot get stream url for " .  $enclosure->url) 
    111         unless $stream_url
     115        unless @stream_urls
    112116 
    113     return $stream_url
     117    return @stream_urls
    114118} 
    115119 
     
    127131    config: 
    128132      dir: /path/to/download 
     133      sub_dir_name: sub_directory_name 
    129134      type: asf 
    130135