1111class Imdb
1212{
1313
14- /**
15- * IMDB base url
16- *
17- * @var string
18- */
19- protected $ baseUrl = 'https://www.imdb.com/ ' ;
20-
2114 /**
2215 * Returns default options combined with any user options
2316 *
@@ -66,8 +59,8 @@ public function film(string $filmId, array $options = []): array
6659 // -> handles finding specific content from the dom
6760 $ htmlPieces = new HtmlPieces ;
6861
69- // Load imdb page and parse the dom
70- $ page = $ dom ->fetch ($ this -> baseUrl . " title/ " .$ filmId , $ options );
62+ // Load imdb film page and parse the dom
63+ $ page = $ dom ->fetch (" https://www.imdb.com/ title/ " .$ filmId , $ options );
7164
7265 // Add all film data to response $store
7366 $ response ->add ("id " , $ filmId );
@@ -81,9 +74,10 @@ public function film(string $filmId, array $options = []): array
8174 $ response ->add ("trailer " , $ htmlPieces ->get ($ page , "trailer " ));
8275 $ response ->add ("cast " , $ htmlPieces ->get ($ page , "cast " ));
8376
84- // Technical specs
77+ // If techSpecs is enabled in user $options
78+ // -> Make a second request to load the full techSpecs page
8579 if ($ options ["techSpecs " ]) {
86- $ page_techSpecs = $ dom ->fetch ($ this -> baseUrl . " title/ " . $ filmId. ' /technical ' , $ options );
80+ $ page_techSpecs = $ dom ->fetch (" https://www.imdb.com/title/ $ filmId/technical " , $ options );
8781 $ response ->add ("technical_specs " , $ htmlPieces ->get ($ page_techSpecs , "technical_specs " ));
8882 }
8983 else {
@@ -109,9 +103,21 @@ public function search(string $search, array $options = []): array
109103 // -> handles what the api returns
110104 $ response = new Response ;
111105
112- $ response ->add ("titles " , []);
113- $ response ->add ("names " , []);
114- $ response ->add ("companies " , []);
106+ // Initiate dom object
107+ // -> handles page scraping
108+ $ dom = new Dom ;
109+
110+ // Initiate html-pieces object
111+ // -> handles finding specific content from the dom
112+ $ htmlPieces = new HtmlPieces ;
113+
114+ // Load imdb search page and parse the dom
115+ $ page = $ dom ->fetch ("https://www.imdb.com/find?q= $ search&s=all " , $ options );
116+
117+ // Add all search data to response $store
118+ $ response ->add ("titles " , $ htmlPieces ->get ($ page , "titles " ));
119+ $ response ->add ("names " , $ htmlPieces ->get ($ page , "names " ));
120+ $ response ->add ("companies " , $ htmlPieces ->get ($ page , "companies " ));
115121
116122 return $ response ->return ();
117123 }
0 commit comments