| 54 | | |
|---|
| 55 | | my (@videos, $data); |
|---|
| 56 | | while (<$fh>) { |
|---|
| 57 | | m!<div class="moduleTitle">(.*)</div>! |
|---|
| 58 | | and $feed->title($1); |
|---|
| 59 | | m!<img src="(.*)" class="moduleEntryThumb" width="(\d+)" height="(\d+)">! |
|---|
| 60 | | and do { |
|---|
| 61 | | $data->{image}->{url} = $1; |
|---|
| 62 | | $data->{image}->{width} = $2; |
|---|
| 63 | | $data->{image}->{height} = $3; |
|---|
| | 45 | $feed->title('YouTube Search - ' . $self->conf->{query}); |
|---|
| | 46 | |
|---|
| | 47 | my $page = $self->conf->{page} || 1; |
|---|
| | 48 | my $sort = $self->conf->{sort} || 'video_date_uploaded'; |
|---|
| | 49 | for ( 1 .. $page ){ |
|---|
| | 50 | my $res = $ua->mirror("http://youtube.com/results?search=$q&sort=$sort&page=$_" => $file); |
|---|
| | 51 | |
|---|
| | 52 | if($res->is_error){ |
|---|
| | 53 | $context->log( error => $res->status_line ); |
|---|
| | 54 | return; |
|---|
| | 55 | } |
|---|
| | 56 | |
|---|
| | 57 | open my $fh, "<:encoding(utf-8)", $file |
|---|
| | 58 | or return $context->log(error => "$file: $!"); |
|---|
| | 59 | |
|---|
| | 60 | my (@videos, $data, $title_flag, $tag_flag); |
|---|
| | 61 | while (<$fh>) { |
|---|
| | 62 | # get title |
|---|
| | 63 | m!<div class="title">! |
|---|
| | 64 | and $title_flag = 1; |
|---|
| | 65 | m!<a href="/watch\?v=([^&]+)&search=[^>]+">(.+)</a>! |
|---|
| | 66 | and do { |
|---|
| | 67 | if($title_flag){ |
|---|
| | 68 | $data->{title} = $2; |
|---|
| | 69 | $data->{id} = $1; |
|---|
| | 70 | $title_flag = 0; |
|---|
| | 71 | } |
|---|
| | 72 | }; |
|---|
| | 73 | m!<img src="(http://static\d+.youtube.com/[^">]+/1.jpg)" class="vimgSm" />! |
|---|
| | 74 | and $data->{image}->{url} = $1; |
|---|
| | 75 | m!<div class="desc">(.*)</div>! |
|---|
| | 76 | and $data->{description} = $1; |
|---|
| | 77 | m!<td><span class="grayText">Tags:</span></td>! |
|---|
| | 78 | and $tag_flag = 1; |
|---|
| | 79 | m!(<td><a href="/results\?search=.*)! |
|---|
| | 80 | and do { |
|---|
| | 81 | if($tag_flag){ |
|---|
| | 82 | $data->{tags} = $1; |
|---|
| | 83 | $tag_flag = 0; |
|---|
| | 84 | } |
|---|
| | 85 | }; |
|---|
| | 86 | m!profile\?user=([^"]+)! |
|---|
| | 87 | and do { |
|---|
| | 88 | $context->log( info => 'Got ' . $data->{title}); |
|---|
| | 89 | $data->{author} = $1; |
|---|
| | 90 | my $entry = Plagger::Entry->new; |
|---|
| | 91 | $entry->title($data->{title}); |
|---|
| | 92 | $entry->link('http://youtube.com/watch?v=' . $data->{id}); |
|---|
| | 93 | $entry->icon({ |
|---|
| | 94 | url => $data->{image}->{url}, |
|---|
| | 95 | #width => $data->{image}->{width}, |
|---|
| | 96 | #height => $data->{image}->{height}, |
|---|
| | 97 | }); |
|---|
| | 98 | $entry->summary($data->{description}); |
|---|
| | 99 | $entry->body($data->{description}); |
|---|
| | 100 | $entry->author($data->{author}); |
|---|
| | 101 | |
|---|
| | 102 | # tags |
|---|
| | 103 | while( $data->{tags} =~ /<a href="\/results\?search=.*">(.*)<\/a>/gms){ |
|---|
| | 104 | $entry->add_tag($1); |
|---|
| | 105 | } |
|---|
| | 106 | |
|---|
| | 107 | # enclosure |
|---|
| | 108 | my $res = $ua->fetch($entry->link); |
|---|
| | 109 | if($res->is_error){ |
|---|
| | 110 | $context->log( error => $res->status_line ); |
|---|
| | 111 | return; |
|---|
| | 112 | } |
|---|
| | 113 | if($res->content =~ /&t=([^&]+)/gms){ |
|---|
| | 114 | $entry->meta->{enclosure}->{url} = 'http://youtube.com/get_video?video_id=' . $data->{id} . "&t=$1"; |
|---|
| | 115 | $entry->meta->{enclosure}->{type} = 'application/x-shockwave-flash'; |
|---|
| | 116 | } |
|---|
| | 117 | |
|---|
| | 118 | $feed->add_entry($entry); |
|---|
| | 119 | $data = {}; |
|---|
| 65 | | m!<div class="moduleEntryTitle"><a href="/(watch\?v=.*)&search=.*">(.*)</a> </div>! |
|---|
| 66 | | and do { |
|---|
| 67 | | $data->{title} = $2; |
|---|
| 68 | | $data->{path} = $1; |
|---|
| 69 | | }; |
|---|
| 70 | | m!<div class="moduleEntryDescription">(.*)<br>! |
|---|
| 71 | | and $data->{description} = $1; |
|---|
| 72 | | m!Tags // (.*)! |
|---|
| 73 | | and $data->{tags} = $1; |
|---|
| 74 | | m!profile\?user=([^"]+)! |
|---|
| 75 | | and do { |
|---|
| 76 | | $data->{author} = $1; |
|---|
| 77 | | my $entry = Plagger::Entry->new; |
|---|
| 78 | | $entry->title($data->{title}); |
|---|
| 79 | | $entry->link('http://youtube.com/' . $data->{path}); |
|---|
| 80 | | $entry->icon({ |
|---|
| 81 | | url => $data->{image}->{url}, |
|---|
| 82 | | width => $data->{image}->{width}, |
|---|
| 83 | | height => $data->{image}->{height}, |
|---|
| 84 | | }); |
|---|
| 85 | | $entry->summary($data->{description}); |
|---|
| 86 | | $entry->body($data->{description}); |
|---|
| 87 | | $entry->author($data->{author}); |
|---|
| 88 | | |
|---|
| 89 | | # tags |
|---|
| 90 | | while( $data->{tags} =~ /<a href="\/results\?search=.*">(.*)<\/a>/gms){ |
|---|
| 91 | | push @{$entry->tags}, $1; |
|---|
| 92 | | } |
|---|
| 93 | | |
|---|
| 94 | | # enclosure |
|---|
| 95 | | $context->log( info => 'Getting http://youtube.com/' . $data->{path}); |
|---|
| 96 | | my $res = $ua->fetch('http://youtube.com/' . $data->{path}); |
|---|
| 97 | | if($res->is_error){ |
|---|
| 98 | | $context->log( error => $res->status_line ); |
|---|
| 99 | | return; |
|---|
| 100 | | } |
|---|
| 101 | | if($res->content =~ /embed src="([^&]*)"/gms){ |
|---|
| 102 | | $entry->meta->{enclosure}->{url} = $1; |
|---|
| 103 | | $entry->meta->{enclosure}->{type} = 'application/x-shockwave-flash'; |
|---|
| 104 | | } |
|---|
| 105 | | |
|---|
| 106 | | $feed->add_entry($entry); |
|---|
| 107 | | $data = {}; |
|---|
| 108 | | }; |
|---|
| | 121 | } |
|---|