@@ -115,6 +115,10 @@ public function film($query, $techSpecs=false) {
115115 "rating_votes " => "" ,
116116 "poster " => "" ,
117117 "plot " => "" ,
118+ "trailer " => [
119+ "id " => "" ,
120+ "link " => ""
121+ ],
118122 "cast " => [],
119123 "technical_specs " => []
120124 ];
@@ -149,12 +153,12 @@ public function film($query, $techSpecs=false) {
149153 // Load page
150154 $ film_page = $ this ->loadDom ($ film_url );
151155
152- $ response ["title " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.title_wrapper h1 ' )->text );
153- $ response ["year " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.title_wrapper h1 #titleYear a ' )->text );
154- $ response ["rating " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.ratings_wrapper .ratingValue strong span ' )->text );
155- $ response ["rating_votes " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.ratings_wrapper span[itemprop=ratingCount] ' )->text );
156- $ response ["length " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.subtext time ' )->text );
157- $ response ["plot " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.plot_summary .summary_text ' )->text );
156+ $ response ["title " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.title_wrapper h1 ' )->text );
157+ $ response ["year " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.title_wrapper h1 #titleYear a ' )->text );
158+ $ response ["rating " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.ratings_wrapper .ratingValue strong span ' )->text );
159+ $ response ["rating_votes " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.ratings_wrapper span[itemprop=ratingCount] ' )->text );
160+ $ response ["length " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.subtext time ' )->text );
161+ $ response ["plot " ] = $ this ->textClean ($ this ->htmlFind ($ film_page , '.plot_summary .summary_text ' )->text );
158162
159163 // If rating votes exists
160164 if ($ this ->count ($ response ["rating_votes " ]) > 0 )
@@ -164,14 +168,27 @@ public function film($query, $techSpecs=false) {
164168 }
165169
166170 // Get poster src
167- $ response ["poster " ] = $ this ->htmlFind ($ film_page , '.poster img ' )->src ;
171+ $ response ["poster " ] = $ this ->textClean ( $ this -> htmlFind ($ film_page , '.poster img ' )->src ) ;
168172 // If '@' appears in poster link
169173 if (preg_match ('/@/ ' , $ response ["poster " ]))
170174 {
171175 // Remove predetermined size to get original image
172176 $ response ["poster " ] = preg_split ('~@(?=[^@]*$)~ ' , $ response ["poster " ])[0 ] . "@.jpg " ;
173177 }
174178
179+ // Get trailer link
180+ $ trailer_link = $ film_page ->find ('.slate a[data-video] ' );
181+ // Check if trailer link exists
182+ if ($ this ->count ($ trailer_link ) > 0 )
183+ {
184+ // Get trailer id
185+ $ response ["trailer " ]["id " ] = $ this ->textClean ($ trailer_link ->getAttribute ("data-video " ));
186+ if (!empty ($ response ["trailer " ]["id " ]))
187+ {
188+ $ response ["trailer " ]["link " ] = "https://www.imdb.com/videoplayer/ " . $ response ["trailer " ]["id " ];
189+ }
190+ }
191+
175192
176193 // Get all cast list
177194 $ cast_list_all = $ film_page ->find ('table.cast_list tr ' );
@@ -306,7 +323,7 @@ private function htmlFind($dom, $selection) {
306323 */
307324 private function emptyDomElement () {
308325 $ dom = new Dom ;
309- $ dom ->load ('<a src="" href=""></a> ' );
326+ $ dom ->load ('<a src="" href="" data-video="" ></a> ' );
310327 return $ dom ;
311328 }
312329
@@ -358,7 +375,7 @@ private function extractImdbId($str) {
358375 * @return string
359376 */
360377 private function textClean ($ str ) {
361- return trim (html_entity_decode ($ str ));
378+ return empty ( $ str ) ? "" : trim (html_entity_decode ($ str ));
362379 }
363380
364381
0 commit comments