@@ -62,14 +62,81 @@ public function get(object $page, string $element)
6262 return $ this ->strClean ($ poster );
6363 break ;
6464
65+ case "trailer " :
66+ $ trailerLink = $ page ->find ('.slate a[data-video] ' );
67+ $ trailerId = $ this ->count ($ trailerLink ) ? $ trailerLink ->getAttribute ("data-video " ) : "" ;
68+ $ trailerLink = $ this ->count ($ trailerId ) ? "https://www.imdb.com/videoplayer/ " .$ trailerId : "" ;
69+ return [
70+ "id " => $ trailerId ,
71+ "link " => $ trailerLink
72+ ];
73+ break ;
74+
75+ case "cast " :
76+ $ cast = [];
77+ $ findAllCast = $ dom ->find ($ page , 'table.cast_list tr ' );
78+ foreach ($ findAllCast as $ castRow )
79+ {
80+ if (count ($ castRow ->find ('.primary_photo ' )) === 0 ) {
81+ continue ;
82+ }
83+ $ actor = [];
84+
85+ $ characterLink = $ castRow ->find ('.character a ' );
86+ $ actor ["character " ] = count ($ characterLink ) ? $ characterLink ->text : $ dom ->find ($ castRow , '.character ' )->text ;
87+
88+ $ actorRow = $ castRow ->find ('td ' )[1 ];
89+ $ actorLink = $ actorRow ->find ('a ' );
90+ if (count ($ actorLink ) > 0 )
91+ {
92+ // Set actor name to text within link
93+ $ actor ["actor " ] = $ actorLink ->text ;
94+ $ actor ["actor_id " ] = $ this ->extractImdbId ($ actorLink ->href );
95+ } else
96+ {
97+ // No link found
98+ // Set actor name to whatever is there
99+ $ actor ["actor " ] = $ actorRow ->text ;
100+ }
101+
102+ $ actor ["character " ] = $ this ->strClean ($ actor ["character " ]);
103+ $ actor ["actor " ] = $ this ->strClean ($ actor ["actor " ]);
104+ $ actor ["actor_id " ] = $ this ->strClean ($ actor ["actor_id " ]);
105+
106+ array_push ($ cast , $ actor );
107+ }
108+ return $ cast ;
109+ break ;
110+
65111 default :
66112 return "" ;
67113 }
68114 }
69115
116+ /**
117+ * Extract an imdb-id from a string '/ttxxxxxxx/'
118+ * Returns string of id or empty string if none found
119+ *
120+ * @param string $str
121+ * @return string
122+ */
123+ private function extractImdbId ($ str )
124+ {
125+ // Search string for 2 letters followed by numbers
126+ // '/yyxxxxxxx'
127+ preg_match ('/\/[A-Za-z]{2}[0-9]+/ ' , $ str , $ imdbIds );
128+ $ id = substr ($ imdbIds [0 ], 1 );
129+ if ($ id == NULL )
130+ {
131+ $ id = "" ;
132+ }
133+ return $ id ;
134+ }
135+
70136 /**
71137 * Cleans-up string
72138 * -> removes white-space and html entitys
139+ * turns null into empty string
73140 *
74141 * @param $string
75142 * @return string
@@ -79,4 +146,14 @@ private function strClean($string)
79146 return empty ($ string ) ? "" : str_replace (chr (194 ).chr (160 ), '' , html_entity_decode (trim ($ string )));
80147 }
81148
149+ /**
150+ * Count (either array items or string length)
151+ *
152+ * @param array|string $item
153+ * @return string
154+ */
155+ private function count ($ item ) {
156+ return (is_array ($ item ) ? count ($ item ) : strlen ($ item ));
157+ }
158+
82159}
0 commit comments