public function assignPageContent(\phpQueryObject $_) { parent::assignPageContent($_); $this->_seasons = []; foreach ($_['a[href^="/title/' . $this->_id . '/episodes?season="]'] as $seasonLink) { $this->_seasons[] = (int) pq($seasonLink)->text(); } }
public function jsonSerialize() { return parent::jsonSerialize() + ['tvShowId' => $this->_tvShowId, 'tvShowName' => $this->_tvShowName, 'seasonNumber' => $this->_seasonNumber, 'episodeNumber' => $this->_episodeNumber]; }
/** * Get the series episode(s) * @return array episodes (array[0..n] of array[0..m] of array[imdbid,title,airdate,plot,season,episode]) * @see IMDB page /episodes * @version Attention: Starting with revision 506 (version 2.1.3), the outer array no longer starts at 0 but reflects the real season number! */ public function episodes() { if (!$this->is_serial() && !$this->seasons()) { return array(); } if (empty($this->season_episodes)) { if (!$this->seasons()) { $ser = $this->get_episode_details(); if (isset($ser['imdbid'])) { $show = new Title($ser['imdbid'], $this->config); return $this->season_episodes = $show->episodes(); } else { return array(); } } $page = $this->getPage("Episodes"); if (empty($page)) { return $this->season_episodes; } // no such page if (preg_match('!<select id="bySeason"(.*?)</select!ims', $this->page["Episodes"], $match)) { preg_match_all('!<option\\s+(selected="selected" |)value="(\\d+)">!i', $match[1], $matches); for ($i = 0; $i < count($matches[0]); ++$i) { $s = $matches[2][$i]; $this->getPage("Episodes-{$s}"); if (empty($this->page["Episodes-{$s}"])) { continue; } // no such page $preg = '!<div class="info" itemprop="episodes".+?>\\s*<meta itemprop="episodeNumber" content="(?<episodeNumber>\\d+)"/>\\s*' . '<div class="airdate">\\s*(?<airdate>.*?)\\s*</div>\\s*' . '.+?\\shref="/title/tt(?<imdbid>\\d{7})/.+?"\\s+title="(?<title>.+?)"\\s+itemprop="name"' . '.+?<div class="item_description" itemprop="description">(?<plot>.*?)</div>!ims'; preg_match_all($preg, $this->page["Episodes-{$s}"], $eps); $ec = count($eps[0]); for ($ep = 0; $ep < $ec; ++$ep) { $plot = preg_replace('#<a href="[^"]+"\\s+>Add a Plot</a>#', '', trim($eps['plot'][$ep])); $plot = preg_replace('#Know what this is about\\?<br>\\s*<a href="[^"]+"\\s*> Be the first one to add a plot.\\s*</a>#ims', '', $plot); $this->season_episodes[$s][$eps['episodeNumber'][$ep]] = array('imdbid' => $eps['imdbid'][$ep], 'title' => trim($eps['title'][$ep]), 'airdate' => $eps['airdate'][$ep], 'plot' => $plot, 'season' => $s, 'episode' => $eps['episodeNumber'][$ep]); } } } } return $this->season_episodes; }