line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TMDB::TV; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
####################### |
4
|
|
|
|
|
|
|
# LOAD CORE MODULES |
5
|
|
|
|
|
|
|
####################### |
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
3
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak carp); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
####################### |
11
|
|
|
|
|
|
|
# LOAD CPAN MODULES |
12
|
|
|
|
|
|
|
####################### |
13
|
1
|
|
|
1
|
|
4
|
use Object::Tiny qw(id session); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
14
|
1
|
|
|
1
|
|
202
|
use Params::Validate qw(validate_with :types); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
187
|
|
15
|
1
|
|
|
1
|
|
6
|
use Locale::Codes::Country qw(all_country_codes); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
####################### |
18
|
|
|
|
|
|
|
# LOAD DIST MODULES |
19
|
|
|
|
|
|
|
####################### |
20
|
1
|
|
|
1
|
|
3
|
use TMDB::Session; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
####################### |
23
|
|
|
|
|
|
|
# VERSION |
24
|
|
|
|
|
|
|
####################### |
25
|
|
|
|
|
|
|
our $VERSION = '1.2.1'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
####################### |
28
|
|
|
|
|
|
|
# PUBLIC METHODS |
29
|
|
|
|
|
|
|
####################### |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
## ==================== |
32
|
|
|
|
|
|
|
## Constructor |
33
|
|
|
|
|
|
|
## ==================== |
34
|
|
|
|
|
|
|
sub new { |
35
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
36
|
0
|
|
|
|
|
|
my %opts = validate_with( |
37
|
|
|
|
|
|
|
params => \@_, |
38
|
|
|
|
|
|
|
spec => { |
39
|
|
|
|
|
|
|
session => { |
40
|
|
|
|
|
|
|
type => OBJECT, |
41
|
|
|
|
|
|
|
isa => 'TMDB::Session', |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
id => { |
44
|
|
|
|
|
|
|
type => SCALAR, |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(%opts); |
50
|
0
|
|
|
|
|
|
return $self; |
51
|
|
|
|
|
|
|
} ## end sub new |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## ==================== |
54
|
|
|
|
|
|
|
## INFO |
55
|
|
|
|
|
|
|
## ==================== |
56
|
|
|
|
|
|
|
sub info { |
57
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
58
|
0
|
|
|
|
|
|
my $params = {}; |
59
|
0
|
0
|
|
|
|
|
$params->{language} = $self->session->lang if $self->session->lang; |
60
|
0
|
|
|
|
|
|
my $info = $self->session->talk( |
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
method => 'tv/' . $self->id, |
63
|
|
|
|
|
|
|
params => $params |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
); |
66
|
0
|
0
|
|
|
|
|
return unless $info; |
67
|
0
|
|
|
|
|
|
$self->{id} = $info->{id}; # Reset TMDB ID |
68
|
0
|
|
|
|
|
|
return $info; |
69
|
|
|
|
|
|
|
} ## end sub info |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
## ==================== |
72
|
|
|
|
|
|
|
## ALTERNATIVE TITLES |
73
|
|
|
|
|
|
|
## ==================== |
74
|
|
|
|
|
|
|
sub alternative_titles { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my $country = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Valid Country codes |
79
|
0
|
0
|
|
|
|
|
if ($country) { |
80
|
|
|
|
|
|
|
my %valid_country_codes |
81
|
0
|
|
|
|
|
|
= map { $_ => 1 } all_country_codes('alpha-2'); |
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$country = uc $country; |
83
|
0
|
0
|
|
|
|
|
return unless $valid_country_codes{$country}; |
84
|
|
|
|
|
|
|
} ## end if ($country) |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $args = { |
87
|
|
|
|
|
|
|
method => 'tv/' . $self->id() . '/alternative_titles', |
88
|
|
|
|
|
|
|
params => {}, |
89
|
|
|
|
|
|
|
}; |
90
|
0
|
0
|
|
|
|
|
$args->{params}->{country} = $country if $country; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $response = $self->session->talk($args); |
93
|
0
|
|
0
|
|
|
|
my $titles = $response->{results} || []; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
return @$titles if wantarray; |
96
|
0
|
|
|
|
|
|
return $titles; |
97
|
|
|
|
|
|
|
} ## end sub alternative_titles |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
## ==================== |
100
|
|
|
|
|
|
|
## CAST |
101
|
|
|
|
|
|
|
## ==================== |
102
|
|
|
|
|
|
|
sub cast { |
103
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
my $response = $self->_credits(); |
105
|
0
|
|
0
|
|
|
|
my $cast = $response->{cast} || []; |
106
|
0
|
0
|
|
|
|
|
return @$cast if wantarray; |
107
|
0
|
|
|
|
|
|
return $cast; |
108
|
|
|
|
|
|
|
} ## end sub cast |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
## ==================== |
111
|
|
|
|
|
|
|
## CREW |
112
|
|
|
|
|
|
|
## ==================== |
113
|
|
|
|
|
|
|
sub crew { |
114
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
my $response = $self->_credits(); |
116
|
0
|
|
0
|
|
|
|
my $crew = $response->{crew} || []; |
117
|
0
|
0
|
|
|
|
|
return @$crew if wantarray; |
118
|
0
|
|
|
|
|
|
return $crew; |
119
|
|
|
|
|
|
|
} ## end sub crew |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
## ==================== |
122
|
|
|
|
|
|
|
## IMAGES |
123
|
|
|
|
|
|
|
## ==================== |
124
|
|
|
|
|
|
|
sub images { |
125
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
126
|
0
|
|
|
|
|
|
my $params = {}; |
127
|
0
|
0
|
|
|
|
|
$params->{lang} = $self->session->lang if $self->session->lang; |
128
|
0
|
|
|
|
|
|
return $self->session->talk( |
129
|
|
|
|
|
|
|
{ |
130
|
|
|
|
|
|
|
method => 'tv/' . $self->id() . '/images', |
131
|
|
|
|
|
|
|
params => $params |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
} ## end sub images |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
## ==================== |
137
|
|
|
|
|
|
|
## VIDEOS |
138
|
|
|
|
|
|
|
## ==================== |
139
|
|
|
|
|
|
|
sub videos { |
140
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my $response |
142
|
|
|
|
|
|
|
= $self->session->talk( { method => 'tv/' . $self->id() . '/videos' } ); |
143
|
0
|
|
0
|
|
|
|
my $videos = $response->{results} || []; |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
|
return @$videos if wantarray; |
146
|
0
|
|
|
|
|
|
return $videos; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} ## end sub videos |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
## ==================== |
151
|
|
|
|
|
|
|
## KEYWORDS |
152
|
|
|
|
|
|
|
## ==================== |
153
|
|
|
|
|
|
|
sub keywords { |
154
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
155
|
0
|
|
|
|
|
|
my $response = $self->session->talk( |
156
|
|
|
|
|
|
|
{ method => 'tv/' . $self->id() . '/keywords' } ); |
157
|
0
|
|
0
|
|
|
|
my $keywords_dump = $response->{results} || []; |
158
|
0
|
|
|
|
|
|
my @keywords; |
159
|
0
|
|
|
|
|
|
foreach (@$keywords_dump) { push @keywords, $_->{name}; } |
|
0
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
return @keywords if wantarray; |
161
|
0
|
|
|
|
|
|
return \@keywords; |
162
|
|
|
|
|
|
|
} ## end sub keywords |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
## ==================== |
165
|
|
|
|
|
|
|
## TRANSLATIONS |
166
|
|
|
|
|
|
|
## ==================== |
167
|
|
|
|
|
|
|
sub translations { |
168
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
169
|
0
|
|
|
|
|
|
my $response = $self->session->talk( |
170
|
|
|
|
|
|
|
{ method => 'tv/' . $self->id() . '/translations' } ); |
171
|
0
|
|
0
|
|
|
|
my $translations = $response->{translations} || []; |
172
|
0
|
0
|
|
|
|
|
return @$translations if wantarray; |
173
|
0
|
|
|
|
|
|
return $translations; |
174
|
|
|
|
|
|
|
} ## end sub translations |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
## ==================== |
177
|
|
|
|
|
|
|
## SIMILAR TV SHOWS |
178
|
|
|
|
|
|
|
## ==================== |
179
|
|
|
|
|
|
|
sub similar { |
180
|
0
|
|
|
0
|
0
|
|
my ( $self, $max_pages ) = @_; |
181
|
0
|
0
|
|
|
|
|
return $self->session->paginate_results( |
182
|
|
|
|
|
|
|
{ |
183
|
|
|
|
|
|
|
method => 'tv/' . $self->id() . '/similar', |
184
|
|
|
|
|
|
|
max_pages => $max_pages, |
185
|
|
|
|
|
|
|
params => { |
186
|
|
|
|
|
|
|
language => $self->session->lang |
187
|
|
|
|
|
|
|
? $self->session->lang |
188
|
|
|
|
|
|
|
: undef, |
189
|
|
|
|
|
|
|
}, |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
); |
192
|
|
|
|
|
|
|
} ## end sub similar |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
## ==================== |
195
|
|
|
|
|
|
|
## CONTENT RATING |
196
|
|
|
|
|
|
|
## ==================== |
197
|
|
|
|
|
|
|
sub content_ratings { |
198
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
199
|
0
|
|
|
|
|
|
my $response = $self->session->talk( |
200
|
|
|
|
|
|
|
{ method => 'tv/' . $self->id() . '/content_ratings' } ); |
201
|
0
|
|
0
|
|
|
|
my $content_ratings = $response->{results} || []; |
202
|
0
|
0
|
|
|
|
|
return @$content_ratings if wantarray; |
203
|
0
|
|
|
|
|
|
return $content_ratings; |
204
|
|
|
|
|
|
|
} ## end sub content_ratings |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
## ==================== |
207
|
|
|
|
|
|
|
## SEASON |
208
|
|
|
|
|
|
|
## ==================== |
209
|
|
|
|
|
|
|
sub season { |
210
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
211
|
0
|
|
|
|
|
|
my $season = shift; |
212
|
0
|
|
|
|
|
|
return $self->session->talk( |
213
|
|
|
|
|
|
|
{ method => 'tv/' . $self->id() . '/season/' . $season } ); |
214
|
|
|
|
|
|
|
} ## end sub season |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
## ==================== |
217
|
|
|
|
|
|
|
## EPISODE |
218
|
|
|
|
|
|
|
## ==================== |
219
|
|
|
|
|
|
|
sub episode { |
220
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
221
|
0
|
|
|
|
|
|
my $season = shift; |
222
|
0
|
|
|
|
|
|
my $episode = shift; |
223
|
0
|
|
|
|
|
|
return $self->session->talk( |
224
|
|
|
|
|
|
|
{ |
225
|
|
|
|
|
|
|
method => 'tv/' |
226
|
|
|
|
|
|
|
. $self->id() |
227
|
|
|
|
|
|
|
. '/season/' |
228
|
|
|
|
|
|
|
. $season |
229
|
|
|
|
|
|
|
. '/episode/' |
230
|
|
|
|
|
|
|
. $episode |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
); |
233
|
|
|
|
|
|
|
} ## end sub episode |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
## ==================== |
236
|
|
|
|
|
|
|
## CHANGES |
237
|
|
|
|
|
|
|
## ==================== |
238
|
|
|
|
|
|
|
sub changes { |
239
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
240
|
0
|
|
|
|
|
|
my %options = validate_with( |
241
|
|
|
|
|
|
|
params => [@args], |
242
|
|
|
|
|
|
|
spec => { |
243
|
|
|
|
|
|
|
start_date => { |
244
|
|
|
|
|
|
|
type => SCALAR, |
245
|
|
|
|
|
|
|
optional => 1, |
246
|
|
|
|
|
|
|
regex => qr/^\d{4}\-\d{2}\-\d{2}$/ |
247
|
|
|
|
|
|
|
}, |
248
|
|
|
|
|
|
|
end_date => { |
249
|
|
|
|
|
|
|
type => SCALAR, |
250
|
|
|
|
|
|
|
optional => 1, |
251
|
|
|
|
|
|
|
regex => qr/^\d{4}\-\d{2}\-\d{2}$/ |
252
|
|
|
|
|
|
|
}, |
253
|
|
|
|
|
|
|
}, |
254
|
|
|
|
|
|
|
); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
my $changes = $self->session->talk( |
257
|
|
|
|
|
|
|
{ |
258
|
|
|
|
|
|
|
method => 'tv/' . $self->id() . '/changes', |
259
|
|
|
|
|
|
|
params => { |
260
|
|
|
|
|
|
|
( |
261
|
|
|
|
|
|
|
$options{start_date} |
262
|
|
|
|
|
|
|
? ( start_date => $options{start_date} ) |
263
|
|
|
|
|
|
|
: () |
264
|
|
|
|
|
|
|
), ( |
265
|
|
|
|
|
|
|
$options{end_date} ? ( end_date => $options{end_date} ) |
266
|
0
|
0
|
|
|
|
|
: () |
|
|
0
|
|
|
|
|
|
267
|
|
|
|
|
|
|
), |
268
|
|
|
|
|
|
|
}, |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
); |
271
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
return unless defined $changes; |
273
|
0
|
0
|
|
|
|
|
return unless exists $changes->{changes}; |
274
|
0
|
0
|
|
|
|
|
return @{ $changes->{changes} } if wantarray; |
|
0
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
|
return $changes->{changes}; |
276
|
|
|
|
|
|
|
} ## end sub changes |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
## ==================== |
279
|
|
|
|
|
|
|
## VERSION |
280
|
|
|
|
|
|
|
## ==================== |
281
|
|
|
|
|
|
|
sub version { |
282
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
283
|
0
|
0
|
|
|
|
|
my $response = $self->session->talk( |
284
|
|
|
|
|
|
|
{ |
285
|
|
|
|
|
|
|
method => 'tv/' . $self->id(), |
286
|
|
|
|
|
|
|
want_headers => 1, |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
) or return; |
289
|
0
|
|
0
|
|
|
|
my $version = $response->{etag} || q(); |
290
|
0
|
|
|
|
|
|
$version =~ s{"}{}gx; |
291
|
0
|
|
|
|
|
|
return $version; |
292
|
|
|
|
|
|
|
} ## end sub version |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
####################### |
295
|
|
|
|
|
|
|
# PRIVATE METHODS |
296
|
|
|
|
|
|
|
####################### |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
## ==================== |
299
|
|
|
|
|
|
|
## CREDITS |
300
|
|
|
|
|
|
|
## ==================== |
301
|
|
|
|
|
|
|
sub _credits { |
302
|
0
|
|
|
0
|
|
|
my $self = shift; |
303
|
0
|
|
|
|
|
|
return $self->session->talk( |
304
|
|
|
|
|
|
|
{ |
305
|
|
|
|
|
|
|
method => 'tv/' . $self->id() . '/credits', |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
); |
308
|
|
|
|
|
|
|
} ## end sub _credits |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
####################### |
311
|
|
|
|
|
|
|
1; |