| 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::TVDB; | ||||||||||
| 6 | { | ||||||||||
| 7 | 2 | $App::MP4Meta::Source::TVDB::VERSION = '1.153340'; | |||||||||
| 8 | } | ||||||||||
| 9 | |||||||||||
| 10 | # ABSTRACT: Searches http://thetvbd.com for TV data. | ||||||||||
| 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::TVEpisode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 2 | ▶ | use WebService::TVDB 1.122800; | ||||||||
|
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 => 'theTVDB.com'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 24 | 0 | my $class = shift; | |||||||||
| 25 | 0 | my $args = shift; | |||||||||
| 26 | 0 | my $self = $class->SUPER::new($args); | |||||||||
| 27 | |||||||||||
| 28 | # TODO: specify language | ||||||||||
| 29 | # TODO: API key? | ||||||||||
| 30 | 0 | $self->{tvdb} = WebService::TVDB->new(); | |||||||||
| 31 | |||||||||||
| 32 | 0 | return $self; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub name { | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 36 | 0 | return NAME; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub get_tv_episode { | ||||||||
|
Subroutine
get_tv_episode: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 40 | 0 | my ( $self, $args ) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 0 | $self->SUPER::get_tv_episode($args); | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $series_list = $self->{tvdb}->search( $args->{show_title} ); | |||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | die 'no series found' unless @$series_list; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | # TODO: ability to search results i.e. by year | ||||||||||
| 49 | 0 | my $series = @{$series_list}[0]; | |||||||||
| 50 | 0 | my $cover_file; | |||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | if ( $self->{cache}->{ $series->id } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | $series = $self->{cache}->{ $series->id }; | |||||||||
| 54 | } | ||||||||||
| 55 | else { | ||||||||||
| 56 | |||||||||||
| 57 | # fetches full series data and cache | ||||||||||
| 58 | 0 | $series->fetch(); | |||||||||
| 59 | 0 | $series = $self->{cache}->{ $series->id } = $series; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | # get banner file and cache | ||||||||||
| 63 | 0 | ▶ | if ( $self->{banner_cache}->{ $series->id . '-S' . $args->{season} } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | $cover_file = | ||||||||||
| 65 | 0 | $self->{banner_cache}->{ $series->id . '-S' . $args->{season} }; | |||||||||
| 66 | } | ||||||||||
| 67 | else { | ||||||||||
| 68 | |||||||||||
| 69 | $cover_file = | ||||||||||
| 70 | $self->{banner_cache}->{ $series->id . '-S' . $args->{season} } = | ||||||||||
| 71 | 0 | $self->_get_cover_file( $series, $args->{season} ); | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | # get episode | ||||||||||
| 75 | 0 | my $episode = $series->get_episode( $args->{season}, $args->{episode} ); | |||||||||
| 76 | |||||||||||
| 77 | 0 | return App::MP4Meta::Source::Data::TVEpisode->new( | |||||||||
| 78 | overview => $episode->Overview, | ||||||||||
| 79 | title => $episode->EpisodeName, | ||||||||||
| 80 | show_title => $series->SeriesName, | ||||||||||
| 81 | genre => $series->Genre->[0], | ||||||||||
| 82 | cover => $cover_file, | ||||||||||
| 83 | year => $episode->year, | ||||||||||
| 84 | ); | ||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | # gets the cover file for the season and returns the filename | ||||||||||
| 88 | # also stores in cache | ||||||||||
| 89 | 0 | ▶ | sub _get_cover_file { | ||||||||
|
Subroutine
_get_cover_file: not called CC=5 SCAR=34.0
| |||||||||||
| 90 | 0 | my ( $self, $series, $season ) = @_; | |||||||||
| 91 | |||||||||||
| 92 | 0 | for my $banner ( @{ $series->banners } ) { | |||||||||
| 93 | 0 | ▶ | if ( $banner->BannerType2 eq 'season' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | ▶ | if ( $banner->Season eq $season ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 0 | my $temp = File::Temp->new( SUFFIX => '.jpg' ); | |||||||||
| 96 | 0 | push @{ $self->{tempfiles} }, $temp; | |||||||||
| 97 | 0 | ▶ | if ( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | LWP::Simple::is_success( | ||||||||||
| 99 | LWP::Simple::getstore( $banner->url, $temp->filename ) | ||||||||||
| 100 | ) | ||||||||||
| 101 | ) | ||||||||||
| 102 | { | ||||||||||
| 103 | 0 | return $temp->filename; | |||||||||
| 104 | } | ||||||||||
| 105 | } | ||||||||||
| 106 | } | ||||||||||
| 107 | } | ||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 2 | 1; | |||||||||
| 111 | |||||||||||
| 112 | __END__ | ||||||||||