Changeset 1775

Show
Ignore:
Timestamp:
10/17/06 23:06:33
Author:
mizzy
Message:

CustomFeed?::YouTube?: encode query if no_decode_utf8 is not set and a little refactoring.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/YouTube.pm

    r1734 r1775  
    66use Plagger::Enclosure; 
    77use Plagger::UserAgent; 
     8use URI; 
     9use Encode; 
    810 
    911sub register { 
     
    2527    my($self, $context, $args) = @_; 
    2628 
    27     my $q = $self->conf->{query}; 
    28     $q =~ s/\s/\+/g; 
     29    my $url  = URI->new('http://youtube.com/results'); 
     30    my $file = $self->cache->path_to('youtube_search_result.html'); 
     31    my $query = $self->conf->{query}; 
    2932 
    30     my $file = $self->cache->path_to('youtube_search_result.html')
     33    $query = encode('UTF-8', $query) unless $context->conf->{no_decode_utf8}
    3134 
    32     $context->log( info => 'Getting YouTube search results for ' . $self->conf->{query} ); 
     35    $context->log( info => 'Getting YouTube search results for ' . $query ); 
    3336 
    3437    my $ua = Plagger::UserAgent->new; 
     
    3639    my $feed = Plagger::Feed->new; 
    3740    $feed->type('youtubesearch'); 
    38     $feed->title('YouTube Search - ' . $self->conf->{query}); 
     41    $feed->title("YouTube Search - $query"); 
    3942 
    4043    my $page = $self->conf->{page} || 1; 
    4144    my $sort = $self->conf->{sort} || 'video_date_uploaded'; 
     45 
    4246    for ( 1 .. $page ){ 
    43         my $res = $ua->mirror("http://youtube.com/results?search_type=search_videos&search_query=$q&search_sort=$sort&search_category=0&page=$_" => $file); 
     47        $url->query_form( 
     48            search_type     => 'search_videos', 
     49            search_query    => $query, 
     50            search_sort     => $sort, 
     51            search_category => 0, 
     52            page            => $_, 
     53        ); 
     54 
     55        my $res = $ua->mirror( $url->as_string => $file ); 
    4456 
    4557        if($res->is_error){