From efaffbb8b581dc70d080ddf0f80ca32d3d114cf0 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sun, 16 Aug 2015 19:03:42 +0200 Subject: [PATCH] Add support for TraktTv covers in Film.php, update TraktTv.php and ReleaseImage.php for this to function.. --- newznab/controllers/Film.php | 93 +++++++++++++++++++++------- newznab/controllers/ReleaseImage.php | 2 +- newznab/controllers/TraktTv.php | 1 + 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/newznab/controllers/Film.php b/newznab/controllers/Film.php index 1fb5fd824..f18967848 100644 --- a/newznab/controllers/Film.php +++ b/newznab/controllers/Film.php @@ -426,7 +426,7 @@ class Film $this->traktTv = new TraktTv(['Settings' => $this->pdo]); } - $data = $this->traktTv->movieSummary('tt' . $imdbID, 'full'); + $data = $this->traktTv->movieSummary('tt' . $imdbID, 'full,images'); if ($data) { $this->parseTraktTv($data); if (isset($data['trailer']) && !empty($data['trailer'])) { @@ -444,28 +444,36 @@ class Film return false; } - /** - * Parse trakt info, insert into DB. - * - * @param array $data - */ + /** + * Parse trakt info, insert into DB. + * + * @param array $data + * + * @return mixed|void + */ public function parseTraktTv(&$data) { + if (!isset($data['ids']['imdb']) || empty($data['ids']['imdb'])) { + return false; + } + if (isset($data['trailer']) && !empty($data['trailer'])) { $data['trailer'] = str_ireplace( 'http://', 'https://', str_ireplace('watch?v=', 'embed/', $data['trailer']) ); + return $data['trailer']; } $this->update([ 'genres' => $this->checkTraktValue($data['genres']), 'imdbid' => $this->checkTraktValue(str_ireplace('tt', '', $data['ids']['imdb'])), 'language' => $this->checkTraktValue($data['language']), 'plot' => $this->checkTraktValue($data['overview']), - 'rating' => $this->checkTraktValue($data['rating']), + 'rating' => round($this->checkTraktValue($data['rating']), 1), 'tagline' => $this->checkTraktValue($data['tagline']), 'title' => $this->checkTraktValue($data['title']), 'tmdbid' => $this->checkTraktValue($data['ids']['tmdb']), 'trailer' => $this->checkTraktValue($data['trailer']), + 'cover' => $this->checkTraktValue($data['images']['poster']['thumb']), 'year' => $this->checkTraktValue($data['year']) ]); } @@ -594,15 +602,18 @@ class Film * * @param string $variable1 * @param string $variable2 + * @param string $variable3 * * @return string */ - protected function setTmdbImdbVar(&$variable1, &$variable2) + protected function setTmdbImdbTraktVar(&$variable1, &$variable2, &$variable3) { if ($this->checkVariable($variable1)) { return $variable1; } elseif ($this->checkVariable($variable2)) { return $variable2; + } elseif ($this->checkVariable($variable3)) { + return $variable3; } return ''; } @@ -617,7 +628,7 @@ class Film public function updateMovieInfo($imdbId) { if ($this->echooutput && $this->service !== '') { - $this->pdo->log->doEcho($this->pdo->log->primary("Fetching IMDB info from TMDB using IMDB id: " . $imdbId)); + $this->pdo->log->doEcho($this->pdo->log->primary("Fetching IMDB info from TMDB and/or Trakt using IMDB id: " . $imdbId)); } // Check TMDB for IMDB info. @@ -625,7 +636,10 @@ class Film // Check IMDB for movie info. $imdb = $this->fetchIMDBProperties($imdbId); - if (!$imdb && !$tmdb) { + + // Check TRAKT for movie info + $trakt = $this->fetchTraktTVProperties($imdbId); + if (!$imdb && !$tmdb && !$trakt) { return false; } @@ -638,10 +652,12 @@ class Film $mov['type'] = $mov['director'] = $mov['actors'] = $mov['language'] = ''; $mov['imdbid'] = $imdbId; - $mov['tmdbid'] = (!isset($tmdb['tmdbid']) || $tmdb['tmdbid'] == '') ? 'NULL' : $tmdb['tmdbid']; + $mov['tmdbid'] = (!isset($tmdb['tmdbid']) || $tmdb['tmdbid'] == '') ? 0 : $tmdb['tmdbid']; - // Prefer FanArt.tv cover over TMDB. And TMDB over IMDB. - if ($this->checkVariable($fanart['cover'])) { + // Prefer TRAKT cover over Fanart.tv, Fanart.tv over TMDB and TMDB over IMDB. + if ($this->checkVariable($trakt['cover'])) { + $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $trakt['cover'], $this->imgSavePath); + } else if ($this->checkVariable($fanart['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $fanart['cover'], $this->imgSavePath); } else if ($this->checkVariable($tmdb['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $tmdb['cover'], $this->imgSavePath); @@ -660,13 +676,12 @@ class Film if ($this->checkVariable($fanart['banner'])) { $mov['banner'] = $this->releaseImage->saveImage($imdbId . '-banner', $fanart['banner'], $this->imgSavePath); } - - $mov['title'] = $this->setTmdbImdbVar($imdb['title'] , $tmdb['title']); - $mov['rating'] = $this->setTmdbImdbVar($imdb['rating'] , $tmdb['rating']); - $mov['plot'] = $this->setTmdbImdbVar($imdb['plot'] , $tmdb['plot']); - $mov['tagline'] = $this->setTmdbImdbVar($imdb['tagline'], $tmdb['tagline']); - $mov['year'] = $this->setTmdbImdbVar($imdb['year'] , $tmdb['year']); - $mov['genre'] = $this->setTmdbImdbVar($imdb['genre'] , $tmdb['genre']); + $mov['title'] = $this->setTmdbImdbTraktVar($imdb['title'] , $tmdb['title'], $trakt['title']); + $mov['rating'] = $this->setTmdbImdbTraktVar($imdb['rating'] , $tmdb['rating'], $trakt['rating']); + $mov['plot'] = $this->setTmdbImdbTraktVar($imdb['plot'] , $tmdb['plot'], $trakt['overview']); + $mov['tagline'] = $this->setTmdbImdbTraktVar($imdb['tagline'], $tmdb['tagline'], $trakt['tagline']); + $mov['year'] = $this->setTmdbImdbTraktVar($imdb['year'] , $tmdb['year'], $trakt['year']); + $mov['genre'] = $this->setTmdbImdbTraktVar($imdb['genre'] , $tmdb['genre'], $trakt['genres']); if ($this->checkVariable($imdb['type'])) { $mov['type'] = $imdb['type']; @@ -704,7 +719,7 @@ class Film 'imdbid' => $mov['imdbid'], 'language' => html_entity_decode($mov['language'], ENT_QUOTES, 'UTF-8'), 'plot' => html_entity_decode(preg_replace('/\s+See full summary ยป/', ' ', $mov['plot']), ENT_QUOTES, 'UTF-8'), - 'rating' => $mov['rating'], + 'rating' => round($mov['rating'], 1), 'tagline' => html_entity_decode($mov['tagline'] , ENT_QUOTES, 'UTF-8'), 'title' => $mov['title'], 'tmdbid' => $mov['tmdbid'], @@ -763,7 +778,7 @@ class Film $ret['title'] = $art['name']; } if ($this->echooutput) { - $this->pdo->log->doEcho($this->pdo->log->alternateOver("Fanart Found ") . $this->pdo->log->headerOver($ret['title'])); + $this->pdo->log->doEcho($this->pdo->log->alternateOver("Fanart Found ") . $this->pdo->log->headerOver($ret['title']), true); } return $ret; } @@ -952,6 +967,38 @@ class Film return false; } + /** + * Fetch TraktTV backdrop / cover / title. + * + * @param $imdbId + * + * @return bool|array + */ + protected function fetchTraktTVProperties($imdbId) + { + if (is_null($this->traktTv)) { + $this->traktTv = new TraktTv(['Settings' => $this->pdo]); + } + $resp = $this->traktTv->movieSummary('tt' . $imdbId, 'full,images'); + if ($resp !== false) { + $ret = []; + if (isset($resp['images']['poster']['thumb'])) { + $ret['cover'] = $resp['images']['poster']['thumb']; + } + if (isset($resp['images']['banner']['full'])) { + $ret['banner'] = $resp['images']['banner']['full']; + } + + if (isset($ret['cover'])) { + $ret['title'] = $resp['title']; + } + if ($this->echooutput) { + $this->pdo->log->doEcho($this->pdo->log->alternateOver("Trakt Found ") . $this->pdo->log->headerOver($ret['title']), true); + } + return $ret; + } + } + /** * Update a release with a IMDB id. * @@ -1081,7 +1128,7 @@ class Film } // Check on trakt. - $data = $this->traktTv->movieSummary($movieName, 'full'); + $data = $this->traktTv->movieSummary($movieName, 'full,images'); if ($data !== false) { $this->parseTraktTv($data); if (isset($data['ids']['imdb'])) { diff --git a/newznab/controllers/ReleaseImage.php b/newznab/controllers/ReleaseImage.php index 23e7c3353..a7eed3d09 100644 --- a/newznab/controllers/ReleaseImage.php +++ b/newznab/controllers/ReleaseImage.php @@ -84,7 +84,7 @@ class ReleaseImage { $img = false; - if (strpos(strtolower($imgLoc), 'http:') === 0) { + if (strpos(strtolower($imgLoc), 'http:') === 0 || strpos(strtolower($imgLoc), 'https:') === 0) { $img = Utility::getUrl(['url' => $imgLoc]); } else if (is_file($imgLoc)) { $img = @file_get_contents($imgLoc); diff --git a/newznab/controllers/TraktTv.php b/newznab/controllers/TraktTv.php index 110c13041..f3d9bb483 100644 --- a/newznab/controllers/TraktTv.php +++ b/newznab/controllers/TraktTv.php @@ -96,6 +96,7 @@ class TraktTv switch($type) { case 'full': case 'images': + case 'full,images': $extended = $type; break; case 'imdbID':