Skip to content

Commit

Permalink
company: add resource links #538
Browse files Browse the repository at this point in the history
  • Loading branch information
irfan-dahir committed Oct 17, 2023
1 parent 561cf86 commit 40d797d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/Parser/Common/UrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jikan\Parser\Common;

use Jikan\Helper\JString;
use Jikan\Model\Common\Url;
use Symfony\Component\DomCrawler\Crawler;

Expand All @@ -15,7 +16,7 @@ class UrlParser
/**
* @var Crawler
*/
private $crawler;
private Crawler $crawler;

/**
* MalUrlParser constructor.
Expand All @@ -34,8 +35,8 @@ public function __construct(Crawler $crawler)
public function getModel(): Url
{
return new Url(
$this->crawler->text(),
$this->crawler->attr('href')
JString::cleanse($this->crawler->text()),
JString::cleanse($this->crawler->attr('href'))
);
}
}
28 changes: 23 additions & 5 deletions src/Parser/Producer/ProducerParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,34 @@ public function getAnimeCount(): int
*/
public function getExternalLinks(): array
{
$links = $this->crawler
$links = [];

$availableAtLinks = $this->crawler
->filterXPath('//*[@id="content"]/div[1]/div[contains(@class, "user-profile-sns")]/span//a');

if (!$links->count()) {
if (!$availableAtLinks->count()) {
return [];
}

$links = array_merge($links, $availableAtLinks
->each(function (Crawler $c) {
return (new UrlParser($c))->getModel();
}));


$resourcesLinks = $this->crawler
->filterXPath('//*[@id="content"]/div[1]/div[contains(@class, "pb16")]/span//a');

if (!$resourcesLinks->count()) {
return [];
}

return $links->each(function (Crawler $c) {
return (new UrlParser($c))->getModel();
});
$links = array_merge($links, $resourcesLinks
->each(function (Crawler $c) {
return (new UrlParser($c))->getModel();
}));

return $links;
}

/**
Expand Down

0 comments on commit 40d797d

Please sign in to comment.