private function parseNewEpisodes($page) { $animediaShowRepository = $this->dm->getRepository('AppBundle:AnimediaShow'); libxml_use_internal_errors(true); $dom = new \DOMDocument(); $dom->loadHTML($page); $finder = new \DOMXPath($dom); $classname = 'widget__new-series__item__title'; $nodes = $finder->query("//a[contains(@class, '{$classname}')]"); foreach ($nodes as $node) { $showTitle = $node->getAttribute('title'); $show = $animediaShowRepository->findOneBy(['title' => $showTitle]); if ($show) { $url = 'http://online.animedia.tv' . $node->getAttribute('href'); $matches = []; if (preg_match('#Серия\\s(\\d+)\\sиз#u', $node->parentNode->nodeValue, $matches)) { $episode = $show->getEpisodeByNumbers(null, (int) $matches[1]); if (!$episode) { $episode = new Episode(); $episode->setEpisodeNumber((int) $matches[1]); $link = new Link(); $link->setUrl($url); $link->setResolution('online'); $episode->addLink($link); $show->addEpisode($episode); $this->logger->info('Новая серия сериала на animedia:' . $showTitle); } } } else { $this->logger->error('Сериал на animedia не найден:' . $showTitle); } } $this->dm->flush(); }
private function addLinkToEpisode(Episode $episode, $url) { $existLinks = $episode->getLinks()->map(function (Link $link) { return $link->getUrl(); })->toArray(); if (in_array($url, $existLinks, true)) { return; } $resolution = 'SD'; if (strpos($url, '.720p.')) { $resolution = '720p'; } elseif (strpos($url, '.1080p') !== false) { $resolution = '1080p'; } $link = new Link(); $link->setUrl($url); $link->setResolution($resolution); $episode->addLink($link); }