| 1 | 2 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package App::MP4Meta::Source::OMDB; | ||||||||||
| 6 | { | ||||||||||
| 7 | 2 | $App::MP4Meta::Source::OMDB::VERSION = '1.153340'; | |||||||||
| 8 | } | ||||||||||
| 9 | |||||||||||
| 10 | # ABSTRACT: Fetches film data from the OMDB. | ||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use App::MP4Meta::Source::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | our @ISA = 'App::MP4Meta::Source::Base'; | |||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | use App::MP4Meta::Source::Data::Film; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 2 | ▶ | use WebService::OMDB; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use File::Temp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use LWP::Simple (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 2 | ▶ | use constant NAME => 'OMDB'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ▶ | use constant PLOT => 'short'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 2 | ▶ | use constant RESPONSE => 'json'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 26 | 0 | my $class = shift; | |||||||||
| 27 | 0 | my $args = shift; | |||||||||
| 28 | 0 | my $self = $class->SUPER::new($args); | |||||||||
| 29 | |||||||||||
| 30 | 0 | return $self; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub name { | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | 0 | return NAME; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub get_film { | ||||||||
|
Subroutine
get_film: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 38 | 0 | my ( $self, $args ) = @_; | |||||||||
| 39 | |||||||||||
| 40 | 0 | $self->SUPER::get_film($args); | |||||||||
| 41 | |||||||||||
| 42 | my $result = WebService::OMDB::title( | ||||||||||
| 43 | $args->{title}, | ||||||||||
| 44 | { | ||||||||||
| 45 | year => $args->{year}, | ||||||||||
| 46 | 0 | plot => PLOT, | |||||||||
| 47 | r => RESPONSE | ||||||||||
| 48 | } | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | # get cover file | ||||||||||
| 52 | # FIXME: never set | ||||||||||
| 53 | 0 | my $cover_file; | |||||||||
| 54 | 0 | ▶ | unless ($cover_file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 0 | my $poster = $result->{Poster}; | |||||||||
| 57 | 0 | $cover_file = $self->_get_cover_file($poster); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | # FIXME: poster could be null. | ||||||||||
| 61 | |||||||||||
| 62 | return App::MP4Meta::Source::Data::Film->new( | ||||||||||
| 63 | overview => $result->{Plot}, | ||||||||||
| 64 | title => $result->{Title}, | ||||||||||
| 65 | genre => $result->{Genre}, | ||||||||||
| 66 | cover => $cover_file, | ||||||||||
| 67 | year => $result->{Year}, | ||||||||||
| 68 | 0 | ); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | # gets the cover file for the season and returns the filename | ||||||||||
| 72 | # also stores in cache | ||||||||||
| 73 | 0 | ▶ | sub _get_cover_file { | ||||||||
|
Subroutine
_get_cover_file: not called CC=2 SCAR=17.9
| |||||||||||
| 74 | 0 | my ( $self, $url ) = @_; | |||||||||
| 75 | |||||||||||
| 76 | 0 | my $temp = File::Temp->new( SUFFIX => '.jpg' ); | |||||||||
| 77 | 0 | push @{ $self->{tempfiles} }, $temp; | |||||||||
| 78 | 0 | ▶ | if ( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | LWP::Simple::is_success( | ||||||||||
| 80 | LWP::Simple::getstore( $url, $temp->filename ) | ||||||||||
| 81 | ) | ||||||||||
| 82 | ) | ||||||||||
| 83 | { | ||||||||||
| 84 | 0 | return $temp->filename; | |||||||||
| 85 | } | ||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 2 | 1; | |||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||