Example #1
0
 /**
  * Calls the API to perform initial show name match to TVDB title
  * Returns a formatted array of show data or false if no match
  *
  * @param $cleanName
  *
  * @return array|false
  */
 protected function getShowInfo($cleanName)
 {
     $return = $response = false;
     // TVMaze does NOT like shows with the year in them even without the parentheses
     // Do this for the API Search only as a local lookup should require it
     $cleanName = preg_replace('# \\((19|20)\\d{2}\\)$#', '', $cleanName);
     //Try for the best match with AKAs embedded
     $response = $this->client->singleSearch($cleanName);
     sleep(1);
     if (is_array($response)) {
         $return = $this->matchShowInfo($response, $cleanName);
     }
     if ($return === false) {
         //Try for the best match via full search (no AKAs can be returned but the search is better)
         $response = $this->client->search($cleanName);
         if (is_array($response)) {
             $return = $this->matchShowInfo($response, $cleanName);
         }
     }
     //If we didn't get any aliases do a direct alias lookup
     if (is_array($return) && empty($return['aliases']) && is_numeric($return['tvmaze'])) {
         $return['aliases'] = $this->client->getShowAKAs($return['tvmaze']);
     }
     return $return;
 }