Changeset 10
- Timestamp:
- 10/14/06 22:15:08
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plagger/trunk/my-plugins/Filter-FetchEnclosure-Mplayer/Mplayer.pm
r9 r10 25 25 $context->log(error => q{config 'type' is not set.}); 26 26 } 27 my $file_name_base = $args->{entry}->date->strftime('%Y%m%d-%H%M'); 27 28 28 29 for my $enclosure ($args->{entry}->enclosures) { … … 41 42 } 42 43 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 46 50 # Check existence of fetched data 47 51 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"; 49 53 if (-e $fetched_data_path || -e $output_path) { 50 54 my $length = -s _; 55 $ enclosure->url($enclosure->url); 51 56 $enclosure->length($length); 52 57 $enclosure->type('audio/x-wav'); … … 55 60 next; 56 61 } 57 58 my $stream_url = $self->_get_stream_url_for($enclosure);59 62 60 63 $context->log(info => "fetch $stream_url to $output_path"); … … 79 82 $enclosure->type('audio/x-wav'); 80 83 $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."); 82 86 } 83 87 else { … … 89 93 } 90 94 91 sub _get_stream_url _for {95 sub _get_stream_urls_for { 92 96 my ($self, $enclosure) = @_; 93 97 94 my $stream_url;98 my @stream_urls; 95 99 96 100 # TODO support multi stream addresses … … 98 102 my $res = $self->{ua}->fetch($enclosure->url) 99 103 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; 102 106 } 103 107 elsif ($enclosure->type =~ /realaudio/) { 104 108 my $res = $self->{ua}->fetch($enclosure->url) 105 109 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; 108 112 } 109 113 110 114 Plagger->context->log(warn => "Cannot get stream url for " . $enclosure->url) 111 unless $stream_url;115 unless @stream_urls; 112 116 113 return $stream_url;117 return @stream_urls; 114 118 } 115 119 … … 127 131 config: 128 132 dir: /path/to/download 133 sub_dir_name: sub_directory_name 129 134 type: asf 130 135
