From a3a17adc7eee26cf7ebbe41d20a474a6d0fd2e9b Mon Sep 17 00:00:00 2001 From: Irfan Date: Thu, 23 Jul 2020 02:26:02 +0500 Subject: [PATCH] Bug fixes [ci skip] --- src/Model/Anime/AnimeReview.php | 7 ++++++- src/Model/Manga/MangaReview.php | 11 +++++++++-- src/Parser/Anime/AnimeReviewParser.php | 6 +++--- src/Parser/Manga/MangaReviewParser.php | 10 ++++++---- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Model/Anime/AnimeReview.php b/src/Model/Anime/AnimeReview.php index 7f5abc78..ff29e0b4 100644 --- a/src/Model/Anime/AnimeReview.php +++ b/src/Model/Anime/AnimeReview.php @@ -13,6 +13,10 @@ */ class AnimeReview extends \Jikan\Model\Reviews\AnimeReview { + /** + * @var string + */ + private $title; /** * @var AnimeReviewer @@ -33,9 +37,10 @@ public static function fromParser(AnimeReviewParser $parser): AnimeReview { $instance = new self(); + $instance->images = CommonImageResource::factory($parser->getImageUrl()); + $instance->title = $parser->getTitle(); $instance->malId = $parser->getId(); $instance->url = $parser->getUrl(); - $instance->images = CommonImageResource::factory($parser->getImageUrl()); $instance->type = $parser->getType(); $instance->votes = $parser->getHelpfulCount(); $instance->date = $parser->getDate(); diff --git a/src/Model/Manga/MangaReview.php b/src/Model/Manga/MangaReview.php index 33dfbae4..19b2bef0 100644 --- a/src/Model/Manga/MangaReview.php +++ b/src/Model/Manga/MangaReview.php @@ -2,6 +2,7 @@ namespace Jikan\Model\Manga; +use Jikan\Model\Resource\CommonImageResource\CommonImageResource; use Jikan\Parser\Manga\MangaReviewParser; /** @@ -16,6 +17,11 @@ class MangaReview extends \Jikan\Model\Reviews\MangaReview */ private $reviewer; + /** + * @var CommonImageResource + */ + private $images; + /** * Create an instance from an MangaReviewParser parser * @@ -30,14 +36,15 @@ public static function fromParser(MangaReviewParser $parser): MangaReview { $instance = new self(); + $instance->images = CommonImageResource::factory($parser->getImageUrl()); $instance->malId = $parser->getId(); $instance->url = $parser->getUrl(); $instance->type = $parser->getType(); - $instance->helpfulCount= $parser->getHelpfulCount(); + $instance->votes = $parser->getHelpfulCount(); $instance->date = $parser->getDate(); $instance->reviewer = $parser->getReviewer(); $instance->scores = $parser->getMangaScores(); - $instance->content = $parser->getContent(); + $instance->review = $parser->getContent(); return $instance; } diff --git a/src/Parser/Anime/AnimeReviewParser.php b/src/Parser/Anime/AnimeReviewParser.php index f8fd5605..f1100c0d 100644 --- a/src/Parser/Anime/AnimeReviewParser.php +++ b/src/Parser/Anime/AnimeReviewParser.php @@ -69,7 +69,7 @@ public function getUrl(): string public function getTitle(): string { return $this->crawler - ->filterXPath('//div[1]/div[3]/div/div/a') + ->filterXPath('//div[1]/div[1]/div[2]/strong/a') ->text(); } @@ -84,14 +84,14 @@ public function getImageUrl(): string ->filterXPath('//div[12]/div[1]/div[1]/a/img'); if ($node->count()) { - return $node->attr('data-src'); + return Parser::parseImageQuality($node->attr('data-src')); } // Recent Reviews page $node = $this->crawler ->filterXPath('//div[1]/div[2]/div[1]/div[1]/a/img'); - return $node->attr('data-src'); + return Parser::parseImageQuality($node->attr('data-src')); } /** diff --git a/src/Parser/Manga/MangaReviewParser.php b/src/Parser/Manga/MangaReviewParser.php index 8a34564f..428c3500 100644 --- a/src/Parser/Manga/MangaReviewParser.php +++ b/src/Parser/Manga/MangaReviewParser.php @@ -174,7 +174,7 @@ public function getType(): ?string public function getTitle(): string { return $this->crawler - ->filterXPath('//div[1]/div[3]/div/div/a') + ->filterXPath('//div[1]/div[1]/div[2]/strong/a') ->text(); } @@ -189,13 +189,15 @@ public function getImageUrl(): string ->filterXPath('//div[12]/div[1]/div[1]/a/img'); if ($node->count()) { - return $node->attr('data-src'); + return Parser::parseImageQuality($node->attr('data-src')); } - // Recent Reviews page + // Recent Reviews Anime page $node = $this->crawler ->filterXPath('//div[1]/div[2]/div[1]/div[1]/a/img'); - return $node->attr('data-src'); + if ($node->count()) { + return Parser::parseImageQuality($node->attr('data-src')); + } } }