package Plagger::Plugin::CustomFeed::YouTube_dev; use strict; use warnings; use base qw( Plagger::Plugin ); use Plagger::Enclosure; use Plagger::UserAgent; use Plagger::Date; use LWP::Simple; use XML::Simple; sub register { my($self, $context) = @_; $context->register_hook( $self, 'subscription.load' => \&load, ); } sub load { my($self, $context) = @_; my $feed = Plagger::Feed->new; $feed->aggregator(sub { $self->aggregate(@_) }); $context->subscription->add($feed); } sub aggregate { my($self, $context, $args) = @_; my $q = $self->conf->{query}; $q =~ s/\s/\+/g; my $file = $self->cache->path_to('youtube_search_result.html'); $context->log( info => 'Getting YouTube search results for ' . $self->conf->{query} ); my $ua = Plagger::UserAgent->new; my $feed = Plagger::Feed->new; $feed->type('youtubesearch'); $feed->title('YouTube Search - ' . $self->conf->{query}); my $page = $self->conf->{page} || 1; my $sort = $self->conf->{sort} || 'video_date_uploaded'; for ( 1 .. $page ){ my $res = $ua->mirror("http://youtube.com/results?search=$q&sort=$sort&page=$_"=>$file); if($res->is_error){ $context->log( error => $res->status_line ); return; } open my $fh, "<:encoding(utf-8)", $file or return $context->log(error => "$file: $!"); my (@videos, $data, $title_flag, $tag_flag, $video_details, $video_id); while (<$fh>) { # get id m!