/** * @param FixtureEpisodeData $fixture * @param Tv|null $result * * @return null|\Tmdb\Model\AbstractModel|Tv\Episode */ public function resolveSingle(FixtureEpisodeData $fixture, Tv $result = null) { if ($result === null) { return null; } $item = null; try { $repo = $this->getSingleRepository(); $item = $repo->load($result->getId(), $fixture->getSeasonNumber(), $fixture->getEpisodeNumberStart()); } catch (\Exception $e) { } return $item instanceof Tv\Episode ? $item : null; }
/** * @param FixtureEpisodeData $fixture * @param string $baseName */ protected function parseEpisodeNumbers(FixtureEpisodeData $fixture, &$baseName) { if (1 !== preg_match('{s([0-9]+)e([0-9]+)-?([0-9]+)?}i', $baseName, $match) && 1 !== preg_match('{([0-9]{1,2})x([0-9]{1,2})}i', $baseName, $match) && 1 !== preg_match('{([0-9]{1,2})([0-9]{2})}', $baseName, $match)) { return; } $fixture->setSeasonNumber(isset($match[1]) ? $match[1] : 0); $fixture->setEpisodeNumberStart(isset($match[2]) ? $match[2] : 0); if (isset($match[3])) { $fixture->setEpisodeNumberEnd($match[3]); } $baseName = [substr($baseName, 0, strpos($baseName, $match[0])), substr($baseName, strpos($baseName, $match[0]) + strlen($match[0]))]; }
/** * @param FixtureEpisodeData $f */ private function writeLookupFailureEpisode(FixtureEpisodeData $f) { try { $fileSize = $f->getFile()->getSizeHuman(); } catch (\RuntimeException $e) { $fileSize = 'UNKNOWN'; } $rows = [['File Path', $f->getFile()->getPathname()], ['Show Name', $f->getName()], ['Season', $f->getSeasonNumber()], ['Episode Number', $f->getEpisodeNumberStart()], ['Episode Title', $f->getTitle()], ['Air Year', $f->getYear()], ['Size', $fileSize], ['API Match', '<fg=red>FAIL</>']]; $this->ioVerbose(function (StyleInterface $style) use($rows) { $style->table($rows, []); }); $rows = [['File Path', $f->getFile()->getPathname()], ['Size', $fileSize], ['API Match', '<fg=red>FAIL</>']]; $this->ioNotVerbose(function (StyleInterface $style) use($rows) { $style->table($rows, []); }); }
/** * @param FixtureEpisodeData $f * @param \Twig_Environment $e * @param string $tplPathName * @param string $tplFileName * * @return \Twig_Environment[]|mixed[][] */ private function moveEpisode(FixtureEpisodeData $f, \Twig_Environment $e, $tplPathName, $tplFileName) { $e->setLoader(new \Twig_Loader_Array([$tplPathName => $this->tplPathEpisode, $tplFileName => $this->tplFileEpisode])); $opts = ['name' => $f->getName(), 'season' => str_pad($f->getSeasonNumber(), 2, 0, STR_PAD_LEFT), 'start' => str_pad($f->getEpisodeNumberStart(), 2, 0, STR_PAD_LEFT), 'ext' => strtolower(pathinfo($f->getFile()->getRelativePathname(), PATHINFO_EXTENSION))]; if ($f->hasTitle()) { $opts['title'] = $f->getTitle(); } if ($f->hasYear()) { $opts['year'] = $f->getYear(); } return [$e, $opts]; }