-
Notifications
You must be signed in to change notification settings - Fork 0
/
Title.php
executable file
·2994 lines (2853 loc) · 106 KB
/
Title.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
#############################################################################
# imdbGraphQLPHP ed (github user: duck7000) #
# written by Giorgos Giagas #
# written extended & maintained by ed (github user: duck7000) #
# extended & maintained by Itzchak Rehberg <izzysoft AT qumran DOT org> #
# http://www.izzysoft.de/ #
# ------------------------------------------------------------------------- #
# This program is free software; you can redistribute and/or modify it #
# under the terms of the GNU General Public License (see doc/LICENSE) #
#############################################################################
namespace Imdb;
use Psr\SimpleCache\CacheInterface;
/**
* A title on IMDb
* @author Georgos Giagas
* @author Izzy (izzysoft AT qumran DOT org)
* @author Ed
* @copyright (c) 2002-2004 by Giorgos Giagas and (c) 2004-2009 by Itzchak Rehberg and IzzySoft
*/
class Title extends MdbBase
{
protected $akas = array();
protected $releaseDates = array();
protected $countries = array();
protected $creditsCast = array();
protected $creditsPrincipal = array();
protected $creditsComposer = array();
protected $creditsStunts = array();
protected $creditsThanks = array();
protected $creditsVisualEffects = array();
protected $creditsSpecialEffects = array();
protected $creditsDirector = array();
protected $creditsProducer = array();
protected $creditsWriter = array();
protected $creditsCinematographer = array();
protected $languages = array();
protected $keywords = array();
protected $mainPoster = "";
protected $mainPosterThumb = "";
protected $mainPlotoutline = "";
protected $mainMovietype = "";
protected $mainTitle = "";
protected $mainOriginalTitle = "";
protected $mainYear = -1;
protected $mainEndYear = -1;
protected $mainTop250 = -1;
protected $mainRating = -1;
protected $mainRank = array();
protected $mainPhoto = array();
protected $trailers = array();
protected $mainAwards = array();
protected $awards = array();
protected $genres = array();
protected $quotes = array();
protected $recommendations = array();
protected $runtimes = array();
protected $mpaas = array();
protected $plot = array();
protected $seasonEpisodes = array();
protected $isOngoing = null;
protected $soundtracks = array();
protected $taglines = array();
protected $trivias = array();
protected $goofs = array();
protected $crazyCredits = array();
protected $locations = array();
protected $compCreditsProd = array();
protected $compCreditsDist = array();
protected $compCreditsSpecial = array();
protected $compCreditsOther = array();
protected $connections = array();
protected $externalSites = array();
protected $productionBudget = array();
protected $grosses = array();
protected $alternateversions = array();
protected $soundMix = array();
protected $colors = array();
protected $aspectRatio = array();
protected $cameras = array();
protected $featuredReviews = array();
protected $faqs = array();
/**
* @param string $id IMDb ID. e.g. 285331 for https://www.imdb.com/title/tt0285331/
* @param Config $config OPTIONAL override default config
* @param LoggerInterface $logger OPTIONAL override default logger `\Imdb\Logger` with a custom one
* @param CacheInterface $cache OPTIONAL override the default cache with any PSR-16 cache.
*/
public function __construct($id, Config $config = null, LoggerInterface $logger = null, CacheInterface $cache = null)
{
parent::__construct($config, $logger, $cache);
$this->setid($id);
}
#-------------------------------------------------------------[ Title ]---
/** Get movie type
* @return string movietype (TV Series, Movie, TV Episode, TV Special, TV Movie, TV Mini Series, Video Game, TV Short, Video)
* @see IMDB page / (TitlePage)
* If no movietype has been defined explicitly, it returns 'Movie' -- so this is always set.
*/
public function movietype()
{
if (empty($this->mainMovietype)) {
$this->titleYear();
if (empty($this->mainMovietype)) {
$this->mainMovietype = 'Movie';
}
}
return $this->mainMovietype;
}
/** Get movie title
* @return string title movie title (name)
* @see IMDB page / (TitlePage)
*/
public function title()
{
if ($this->mainTitle == "") {
$this->titleYear();
}
return $this->mainTitle;
}
/** Get movie original title
* @return string mainOriginalTitle movie original title
* @see IMDB page / (TitlePage)
*/
public function originalTitle()
{
if ($this->mainOriginalTitle == "") {
$this->titleYear();
}
return $this->mainOriginalTitle ;
}
/** Get year
* @return string year
* @see IMDB page / (TitlePage)
*/
public function year()
{
if ($this->mainYear == -1) {
$this->titleYear();
}
return $this->mainYear;
}
/** Get end-year
* if production spanned multiple years, usually for series
* @return int endyear|null
* @see IMDB page / (TitlePage)
*/
public function endyear()
{
if ($this->mainEndYear == -1) {
$this->titleYear();
}
return $this->mainEndYear;
}
#---------------------------------------------------------------[ Runtime ]---
/**
* Retrieve all runtimes and their descriptions
* @return array<array{time: integer, country: string|null, annotations: array()}>
* time is the length in minutes, country optionally exists for alternate cuts, annotations is an array of comments
*/
public function runtime()
{
if (empty($this->runtimes)) {
$query = <<<EOF
query Runtimes(\$id: ID!) {
title(id: \$id) {
runtimes(first: 9999) {
edges {
node {
attributes {
text
}
country {
text
}
seconds
}
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Runtimes", ["id" => "tt$this->imdbID"]);
foreach ($data->title->runtimes->edges as $edge) {
$this->runtimes[] = array(
"time" => $edge->node->seconds / 60,
"annotations" => array_map(function ($attribute) {
return $attribute->text;
}, $edge->node->attributes),
"country" => isset($edge->node->country->text) ? $edge->node->country->text : null
);
}
}
return $this->runtimes;
}
#----------------------------------------------------------[ Movie Rating ]---
/**
* Get movie rating
* @return int/float or 0
* @see IMDB page / (TitlePage)
*/
public function rating()
{
if ($this->mainRating == -1) {
$query = <<<EOF
query Rating(\$id: ID!) {
title(id: \$id) {
ratingsSummary {
aggregateRating
}
}
}
EOF;
$data = $this->graphql->query($query, "Rating", ["id" => "tt$this->imdbID"]);
if (isset($data->title->ratingsSummary->aggregateRating) && !empty($data->title->ratingsSummary->aggregateRating)) {
$this->mainRating = $data->title->ratingsSummary->aggregateRating;
} else {
$this->mainRating = 0;
}
}
return $this->mainRating;
}
/**
* Return number of votes for this movie
* @return int or 0
* @see IMDB page / (TitlePage)
*/
public function votes()
{
$query = <<<EOF
query RatingVotes(\$id: ID!) {
title(id: \$id) {
ratingsSummary {
voteCount
}
}
}
EOF;
$data = $this->graphql->query($query, "RatingVotes", ["id" => "tt$this->imdbID"]);
if (isset($data->title->ratingsSummary->voteCount) && !empty($data->title->ratingsSummary->voteCount)) {
return $data->title->ratingsSummary->voteCount;
} else {
return 0;
}
}
/**
* Rating out of 100 on metacritic
* @return int|0
*/
public function metacritic()
{
$query = <<<EOF
query Metacritic(\$id: ID!) {
title(id: \$id) {
metacritic {
metascore {
score
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Metacritic", ["id" => "tt$this->imdbID"]);
if (isset($data->title->metacritic->metascore->score)) {
if ($data->title->metacritic !== null) {
return $data->title->metacritic->metascore->score;
} else {
return 0;
}
} else {
return 0;
}
}
#----------------------------------------------------------[ Popularity ]---
/**
* Get movie popularity rank
* @return array(currentRank: int, changeDirection: enum (string?), difference: int)
* @see IMDB page / (TitlePage)
*/
public function rank()
{
if (empty($this->mainRank)) {
$query = <<<EOF
query Rank(\$id: ID!) {
title(id: \$id) {
meterRanking {
currentRank
rankChange {
changeDirection
difference
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Rank", ["id" => "tt$this->imdbID"]);
if (isset($data->title->meterRanking)) {
$this->mainRank['currentRank'] = isset($data->title->meterRanking->currentRank) ?
$data->title->meterRanking->currentRank : null;
$this->mainRank['changeDirection'] = isset($data->title->meterRanking->rankChange->changeDirection) ?
$data->title->meterRanking->rankChange->changeDirection : null;
$this->mainRank['difference'] = isset($data->title->meterRanking->rankChange->difference) ?
$data->title->meterRanking->rankChange->difference : null;
} else {
return $this->mainRank;
}
}
return $this->mainRank;
}
#----------------------------------------------------------[ FAQ ]---
/**
* Get movie frequently asked questions, it includes questions with and without answer
* @param $spoil boolean (true or false) to include spoilers or not, isSpoiler indicates if this question is spoiler or not
* @return array of array(question: string, answer: string, isSpoiler: boolean)
* @see IMDB page / (Faq)
*/
public function faq($spoil = false)
{
if (empty($this->faqs)) {
$filter = $spoil === false ? ', filter: {spoilers: EXCLUDE_SPOILERS}' : '';
$query = <<<EOF
question {
plainText
}
answer {
plainText
}
isSpoiler
EOF;
$data = $this->graphQlGetAll("Faq", "faqs", $query, $filter);
if ($data != null) {
foreach ($data as $edge) {
$this->faqs[] = array(
'question' => isset($edge->node->question->plainText) ? $edge->node->question->plainText : '',
'answer' => isset($edge->node->answer->plainText) ? $edge->node->answer->plainText : '',
'isSpoiler' => $edge->node->isSpoiler
);
}
} else {
return $this->faqs;
}
}
return $this->faqs;
}
#-------------------------------------------------------[ Recommendations ]---
/**
* Get recommended movies (People who liked this...also liked)
* @return array<array{title: string, imdbid: number, rating: string| null, img: string|'', year: number|null}>
* @see IMDB page / (TitlePage)
*/
public function recommendation()
{
if (empty($this->recommendations)) {
$query = <<<EOF
query Recommendations(\$id: ID!) {
title(id: \$id) {
moreLikeThisTitles(first: 12) {
edges {
node {
id
titleText {
text
}
ratingsSummary {
aggregateRating
}
primaryImage {
url
width
height
}
releaseYear {
year
}
}
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Recommendations", ["id" => "tt$this->imdbID"]);
foreach ($data->title->moreLikeThisTitles->edges as $edge) {
$thumb = '';
if (isset($edge->node->primaryImage->url) && $edge->node->primaryImage->url != null) {
$fullImageWidth = $edge->node->primaryImage->width;
$fullImageHeight = $edge->node->primaryImage->height;
$newImageWidth = 140;
$newImageHeight = 207;
$img = str_replace('.jpg', '', $edge->node->primaryImage->url);
$parameter = $this->resultParameter($fullImageWidth, $fullImageHeight, $newImageWidth, $newImageHeight);
$thumb = $img . $parameter;
}
$this->recommendations[] = array(
"title" => $edge->node->titleText->text,
"imdbid" => str_replace('tt', '', $edge->node->id),
"rating" => isset($edge->node->ratingsSummary->aggregateRating) ? $edge->node->ratingsSummary->aggregateRating : null,
"img" => $thumb,
"year" => isset($edge->node->releaseYear->year) ? $edge->node->releaseYear->year : null
);
}
}
return $this->recommendations;
}
#--------------------------------------------------------[ Language Stuff ]---
/** Get all spoken languages spoken in this title
* @return array languages (array[0..n] of strings)
* @see IMDB page / (TitlePage)
*/
public function language()
{
if (empty($this->languages)) {
$query = <<<EOF
query Languages(\$id: ID!) {
title(id: \$id) {
spokenLanguages {
spokenLanguages {
text
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Languages", ["id" => "tt$this->imdbID"]);
if (isset($data->title->spokenLanguages->spokenLanguages)) {
foreach ($data->title->spokenLanguages->spokenLanguages as $language) {
$this->languages[] = $language->text;
}
}
return $this->languages;
}
}
#--------------------------------------------------------------[ Genre(s) ]---
/** Get all genres the movie is registered for
* @return array genres (array[0..n] of mainGenre| string, subGenre| array())
* @see IMDB page / (TitlePage)
*/
public function genre()
{
if (empty($this->genres)) {
$query = <<<EOF
query Genres(\$id: ID!) {
title(id: \$id) {
titleGenres {
genres {
genre {
text
}
subGenres {
keyword {
text {
text
}
}
}
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Genres", ["id" => "tt$this->imdbID"]);
if (isset($data->title->titleGenres->genres) && !empty($data->title->titleGenres->genres)) {
foreach ($data->title->titleGenres->genres as $edge) {
$subGenres = array();
if (isset($edge->subGenres) && !empty($edge->subGenres)) {
foreach ($edge->subGenres as $subGenre) {
$subGenres[] = $subGenre->keyword->text->text;
}
}
$this->genres[] = array(
'mainGenre' => $edge->genre->text,
'subGenre' => $subGenres
);
}
}
}
return $this->genres;
}
#--------------------------------------------------------[ Plot (Outline) ]---
/** Get the main Plot outline for the movie as displayed on top of title page
* @return string plotoutline
* @see IMDB page / (TitlePage)
*/
public function plotoutline()
{
if ($this->mainPlotoutline == "") {
$query = <<<EOF
query PlotOutline(\$id: ID!) {
title(id: \$id) {
plot {
plotText {
plainText
}
}
}
}
EOF;
$data = $this->graphql->query($query, "PlotOutline", ["id" => "tt$this->imdbID"]);
if (isset($data->title->plot->plotText->plainText)) {
$this->mainPlotoutline = $data->title->plot->plotText->plainText;
}
}
return $this->mainPlotoutline;
}
#--------------------------------------------------------[ Photo specific ]---
/**
* Get the main photo image url for thumbnail or full size
* @param boolean $thumb get the thumbnail (height: 281) or large (max 1000 pixels)
* @return string|false photo (string URL if found, FALSE otherwise)
* @see IMDB page / (TitlePage)
*/
public function photo($thumb = true)
{
if (empty($this->mainPoster)) {
$this->populatePoster();
}
if (!$thumb && empty($this->mainPoster)) {
return false;
}
if ($thumb && empty($this->mainPosterThumb)) {
return false;
}
if ($thumb) {
return $this->mainPosterThumb;
}
return $this->mainPoster;
}
#-------------------------------------------------[ Country of Origin ]---
/**
* Get country of origin
* @return array country (array[0..n] of string)
* @see IMDB page / (TitlePage)
*/
public function country()
{
if (empty($this->countries)) {
$query = <<<EOF
query Countries(\$id: ID!) {
title(id: \$id) {
countriesOfOrigin {
countries {
text
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Countries", ["id" => "tt$this->imdbID"]);
if ($data->title->countriesOfOrigin != null) {
foreach ($data->title->countriesOfOrigin->countries as $country) {
$this->countries[] = $country->text;
}
}
}
return $this->countries;
}
#-------------------------------------------------[ Release dates ]---
/**
* Get all release dates for this title
* @return releaseDates array[0..n] of array[country, day, month, year, array attributes]
* @see IMDB page / (TitlePage)
*/
public function releaseDate()
{
if (empty($this->releaseDates)) {
$query = <<<EOF
country {
text
}
day
month
year
attributes {
text
}
EOF;
$data = $this->graphQlGetAll("ReleaseDates", "releaseDates", $query);
if ($data != null) {
foreach ($data as $edge) {
$country = isset($edge->node->country->text) ? $edge->node->country->text : '';
$attributes = array();
if ($edge->node->attributes != null) {
foreach ($edge->node->attributes as $attribute) {
$attributes[] = $attribute->text;
}
}
$this->releaseDates[] = array(
'country' => $country,
'day' => $edge->node->day,
'month' => $edge->node->month,
'year' => $edge->node->year,
'attributes' => $attributes
);
}
}
}
return $this->releaseDates;
}
#------------------------------------------------------------[ Movie AKAs ]---
/**
* Get movie's alternative names
* The first item in the list will be the original title
* @return array<array{title: string, country: string, countryId: string, language: string, languageId: string, comment: array()}>
* Ordered Ascending by Country
* @see IMDB page ReleaseInfo
*/
public function alsoknow()
{
if (empty($this->akas)) {
$filter = ', sort: {order: ASC by: COUNTRY}';
$query = <<<EOF
country {
id
text
}
text
attributes {
text
}
language {
id
text
}
EOF;
$data = $this->graphQlGetAll("AlsoKnow", "akas", $query, $filter);
$originalTitle = $this->originalTitle();
if (!empty($originalTitle)) {
$this->akas[] = array(
'title' => ucwords($originalTitle),
'country' => "(Original Title)",
'countryId' => null,
'language' => null,
'languageId' => null,
'comment' => array()
);
}
foreach ($data as $edge) {
$comments = array();
foreach ($edge->node->attributes as $attribute) {
if (isset($attribute->text) && $attribute->text != '') {
$comments[] = $attribute->text;
}
}
$this->akas[] = array(
'title' => ucwords($edge->node->text),
'country' => isset($edge->node->country->text) ? ucwords($edge->node->country->text) : 'Unknown',
'countryId' => isset($edge->node->country->id) ? $edge->node->country->id : null,
'language' => isset($edge->node->language->text) ? ucwords($edge->node->language->text) : null,
'languageId' => isset($edge->node->language->id) ? $edge->node->language->id : null,
'comment' => $comments
);
}
}
return $this->akas;
}
#-------------------------------------------------------[ MPAA / PG / FSK ]---
/**
* Get the MPAA rating / Parental Guidance / Age rating for this title by country
* @return array array[0..n] of array[country,rating,comment of array()] comment whithout brackets
* @see IMDB Parental Guidance page / (parentalguide)
*/
public function mpaa()
{
if (empty($this->mpaas)) {
$query = <<<EOF
country {
text
}
rating
attributes {
text
}
EOF;
$data = $this->graphQlGetAll("Mpaa", "certificates", $query);
foreach ($data as $edge) {
$comments = array();
foreach ($edge->node->attributes as $key => $attribute) {
if (isset($attribute->text) && $attribute->text != '') {
$comments[] = $attribute->text;
}
}
$this->mpaas[] = array(
"country" => isset($edge->node->country->text) ? $edge->node->country->text : '',
"rating" => isset($edge->node->rating) ? $edge->node->rating : '',
"comment" => $comments
);
}
}
return $this->mpaas;
}
#----------------------------------------------[ Position in the "Top250" ]---
/**
* Find the position of a movie or tv show in the top 250 ranked movies or tv shows
* @return int position a number between 1..250 if ranked, 0 otherwise
* @author Ed
*/
public function top250()
{
if ($this->mainTop250 == -1) {
$query = <<<EOF
query TopRated(\$id: ID!) {
title(id: \$id) {
ratingsSummary {
topRanking {
rank
}
}
}
}
EOF;
$data = $this->graphql->query($query, "TopRated", ["id" => "tt$this->imdbID"]);
if (isset($data->title->ratingsSummary->topRanking->rank) && $data->title->ratingsSummary->topRanking->rank <= 250) {
$this->mainTop250 = $data->title->ratingsSummary->topRanking->rank;
} else {
$this->mainTop250 = 0;
}
}
return $this->mainTop250;
}
#=====================================================[ /plotsummary page ]===
/** Get movie plots without Spoilers
* @return array array[0..n] string plot, string author]
* @see IMDB page /plotsummary
*/
public function plot()
{
if (empty($this->plot)) {
$query = <<<EOF
query Plots(\$id: ID!) {
title(id: \$id) {
plots(first: 9999, filter: {spoilers: EXCLUDE_SPOILERS}) {
edges {
node {
author
plotText {
plainText
}
}
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Plots", ["id" => "tt$this->imdbID"]);
foreach ($data->title->plots->edges as $key => $edge) {
$this->plot[] = array(
'plot' => $edge->node->plotText->plainText,
'author' => isset($edge->node->author) ? $edge->node->author : ''
);
}
}
return $this->plot;
}
#========================================================[ /taglines page ]===
/**
* Get all available taglines for the movie
* @return string[] taglines
* @see IMDB page /taglines
*/
public function tagline()
{
if (empty($this->taglines)) {
$query = <<<EOF
query Taglines(\$id: ID!) {
title(id: \$id) {
taglines(first: 9999) {
edges {
node {
text
}
}
}
}
}
EOF;
$data = $this->graphql->query($query, "Taglines", ["id" => "tt$this->imdbID"]);
foreach ($data->title->taglines->edges as $edge) {
$this->taglines[] = $edge->node->text;
}
}
return $this->taglines;
}
#=====================================================[ /fullcredits page ]===
#----------------------------------------------------------------[ PrincipalCredits ]---
/*
* Get the PrincipalCredits for this title
* @return array creditsPrincipal[category][Director, Writer, Creator, Stars] (array[0..n] of array[name,imdbid])
* Not all categories are always available, TV series has Creator instead of writer
*/
public function principalCredits()
{
if (empty($this->creditsPrincipal)) {
$query = <<<EOF
query PrincipalCredits(\$id: ID!) {
title(id: \$id) {
principalCredits {
credits {
name {
nameText {
text
}
id
}
category {
text
}
}
}
}
}
EOF;
$data = $this->graphql->query($query, "PrincipalCredits", ["id" => "tt$this->imdbID"]);
foreach ($data->title->principalCredits as $value){
$cat = $value->credits[0]->category->text;
if ($cat == "Actor" || $cat == "Actress") {
$category = "Star";
} else {
$category = $cat;
}
$temp = array();
foreach ($value->credits as $key => $credit) {
$temp[] = array(
'name' => isset($credit->name->nameText->text) ? $credit->name->nameText->text : '',
'imdbid' => isset($credit->name->id) ? str_replace('nm', '', $credit->name->id) : ''
);
if ($key == 2) {
break;
}
}
$this->creditsPrincipal[$category] = $temp;
}
}
return $this->creditsPrincipal;
}
#----------------------------------------------------------------[ Actors]---
/*
* Get the actors/cast members for this title
* @return array cast (array[0..n] of array[imdb,name,name_alias,credited,array character,array comments,thumb])
* e.g.
* <pre>
* array (
* 'imdb' => '0922035',
* 'name' => 'Dominic West', // Actor's name on imdb,
* 'name_alias' => alias name (as D west),
* 'credited' => true\false False if stated (uncredited),
* 'character' => array "Det. James 'Jimmy' McNulty",
* 'comment' => array comments like archive voice etc,
* 'thumb' => 'https://ia.media-imdb.com/images/M/MV5BMTY5NjQwNDY2OV5BMl5BanBnXkFtZTcwMjI2ODQ1MQ@@._V1_SY44_CR0,0,32,44_AL_.jpg',
* )
* </pre>
* @see IMDB page /fullcredits
*/
public function cast()
{
if (!empty($this->creditsCast)) {
return $this->creditsCast;
}
$filter = ', filter: { categories: ["cast"] }';
$query = <<<EOF
name {
nameText {
text
}
id
primaryImage {
url
width
height
}
}
... on Cast {
characters {
name
}
attributes {
text
}
}
EOF;
$data = $this->graphQlGetAll("CreditQuery", "credits", $query, $filter);
foreach ($data as $edge) {
$name = isset($edge->node->name->nameText->text) ? $edge->node->name->nameText->text : '';
$imdb = isset($edge->node->name->id) ? str_replace('nm', '', $edge->node->name->id) : '';
// character
$castCharacters = array();
if ($edge->node->characters != null) {
foreach ($edge->node->characters as $keyCharacters => $character) {
$castCharacters[] = $character->name;
}
}
// comment, name_alias and credited
$comments = array();
$name_alias = null;
$credited = true;
if ($edge->node->attributes != null) {
foreach ($edge->node->attributes as $keyAttributes => $attribute) {
if (strpos($attribute->text, "as ") !== false) {
$name_alias = trim(ltrim($attribute->text, "as"));
} elseif (stripos($attribute->text, "uncredited") !== false) {
$credited = false;
} else {
$comments[] = $attribute->text;
}
}
}
// image url
$imgUrl = '';
if (isset($edge->node->name->primaryImage->url) && $edge->node->name->primaryImage->url != null) {
$fullImageWidth = $edge->node->name->primaryImage->width;
$fullImageHeight = $edge->node->name->primaryImage->height;
$newImageWidth = 32;
$newImageHeight = 44;
$img = str_replace('.jpg', '', $edge->node->name->primaryImage->url);
$parameter = $this->resultParameter($fullImageWidth, $fullImageHeight, $newImageWidth, $newImageHeight);
$imgUrl = $img . $parameter;
}
$this->creditsCast[] = array(
'imdb' => $imdb,
'name' => $name,
'name_alias' => $name_alias,
'credited' => $credited,
'character' => $castCharacters,
'comment' => $comments,
'thumb' => $imgUrl
);
}
return $this->creditsCast;
}
#-------------------------------------------------------------[ Directors ]---
/**
* Get the director(s) of the movie
* @return array director (array[0..n] of arrays[imdb,name,jobs[],attributes[],episode array(total, year, endYear)])
* @see IMDB page /fullcredits
*/
public function director()
{
if (!empty($this->creditsDirector)) {
return $this->creditsDirector;
}
$directorData = $this->creditHelper($this->creditsQuery("director"));
return $this->creditsDirector = $directorData;
}
#-------------------------------------------------------------[ Cinematographers ]---
/**
* Get the cinematographer of the title
* @return array creditsCinematographer (array[0..n] of arrays[imdb,name,jobs[],attributes[],episode array(total, year, endYear)])
* @see IMDB page /fullcredits
*/
public function cinematographer()
{
if (!empty($this->creditsCinematographer)) {
return $this->creditsCinematographer;
}
$cinematographerData = $this->creditHelper($this->creditsQuery("cinematographer"));
return $this->creditsCinematographer = $cinematographerData;
}