public function toLink(Episode &$Episode = null) : string { if (empty($Episode)) { $Episode = new Episode($this); } return $Episode->formatURL() . '#' . $this->getID(); }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $shows = $input->getArgument('shows'); if (!$shows) { $output->writeln('You have to provide at least one TVMaze show ID'); return; } //Let's convert them to integer: $shows = array_map('intval', $shows); //Now let's fetch episodes: $episodes = Episode::join('series', 'series.id', '=', 'episodes.serie_id_internal', 'inner')->whereIn('series.external_id', $shows)->orderBy('episodes.airdate', 'ASC')->select(['episodes.id', 'series.title as series_title', 'episodes.title', 'episodes.season_id', 'episodes.episode_id', 'episodes.is_special', 'episodes.url'])->get()->toArray(); $rows = array_map('array_values', $episodes); $table = new Table($output); $table->setHeaders(array('Episode ID', 'Show', 'Title', 'Season', 'Episode', 'Is Special?', 'URL'))->setRows($rows); $table->render(); }
/** * @param InputInterface $input * @param OutputInterface $output * * @return string Output to console */ protected function execute(InputInterface $input, OutputInterface $output) { $group = $input->getArgument('group'); if (!$group) { $output->writeln('<fg=red>Error: You have to provide the group name</>'); return; } $watchListGroup = WatchlistGroup::with('watchlists')->where('title', $group)->first(); if (!$watchListGroup) { $output->writeln('<fg=red>Error: No watchlist group found</>'); return; } //Let's get the ID of of the shows $shows = $watchListGroup->watchlists->pluck('tvmaze_id')->toArray(); //Now let's fetch episodes: $episodes = Episode::join('series', 'series.id', '=', 'episodes.serie_id_internal', 'inner')->whereIn('series.external_id', $shows)->orderBy('episodes.airdate', 'ASC')->select(['episodes.id', 'series.title as series_title', 'episodes.title', 'episodes.season_id', 'episodes.episode_id', 'episodes.is_special', 'episodes.url'])->get()->toArray(); $rows = array_map('array_values', $episodes); $table = new Table($output); $table->setHeaders(array('Episode ID', 'Show', 'Title', 'Season', 'Episode', 'Is Special?', 'URL'))->setRows($rows); $table->render(); }
/** * Gets the number of posts bound to an episode * * @param Episode $Episode * * @deprecated * * @return int */ static function getPostCount($Episode) { global $Database; return $Episode->getPostCount(); }
/** * Creates new episodes * * @param InputInterface $input * @param OutputInterface $output */ private function syncEpisodes(InputInterface $input, OutputInterface $output) { //Each episode has an unique ID in TVMaze, this may be a good hint for us //First, let's fetch all series with keys as external IDS, we'll loop through them $currentSeries = Serie::all()->keyBy('external_id')->toArray(); //FirstOrNew is overkill, "eager load Series + contains($episode_id)" cannot check by external_id column, so pre-fetching is best approach $currentEpisodes = Episode::all()->lists('title', 'external_id')->toArray(); foreach ($currentSeries as $external_id => $serie) { $output->writeln('Now syncing: ' . $serie['title']); $request = new Request('GET', 'http://api.tvmaze.com/shows/' . $external_id . '/episodes?specials=1'); $response = $this->client->send($request); if ($response->getStatusCode() != 200) { $output->writeln('An error has been occurred while fetching series with external_id ' . $external_id); $output->writeln('Error code: ' . $response->getStatusCode()); $output->writeln(self::separator); continue; } $episodes = json_decode($response->getBody()->getContents(), true); //Loop through all episodes: foreach ($episodes as $data) { if (!isset($currentEpisodes[$data['id']])) { $episode = new Episode(); $episode->external_id = $data['id']; $episode->serie_id_external = $external_id; $episode->serie_id_internal = $currentSeries[$external_id]['id']; $episode->season_id = $data['season']; //Episode ID can be null or an integer, it MOST POSSIBLY IS special if (is_null($data['number'])) { $episode->episode_id = 0; $episode->is_special = 1; } else { $episode->episode_id = $data['number']; $episode->is_special = 0; } $episode->title = $data['name']; $episode->description = $data['summary']; $episode->url = $data['url']; if (isset($data['image']['original'])) { $episode->image = $data['image']['original']; } $episode->airdate = $data['airdate'] . ' ' . $data['airtime']; $episode->save(); } } $output->writeln($serie['title'] . ' synced successfully!'); $output->writeln(self::separator); } }