/** * 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 string $cleanName * * @param string $country * * @return array|bool */ protected function getShowInfo($cleanName, $country = '') { $return = $response = false; $highestMatch = 0; try { $response = (array) $this->client->getSeries($cleanName, 'en'); } catch (\Exception $error) { } if ($response === false && $country !== '') { try { $response = (array) $this->client->getSeries(rtrim(str_replace($country, '', $cleanName)), 'en'); } catch (\Exception $error) { } } sleep(1); if (is_array($response)) { foreach ($response as $show) { if ($this->checkRequired($show, 1)) { // Check for exact title match first and then terminate if found if ($show->name === $cleanName) { $highest = $show; break; } // Check each show title for similarity and then find the highest similar value $matchPercent = $this->checkMatch($show->name, $cleanName, self::MATCH_PROBABILITY); // If new match has a higher percentage, set as new matched title if ($matchPercent > $highestMatch) { $highestMatch = $matchPercent; $highest = $show; } // Check for show aliases and try match those too if (is_array($show->aliasNames) && !empty($show->aliasNames)) { foreach ($show->aliasNames as $key => $name) { $matchPercent = $this->CheckMatch($name, $cleanName, $matchPercent); if ($matchPercent > $highestMatch) { $highestMatch = $matchPercent; $highest = $show; } } } } } if (isset($highest)) { $return = $this->formatShowArr($highest); } } return $return; }
/** * 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 string $cleanName * * @param string $country * * @return array|false */ protected function getShowInfo($cleanName, $country = '') { $return = $response = false; $highestMatch = 0; try { $response = (array) $this->client->getSeries($cleanName, 'en'); } catch (CurlException $error) { if (strpos($error->getMessage(), 'Cannot fetch') === 0) { //Do nothing as there is a second chance } } catch (XmlException $error) { if (strpos($error->getMessage(), 'Error in file') === 0) { //Do nothing as there is a second chance } } if ($response === false && $country !== '') { try { $response = (array) $this->client->getSeries(rtrim(str_replace($country, '', $cleanName)), 'en'); } catch (CurlException $error) { if (strpos($error->getMessage(), 'Cannot fetch') === 0) { return false; } } catch (XmlException $error) { if (strpos($error->getMessage(), 'Error in file') === 0) { return false; } } } sleep(1); if (is_array($response)) { foreach ($response as $show) { if ($this->checkRequiredAttr($show, 'tvdbS')) { // Check for exact title match first and then terminate if found if (strtolower($show->name) === strtolower($cleanName)) { $highest = $show; break; } // Check each show title for similarity and then find the highest similar value $matchPercent = $this->checkMatch(strtolower($show->name), strtolower($cleanName), self::MATCH_PROBABILITY); // If new match has a higher percentage, set as new matched title if ($matchPercent > $highestMatch) { $highestMatch = $matchPercent; $highest = $show; } // Check for show aliases and try match those too if (!empty($show->aliasNames)) { foreach ($show->aliasNames as $key => $name) { $matchPercent = $this->CheckMatch(strtolower($name), strtolower($cleanName), $matchPercent); if ($matchPercent > $highestMatch) { $highestMatch = $matchPercent; $highest = $show; } } } } } if (isset($highest)) { $return = $this->formatShowInfo($highest); } } return $return; }