/** * @param Item $item * * @return string */ public function getSourceForFill(Item $item) { /* @var $source Source */ foreach ($item->getSources() as $source) { if (strpos($source->getUrl(), $this->browser->getHost()) === 0) { return $source->getUrl(); } } return ''; }
/** * Get catalog item * * @param array $item * * @return \AnimeDb\Bundle\CatalogBundle\Entity\Item|null */ public function getCatalogItem(array $item) { $sources = [$this->browser->getHost() . $item['url']]; if (!empty($item['world_art_id'])) { $sources[] = str_replace('#ID#', $item['world_art_id'], self::WORLD_ART_URL); } if (!empty($item['myanimelist_id'])) { $sources[] = str_replace('#ID#', $item['myanimelist_id'], self::MY_ANIME_LIST_URL); } if (!empty($item['ani_db_id'])) { $sources[] = str_replace('#ID#', $item['ani_db_id'], self::ANI_DB_URL); } /* @var $source \AnimeDb\Bundle\CatalogBundle\Entity\Source|null */ $source = $this->repository->findOneBy(['url' => $sources]); if ($source instanceof Source) { return $source->getItem(); } return null; }
/** * @param array $data * * @return ItemSearch[] */ public function search(array $data) { $path = str_replace('#NAME#', urlencode($data['name']), self::SEARH_URL); $path = str_replace('#LIMIT#', self::DEFAULT_LIMIT, $path); $path = str_replace('#GENRE#', isset($data['genre']) ? $data['genre'] : '', $path); $path = str_replace('#TYPE#', isset($data['type']) ? $data['type'] : '', $path); $path = str_replace('#SEASON#', isset($data['season']) ? str_replace('-', '_', $data['season']) : '', $path); $body = (array) $this->browser->get($path); // build list foreach ($body as $key => $item) { // set a name based on the locale if ($this->locale == 'ru' && $item['russian']) { $name = $item['russian']; $description = $item['name']; } else { $name = $item['name']; $description = $item['russian']; } $body[$key] = new ItemSearch($name, $this->getLinkForFill($this->browser->getHost() . $item['url']), $this->browser->getHost() . $item['image']['original'], $description, $this->browser->getHost() . $item['url']); } return $body; }
/** * @param string $url * * @return bool */ public function isSupportedUrl($url) { return strpos($url, $this->browser->getHost()) === 0; }
public function testGetHost() { $this->assertEquals($this->host, $this->browser->getHost()); }