From 348d3811a559002f5304bb301bc89ee11a33f142 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 15 May 2017 12:14:29 +0200 Subject: [PATCH] Add OMDbAPI apikey support for future use as it will go private soon --- Changelog | 1 + build/nntmux.xml | 4 +- nntmux/Movie.php | 91 ++++++++++++++----- resources/db/patches/mysql/0308~settings.sql | 4 + resources/db/schema/data/10-settings.tsv | 1 + .../shared/templates/admin/site-edit.tpl | 11 +++ 6 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 resources/db/patches/mysql/0308~settings.sql diff --git a/Changelog b/Changelog index 68fdc169e..4969dd13a 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-05-15 DariusIII + * Chg: Add OMDbAPI apikey support for future use as it will go private soon * Chg: Update aharen/omdbapi to version 2.0.6 2017-05-12 DariusIII * Chg: Declare proper @var for pdo (DB) in DnzbFailures diff --git a/build/nntmux.xml b/build/nntmux.xml index 7aa913ff1..df75a0cbc 100755 --- a/build/nntmux.xml +++ b/build/nntmux.xml @@ -16,8 +16,8 @@ - 307 - 307 + 308 + 308 diff --git a/nntmux/Movie.php b/nntmux/Movie.php index 249d3d7f3..4bdf6f4fa 100755 --- a/nntmux/Movie.php +++ b/nntmux/Movie.php @@ -115,6 +115,11 @@ class Movie */ public $fanartapikey; + /** + * @var null|string + */ + public $omdbapikey; + /** * @var bool */ @@ -170,9 +175,12 @@ class Movie ] ] ); - $this->omdb = new OMDbAPI(); $this->fanartapikey = Settings::value('APIs..fanarttvkey'); $this->fanart = new FanartTV($this->fanartapikey); + $this->omdbapikey = Settings::value('APIs..omdbkey'); + if ($this->omdbapikey !== '') { + $this->omdb = new OMDbAPI($this->omdbapikey); + } $this->lookuplanguage = Settings::value('indexer.categorise.imdblanguage') !== '' ? (string)Settings::value('indexer.categorise.imdblanguage') : 'en'; @@ -632,14 +640,11 @@ class Movie * * @param $variable * - * @return string + * @return bool */ - protected function checkVariable(&$variable): string + protected function checkVariable(&$variable): bool { - if (isset($variable) && $variable !== '') { - return true; - } - return false; + return isset($variable) && $variable !== '' ? true : false; } /** @@ -686,7 +691,10 @@ class Movie // Check TRAKT for movie info $trakt = $this->fetchTraktTVProperties($imdbId); - if (!$imdb && !$tmdb && !$trakt) { + + // Check OMDb for movie info + $omdb = $this->fetchOmdbAPIproperties($imdbId); + if (!$imdb && !$tmdb && !$trakt && !$omdb) { return false; } @@ -701,13 +709,15 @@ class Movie $mov['imdbid'] = $imdbId; $mov['tmdbid'] = (!isset($tmdb['tmdbid']) || $tmdb['tmdbid'] === '') ? 0 : $tmdb['tmdbid']; - // Prefer Fanart.tv cover over TMDB and TMDB over IMDB. + // Prefer Fanart.tv cover over TMDB,TMDB over IMDB and IMDB over OMDB. if ($this->checkVariable($fanart['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $fanart['cover'], $this->imgSavePath); - } else if ($this->checkVariable($tmdb['cover'])) { + } elseif ($this->checkVariable($tmdb['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $tmdb['cover'], $this->imgSavePath); - } else if ($this->checkVariable($imdb['cover'])) { + } elseif ($this->checkVariable($imdb['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $imdb['cover'], $this->imgSavePath); + } elseif ($this->checkVariable($omdb['cover'])) { + $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $omdb['cover'], $this->imgSavePath); } // Backdrops. @@ -863,7 +873,7 @@ class Movie if ($percent < 40) { if ($this->debug) { $this->debugging->log( - get_class(), + __CLASS__, __FUNCTION__, 'Found (' . $ret['title'] . @@ -991,7 +1001,7 @@ class Movie if ($percent < 40) { if ($this->debug) { $this->debugging->log( - get_class(), + __CLASS__, __FUNCTION__, 'Found (' . $ret['title'] . @@ -1059,6 +1069,43 @@ class Movie return false; } + /** + * Fetch OMDb backdrop / cover / title. + * + * @param $imdbId + * + * @return bool|array + */ + protected function fetchOmdbAPIProperties($imdbId) + { + if ($this->omdbapikey !== '') { + $this->omdb = new OMDbAPI($this->omdbapikey); + } + $resp = $this->omdb->search('tt' . $imdbId, 'movie'); + + if ($resp->data->Response !== 'False') { + $ret = []; + + if (isset($resp->data->Search[0]->Title)) { + $ret['title'] = $resp->data->Search[0]->Title; + } else { + return false; + } + + if (isset($resp->data->Search[0]->Poster)) { + $ret['cover'] = $resp->data->Search[0]->Poster; + } else { + return false; + } + + if ($this->echooutput) { + ColorCLI::doEcho(ColorCLI::alternateOver('OMDbAPI Found ') . ColorCLI::headerOver($ret['title']), true); + } + return $ret; + } + return false; + } + /** * Update a release with a IMDB id. * @@ -1165,16 +1212,18 @@ class Movie } } - // Check OMDB api. - $buffer = $this->omdb->search($this->currentTitle, 'movies', $this->currentYear !== false ? "'" . $this->currentYear . "'" : ''); + if ($this->omdbapikey !== '') { + // Check OMDB api. + $buffer = $this->omdb->search($this->currentTitle, 'movies', $this->currentYear !== false ? "'" . $this->currentYear . "'" : ''); - if (!empty($buffer) && $buffer->data->Response !== 'False') { - $getIMDBid = $buffer->data->Search[0]->imdbID; + if (!empty($buffer) && $buffer->data->Response !== 'False') { + $getIMDBid = $buffer->data->Search[0]->imdbID; - if (!empty($getIMDBid)) { - $imdbID = $this->doMovieUpdate($getIMDBid, 'OMDbAPI', $arr['id']); - if ($imdbID !== false) { - continue; + if (!empty($getIMDBid)) { + $imdbID = $this->doMovieUpdate($getIMDBid, 'OMDbAPI', $arr['id']); + if ($imdbID !== false) { + continue; + } } } } diff --git a/resources/db/patches/mysql/0308~settings.sql b/resources/db/patches/mysql/0308~settings.sql new file mode 100644 index 000000000..45124e235 --- /dev/null +++ b/resources/db/patches/mysql/0308~settings.sql @@ -0,0 +1,4 @@ +# Add OmdbAPI key setting to settings table + +INSERT IGNORE INTO settings (section, subsection, name, value, hint, setting) VALUES ('APIs', '', 'omdbkey', '', +'OmdbAPI key obtained from Omdb.Used for Omdb API lookups', 'omdbkey'); diff --git a/resources/db/schema/data/10-settings.tsv b/resources/db/schema/data/10-settings.tsv index c1a09a998..4f63270fc 100755 --- a/resources/db/schema/data/10-settings.tsv +++ b/resources/db/schema/data/10-settings.tsv @@ -109,6 +109,7 @@ APIs amazonpubkey AKIAIPDNG5EU7LB4AD3Q The amazon public api key. Used for musi APIs giantbombkey The giantbomb api key. Used for game lookups. giantbombkey APIs anidbkey The Anidb api key. Used for Anime lookups. anidbkey APIs fanarttvkey The Fanart.tv api key. Used for Fanart.tv lookups. Fanart.tv would appreciate it if you use this service to help them out by adding high quality images not already available on TMDB. fanarttvkey +APIs omdbkey OmdbAPI key obtained from Omdb.Used for Omdb API lookups omdbkey APIs rottentomatokey qxbxyngtujprvw7jxam2m6na The api key used for access to rotten tomatoes. rottentomatokey APIs tmdbkey 9a4e16adddcd1e86da19bcaf5ff3c2a3 The API key used for access to TMDb. tmdbkey APIs trakttvclientkey The Trakt.tv API v2 Client ID (SHA256 hash - 64 characters long string). Used for movie and tv lookups. trakttvclientkey diff --git a/www/themes/shared/templates/admin/site-edit.tpl b/www/themes/shared/templates/admin/site-edit.tpl index 5268aeb75..e69421e17 100644 --- a/www/themes/shared/templates/admin/site-edit.tpl +++ b/www/themes/shared/templates/admin/site-edit.tpl @@ -249,6 +249,17 @@ + + + + + +
OmdbAPI key obtained from Omdb.Used for OmdbAPI lookups. This key is private and needs + monthly pledge. You can check the info on OmdbAPI site http://www.omdbapi.com/. You need an pledge + with poster api access (currently 5$/month). +
+ +