diff --git a/Changelog b/Changelog index 39c1ff9a9..6e0e43de6 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-04-11 DariusIII + * Chg: Adjust TMDB class * Chg: Add exceptions handling, fix incorrect library usage 2017-04-10 DariusIII * Chg: Update Tv, TVDB classes for new TVDB v2 library diff --git a/misc/testing/Tests/test_tmdb_API.php b/misc/testing/Tests/test_tmdb_API.php index ff6decec9..2c834a58c 100755 --- a/misc/testing/Tests/test_tmdb_API.php +++ b/misc/testing/Tests/test_tmdb_API.php @@ -4,7 +4,6 @@ require_once dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'bootstrap.php'; use nntmux\processing\tv\TMDB; -$c = new nntmux\ColorCLI(); $tmdb = new TMDB(); if (!empty($argv[1]) && is_numeric($argv[2]) && is_numeric($argv[3])) { @@ -16,39 +15,45 @@ if (!empty($argv[1]) && is_numeric($argv[2]) && is_numeric($argv[3])) { $episode = (int)$argv[3]; // Search for a show - $series = $tmdb->client->searchTVShow((string)$argv[1]); + $series = $tmdb->client->getSearchApi()->searchTv((string)$argv[1]); + //print_r($series); // Use the first show found (highest match) and get the requested season/episode from $argv if (!empty($series)) { - $seriesAppends = $tmdb->client->getTVShow($series[0]->_data['id'], 'append_to_response=alternative_titles,external_ids'); + $seriesAppends = [ + 'networks' => $tmdb->client->getTvApi()->getTvshow($series['results'][0]['id'])['networks'], + 'alternative_titles' => $tmdb->client->getTvApi()->getAlternativeTitles($series['results'][0]['id']), + 'external_ids' => $tmdb->client->getTvApi()->getExternalIds($series['results'][0]['id']) + ]; + print_r($seriesAppends); if ($seriesAppends) { - $series[0]->_data['networks'] = $seriesAppends->_data['networks']; - $series[0]->_data['alternative_titles'] = $seriesAppends->_data['alternative_titles']['results']; - $series[0]->_data['external_ids'] = $seriesAppends->_data['external_ids']; + $series['results'][0]['networks'] = $seriesAppends['networks']; + $series['results'][0]['alternative_titles'] = $seriesAppends['alternative_titles']; + $series['results'][0]['external_ids'] = $seriesAppends['external_ids']; } - print_r($series[0]); + print_r($series['results'][0]); if ($season > 0 && $episode > 0) { - $episodeObj = $tmdb->client->getEpisode($series[0]->_data['id'], $season, $episode); + $episodeObj = $tmdb->client->getTvEpisodeApi()->getEpisode($series['results'][0]['id'], $season, $episode); if ($episodeObj) { print_r($episodeObj); } - } else if ($season == 0 && $episode == 0) { - $episodeObj = $tmdb->client->getTVShow($series[0]->_data['id']); + } else if ($season === 0 && $episode === 0) { + $episodeObj = $tmdb->client->getTvApi()->getTvshow($series['results'][0]['id']); if (is_array($episodeObj)) { foreach ($episodeObj AS $ep) { print_r($ep); } } } else { - exit($c->error("Invalid episode data returned from TMDB API.")); + exit(\nntmux\ColorCLI::error('Invalid episode data returned from TMDB API.')); } } else { - exit($c->error("Invalid show data returned from TMDB API.")); + exit(\nntmux\ColorCLI::error('Invalid show data returned from TMDB API.')); } } else { - exit($c->error("Invalid arguments. This script requires a text string (show name) followed by a season and episode number.")); + exit(\nntmux\ColorCLI::error('Invalid arguments. This script requires a text string (show name) followed by a season and episode number.')); } diff --git a/nntmux/processing/tv/TMDB.php b/nntmux/processing/tv/TMDB.php index 087814ba0..441621521 100755 --- a/nntmux/processing/tv/TMDB.php +++ b/nntmux/processing/tv/TMDB.php @@ -95,7 +95,7 @@ class TMDB extends TV $tvcount = $res->rowCount(); if ($this->echooutput && $tvcount > 0) { - echo ColorCLI::header("Processing TMDB lookup for " . number_format($tvcount) . " release(s)."); + echo ColorCLI::header('Processing TMDB lookup for ' . number_format($tvcount) . ' release(s).'); } if ($res instanceof \Traversable) { @@ -114,9 +114,9 @@ class TMDB extends TV if (in_array($release['cleanname'], $this->titleCache)) { if ($this->echooutput) { - echo ColorCLI::headerOver("Title: ") . - ColorCLI::warningOver('"' . $release['cleanname'] . '"') . - ColorCLI::header(" already failed lookup for this site. Skipping."); + echo ColorCLI::headerOver('Title: ') . + ColorCLI::warningOver($release['cleanname']) . + ColorCLI::header(' already failed lookup for this site. Skipping.'); } $this->setVideoNotFound(parent::PROCESS_TRAKT, $row['id']); continue; @@ -126,7 +126,7 @@ class TMDB extends TV $videoId = $this->getByTitle($release['cleanname'], parent::TYPE_TV, parent::SOURCE_TMDB); // Force local lookup only - if ($local == true) { + if ($local === true) { $lookupSetting = false; } else { $lookupSetting = true; @@ -135,9 +135,9 @@ class TMDB extends TV // If lookups are allowed lets try to get it. if ($videoId === false && $lookupSetting) { if ($this->echooutput) { - echo ColorCLI::primaryOver("Checking TMDB for previously failed title: ") . + echo ColorCLI::primaryOver('Checking TMDB for previously failed title: ') . ColorCLI::headerOver($release['cleanname']) . - ColorCLI::primary("."); + ColorCLI::primary('.'); } // Get the show from TMDB @@ -158,9 +158,9 @@ class TMDB extends TV } } else { if ($this->echooutput) { - echo ColorCLI::primaryOver("Found local TMDB match for: ") . + echo ColorCLI::primaryOver('Found local TMDB match for: ') . ColorCLI::headerOver($release['cleanname']) . - ColorCLI::primary(". Attempting episode lookup!"); + ColorCLI::primary('. Attempting episode lookup!'); } $tmdbid = $this->getSiteIDFromVideoID('tmdb', $videoId); } @@ -175,7 +175,7 @@ class TMDB extends TV if ($episodeNo === 'all') { // Set the video ID and leave episode 0 $this->setVideoIdFound($videoId, $row['id'], 0); - echo ColorCLI::primary("Found TMDB Match for Full Season!"); + echo ColorCLI::primary('Found TMDB Match for Full Season!'); continue; } @@ -205,7 +205,7 @@ class TMDB extends TV // Mark the releases video and episode IDs $this->setVideoIdFound($videoId, $row['id'], $episode); if ($this->echooutput) { - echo ColorCLI::primary("Found TMDB Match!"); + echo ColorCLI::primary('Found TMDB Match!'); } continue; } else { @@ -246,8 +246,8 @@ class TMDB extends TV sleep(1); - if (is_array($response) && !empty($response)) { - $return = $this->matchShowInfo($response, $cleanName); + if (is_array($response) && !empty($response['results'])) { + $return = $this->matchShowInfo($response['results'], $cleanName); } return $return; } @@ -294,12 +294,12 @@ class TMDB extends TV return false; } - if (isset($showAlternativeTitles['alternative_titles']['results']) && is_array($showAlternativeTitles['alternative_titles']['results'])) { - foreach ($showAlternativeTitles['alternative_titles']['results'] AS $aka) { + if (isset($showAlternativeTitles) && is_array($showAlternativeTitles)) { + foreach ($showAlternativeTitles AS $aka) { $highest['alternative_titles'][] = $aka['title']; } $highest['network'] = $show['networks'][0]['name'] ?? ''; - $highest['external_ids'] = $showExternalIds['external_ids']; + $highest['external_ids'] = $showExternalIds; } $return = $this->formatShowInfo($highest); }