@@ -22,6 +22,7 @@ private function populateOptions(array $options = []): array
2222 // Default options
2323 $ defaults = [
2424 'cache ' => true ,
25+ 'category ' => 'all ' ,
2526 'curlHeaders ' => ['Accept-Language: en-US,en;q=0.5 ' ],
2627 'techSpecs ' => true ,
2728 ];
@@ -59,6 +60,23 @@ public function film(string $filmId, array $options = []): array
5960 // -> handles finding specific content from the dom
6061 $ htmlPieces = new HtmlPieces ;
6162
63+ // Check for 'tt' at start of $filmId
64+ if (substr ($ filmId , 0 , 2 ) !== "tt " )
65+ {
66+ // Search $filmId and use first result
67+ $ search_film = $ this ->search ($ filmId , [ "category " => "tt " ]);
68+ if ($ htmlPieces ->count ($ search_film ["titles " ]) > 0 )
69+ {
70+ // Use first film returned from search
71+ $ filmId = $ search_film ["titles " ][0 ]["id " ];
72+ } else
73+ {
74+ // No film found
75+ // -> return default (empty) response
76+ return $ response ->default ('film ' );
77+ }
78+ }
79+
6280 // Load imdb film page and parse the dom
6381 $ page = $ dom ->fetch ("https://www.imdb.com/title/ " .$ filmId , $ options );
6482
@@ -112,7 +130,7 @@ public function search(string $search, array $options = []): array
112130 $ htmlPieces = new HtmlPieces ;
113131
114132 // Load imdb search page and parse the dom
115- $ page = $ dom ->fetch ("https://www.imdb.com/find?q= $ search&s=all " , $ options );
133+ $ page = $ dom ->fetch ("https://www.imdb.com/find?q= $ search&s= " . $ options [ " category " ] , $ options );
116134
117135 // Add all search data to response $store
118136 $ response ->add ("titles " , $ htmlPieces ->get ($ page , "titles " ));
0 commit comments