|
Revision 1951
(checked in by miyagawa, 1 year ago)
|
add Dave's trailer HD extractor using Web::Scraper
|
- Property svn:executable set to
*
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
use strict; |
|---|
| 3 |
use warnings; |
|---|
| 4 |
|
|---|
| 5 |
use Web::Scraper; |
|---|
| 6 |
use URI; |
|---|
| 7 |
use YAML; |
|---|
| 8 |
|
|---|
| 9 |
my $want = $ARGV[0] || "1080P"; |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
my $uri = URI->new("http://www.drfoster.f2s.com/"); |
|---|
| 13 |
|
|---|
| 14 |
my $s = scraper { |
|---|
| 15 |
process "td>ul>li", "trailers[]" => scraper { |
|---|
| 16 |
process_first "li>b", title => "TEXT"; |
|---|
| 17 |
process_first "ul>li>a[href]", url => '@href'; |
|---|
| 18 |
process "ul>li>ul>li>a", "movies[]" => sub { |
|---|
| 19 |
my $elem = shift; |
|---|
| 20 |
return { |
|---|
| 21 |
text => $elem->as_text, |
|---|
| 22 |
href => $elem->attr('href'), |
|---|
| 23 |
}; |
|---|
| 24 |
}; |
|---|
| 25 |
}; |
|---|
| 26 |
result "trailers"; |
|---|
| 27 |
}; |
|---|
| 28 |
|
|---|
| 29 |
my $feed = { |
|---|
| 30 |
title => "Dave's Trailers Page (HD)", |
|---|
| 31 |
link => $uri->as_string, |
|---|
| 32 |
}; |
|---|
| 33 |
|
|---|
| 34 |
for my $trailer (@{ $s->scrape($uri) }) { |
|---|
| 35 |
my @movies = grep { ($_->{text}||'') eq "HD $want" } @{$trailer->{movies} || []}; |
|---|
| 36 |
if (@movies) { |
|---|
| 37 |
push @{$feed->{entries}}, { |
|---|
| 38 |
title => $trailer->{title}, |
|---|
| 39 |
link => $trailer->{url}, |
|---|
| 40 |
enclosure => { |
|---|
| 41 |
url => $movies[0]->{href}, |
|---|
| 42 |
type => "video/quicktime", |
|---|
| 43 |
}, |
|---|
| 44 |
}; |
|---|
| 45 |
} |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
use YAML; |
|---|
| 49 |
binmode STDOUT, ":utf8"; |
|---|
| 50 |
print Dump $feed; |
|---|
| 51 |
|
|---|