Skip to content

Commit e7ba7cc

Browse files
committed
Get technical specs from dom if true in user options
1 parent 11f01ed commit e7ba7cc

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/HtmlPieces.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HtmlPieces
1919
* @param string $element
2020
* @return string
2121
*/
22-
public function get(object $page, string $element)
22+
public function get(object $page, string $element, array $options = [])
2323
{
2424
// Initiate dom object
2525
// -> handles page scraping
@@ -87,13 +87,11 @@ public function get(object $page, string $element)
8787

8888
$actorRow = $castRow->find('td')[1];
8989
$actorLink = $actorRow->find('a');
90-
if (count($actorLink) > 0)
91-
{
90+
if (count($actorLink) > 0) {
9291
// Set actor name to text within link
9392
$actor["actor"] = $actorLink->text;
9493
$actor["actor_id"] = $this->extractImdbId($actorLink->href);
95-
} else
96-
{
94+
} else {
9795
// No link found
9896
// Set actor name to whatever is there
9997
$actor["actor"] = $actorRow->text;
@@ -108,6 +106,24 @@ public function get(object $page, string $element)
108106
return $cast;
109107
break;
110108

109+
case "technical_specs":
110+
$technical_specs = [];
111+
$table = $dom->find($page, '.dataTable tr');
112+
if (count($table) > 0) {
113+
foreach ($table as $row)
114+
{
115+
$row_title = $row->find('td')[0]->text(true);
116+
$row_value = str_replace(" ", " <br> ", $row->find('td')[1]->text(true));
117+
$row = [
118+
$this->strClean($row_title),
119+
$this->strClean($row_value)
120+
];
121+
array_push($technical_specs, $row);
122+
}
123+
}
124+
return $technical_specs;
125+
break;
126+
111127
default:
112128
return "";
113129
}

src/imdb.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ public function film(string $filmId, array $options = []): array
8080
$response->add("poster", $htmlPieces->get($page, "poster"));
8181
$response->add("trailer", $htmlPieces->get($page, "trailer"));
8282
$response->add("cast", $htmlPieces->get($page, "cast"));
83-
$response->add("technical_specs", $options["techSpecs"] ? $htmlPieces->get($page, "technical_specs") : "");
83+
84+
// Technical specs
85+
if ($options["techSpecs"]) {
86+
$page_techSpecs = $dom->fetch($this->baseUrl."title/".$filmId.'/technical', $options);
87+
$response->add("technical_specs", $htmlPieces->get($page_techSpecs, "technical_specs"));
88+
}
89+
else {
90+
$response->add("technical_specs", []);
91+
}
8492

8593
// Return the response $store
8694
return $response->return();

0 commit comments

Comments
 (0)