Skip to content

Commit

Permalink
refs #70: implemented getTrailers() for TVShows and added example;
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Finn committed Oct 29, 2020
1 parent e8ec9e8 commit 1744e96
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 2 additions & 2 deletions configuration/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
$cnf['debug'] = false;

// Data Return Configuration - Manipulate if you want to tune your results
$cnf['appender']['movie'] = array('trailers', 'images', 'credits', 'translations', 'reviews');
$cnf['appender']['tvshow'] = array('trailers', 'images', 'credits', 'translations', 'keywords');
$cnf['appender']['movie'] = array('trailers', 'videos', 'images', 'credits', 'translations', 'reviews');
$cnf['appender']['tvshow'] = array('trailers', 'videos', 'images', 'credits', 'translations', 'keywords');
$cnf['appender']['season'] = array('trailers', 'images', 'credits', 'translations');
$cnf['appender']['episode'] = array('trailers', 'images', 'credits', 'translations');
$cnf['appender']['person'] = array('movie_credits', 'tv_credits', 'images');
Expand Down
34 changes: 34 additions & 0 deletions controller/classes/data/TVShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,40 @@ public function getSeasons() {
return $seasons;
}

public function getVideos() {
$videos = $this->_data['videos'];

if (array_key_exists('results', $videos)) {
return $videos['results'];
}

return [];
}

/**
* Get the TVShow's trailers
*
* @return array
*/
public function getTrailers() {
$trailers = [];
$videos = $this->getVideos();

foreach($videos as $video) {
if($video['type'] !== 'Trailer') {
continue;
}

if($video['site'] !== 'YouTube'){
continue;
}

$trailers[] = $video;
}

return $trailers;
}

/**
* Get the TVShow's Backdrop
*
Expand Down
13 changes: 11 additions & 2 deletions examples/tvshows/infoTVShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@
'</li>
<li>Number of Seasons: ' .
$tvShow->getNumSeasons() .
'</li>
<li>Seasons:
'</li>';

$trailers = $tvShow->getTrailers();
echo '<li>Trailers:</li>';
echo '<ul>';
foreach ($trailers as $trailer) {
echo '<li>Trailer '.$trailer['name'].': <a href="https://www.youtube.com/watch?v=' . $trailer['key'] . '">link</a></li>';
}
echo '</ul>';

echo '<li>Seasons:
<ul>';
$seasons = $tvShow->getSeasons();
foreach ($seasons as $season) {
Expand Down

0 comments on commit 1744e96

Please sign in to comment.