From a55c5d87dd70f224569e4fd631493354ce28bcd1 Mon Sep 17 00:00:00 2001 From: Lee Peuker Date: Sun, 3 Dec 2023 13:27:08 +0100 Subject: [PATCH] Update imdb rating scrapping with latest html changes --- src/Api/Imdb/ImdbWebScrapper.php | 14 +++---- tests/unit/Api/Imdb/ImdbWebScrapperTest.php | 46 ++++++++++----------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Api/Imdb/ImdbWebScrapper.php b/src/Api/Imdb/ImdbWebScrapper.php index 25c1cdb70..377e4430e 100644 --- a/src/Api/Imdb/ImdbWebScrapper.php +++ b/src/Api/Imdb/ImdbWebScrapper.php @@ -70,7 +70,7 @@ private function extractProductionStatus(string $imdbRatingPage) : ?string private function extractRatingAverage(string $imdbRatingPage, string $imdbId) : ?float { - preg_match('/iZlgcd">(\d([.,])\d)/', $imdbRatingPage, $averageRatingMatches); + preg_match('/cMEQkK">(\d([.,])\d)/', $imdbRatingPage, $averageRatingMatches); if (empty($averageRatingMatches[1]) === true) { $this->logger->warning('IMDb: Could not extract rating average.', ['url' => $this->urlGenerator->buildMovieUrl($imdbId)]); @@ -83,32 +83,32 @@ private function extractRatingAverage(string $imdbRatingPage, string $imdbId) : private function extractRatingVoteCount(string $imdbRatingPage, string $imdbId) : ?int { // Handle numbers without suffix - preg_match('/bjjENQ">([0-9]+)([0-9]+)([0-9]{1,3}([.,]?[0-9]{3})+)/', $imdbRatingPage, $voteCountMatches); + preg_match('/gPVQxL">([0-9]{1,3}([.,]?[0-9]{3})+)/', $imdbRatingPage, $voteCountMatches); if (empty($voteCountMatches[1]) === false) { return (int)str_replace([',', '.'], '', $voteCountMatches[1]); } // Handle numbers with K suffix - preg_match('/bjjENQ">([0-9]+)K([0-9]+)K([0-9]{1,3}[.,][0-9]{1,3})K([0-9]{1,3}[.,][0-9]{1,3})K([0-9]+)M([0-9]+)M([0-9]{1,3}[.,][0-9]{1,3})M([0-9]{1,3}[.,][0-9]{1,3})M7.9 - bjjENQ">229.240', + 'cMEQkK">7.9 + gPVQxL">229.240', ImdbRating::create(7.9, 229240) ], 'returns no rating if current production status is found' => [ 'hjAonB">Post-production - iZlgcd">7.9 - bjjENQ">229.240', + cMEQkK">7.9 + gPVQxL">229.240', null, ], [ - 'iZlgcd">7,9 - bjjENQ">229,240', + 'cMEQkK">7,9 + gPVQxL">229,240', ImdbRating::create(7.9, 229240) ], [ - 'iZlgcd">7,9 - bjjENQ">229240', + 'cMEQkK">7,9 + gPVQxL">229240', ImdbRating::create(7.9, 229240) ], [ - 'iZlgcd">7,9 - bjjENQ">1.229,240', + 'cMEQkK">7,9 + gPVQxL">1.229,240', ImdbRating::create(7.9, 1229240) ], [ - 'iZlgcd">7,9 - bjjENQ">40', + 'cMEQkK">7,9 + gPVQxL">40', ImdbRating::create(7.9, 40) ], [ - 'iZlgcd">7,9 - bjjENQ">40K', + 'cMEQkK">7,9 + gPVQxL">40K', ImdbRating::create(7.9, 40000) ], [ - 'iZlgcd">7,9 - bjjENQ">4.1K', + 'cMEQkK">7,9 + gPVQxL">4.1K', ImdbRating::create(7.9, 4100) ], [ - 'iZlgcd">7,9 - bjjENQ">14.12K', + 'cMEQkK">7,9 + gPVQxL">14.12K', ImdbRating::create(7.9, 14120) ], [ - 'iZlgcd">7,9 - bjjENQ">10M', + 'cMEQkK">7,9 + gPVQxL">10M', ImdbRating::create(7.9, 10000000) ], [ - 'iZlgcd">7,9 - bjjENQ">10.1M', + 'cMEQkK">7,9 + gPVQxL">10.1M', ImdbRating::create(7.9, 10100000) ], [ - 'iZlgcd">7,9', + 'cMEQkK">7,9', null ], [