diff --git a/lib/Film.php b/lib/Film.php index 3f351967a..3dca982fa 100644 --- a/lib/Film.php +++ b/lib/Film.php @@ -263,7 +263,7 @@ class Film * * @return int */ - public function getMovieCount($cat, $maxAge = -1, $excludedCats = array()) + public function getMovieCount($cat, $maxAge = -1, $excludedCats = []) { $catsrch = ''; if (count($cat) > 0 && $cat[0] != -1) { @@ -304,7 +304,7 @@ class Film * * @return bool|PDOStatement */ - public function getMovieRange($cat, $start, $num, $orderBy, $maxAge = -1, $excludedCats = array()) + public function getMovieRange($cat, $start, $num, $orderBy, $maxAge = -1, $excludedCats = []) { $catsrch = ''; if (count($cat) > 0 && $cat[0] != -1) { @@ -427,7 +427,7 @@ class Film } $tmpArr = explode(', ', $data[$field]); - $newArr = array(); + $newArr = []; $i = 0; foreach ($tmpArr as $ta) { if ($i > 5) { @@ -542,7 +542,7 @@ class Film // Check FanArt.tv for background images. $fanart = $this->fetchFanartTVProperties($imdbId); - $mov = array(); + $mov = []; $mov['cover'] = $mov['backdrop'] = $mov['banner'] = $movieID = 0; $mov['type'] = $mov['director'] = $mov['actors'] = $mov['language'] = ''; @@ -688,7 +688,7 @@ class Film if (isset($art['status']) && $art['status'] === 'error') { return false; } - $ret = array(); + $ret = []; if (isset($art['moviebackground'][0]['url'])) { $ret['backdrop'] = $art['moviebackground'][0]['url']; } elseif (isset($art['moviethumb'][0]['url'])) { @@ -738,7 +738,7 @@ class Film return false; } - $ret = array(); + $ret = []; $ret['title'] = $tmdbLookup['title']; if ($this->currentTitle !== '') { @@ -778,7 +778,7 @@ class Film $ret['year'] = date("Y", strtotime($tmdbLookup['release_date'])); } if (isset($tmdbLookup['genres']) && sizeof($tmdbLookup['genres']) > 0) { - $genres = array(); + $genres = []; foreach ($tmdbLookup['genres'] as $genre) { $genres[] = $genre['name']; } @@ -828,7 +828,7 @@ class Film ); if ($buffer !== false) { - $ret = array(); + $ret = []; foreach ($imdb_regex as $field => $regex) { if (preg_match($regex, $buffer, $matches)) { $match = $matches[1]; @@ -837,7 +837,7 @@ class Film } } - $matches = array(); + $matches = []; foreach ($imdb_regex_multi as $field => $regex) { if (preg_match_all($regex, $buffer, $matches)) { $match2 = $matches[1]; diff --git a/lib/TvAnger.php b/lib/TvAnger.php index a567223c3..de66de2cd 100644 --- a/lib/TvAnger.php +++ b/lib/TvAnger.php @@ -934,19 +934,19 @@ class TvAnger public function cleanName($str) { - $str = str_replace(array('.', '_'), ' ', $str); + $str = str_replace(['.', '_'], ' ', $str); - $str = str_replace(array('à', 'á', 'â', 'ã', 'ä', 'æ', 'À', 'Á', 'Â', 'Ã', 'Ä'), 'a', $str); - $str = str_replace(array('ç', 'Ç'), 'c', $str); - $str = str_replace(array('Σ', 'è', 'é', 'ê', 'ë', 'È', 'É', 'Ê', 'Ë'), 'e', $str); - $str = str_replace(array('ì', 'í', 'î', 'ï', 'Ì', 'Í', 'Î', 'Ï'), 'i', $str); - $str = str_replace(array('ò', 'ó', 'ô', 'õ', 'ö', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö'), 'o', $str); - $str = str_replace(array('ù', 'ú', 'û', 'ü', 'ū', 'Ú', 'Û', 'Ü', 'Ū'), 'u', $str); + $str = str_replace(['à', 'á', 'â', 'ã', 'ä', 'æ', 'À', 'Á', 'Â', 'Ã', 'Ä'], 'a', $str); + $str = str_replace(['ç', 'Ç'], 'c', $str); + $str = str_replace(['Σ', 'è', 'é', 'ê', 'ë', 'È', 'É', 'Ê', 'Ë'], 'e', $str); + $str = str_replace(['ì', 'í', 'î', 'ï', 'Ì', 'Í', 'Î', 'Ï'], 'i', $str); + $str = str_replace(['ò', 'ó', 'ô', 'õ', 'ö', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö'], 'o', $str); + $str = str_replace(['ù', 'ú', 'û', 'ü', 'ū', 'Ú', 'Û', 'Ü', 'Ū'], 'u', $str); $str = str_replace('ß', 'ss', $str); $str = str_replace('&', 'and', $str); $str = preg_replace('/^(history|discovery) channel/i', '', $str); - $str = str_replace(array('\'', ':', '!', '"', '#', '*', '’', ',', '(', ')', '?'), '', $str); + $str = str_replace(['\'', ':', '!', '"', '#', '*', '’', ',', '(', ')', '?'], '', $str); $str = str_replace('$', 's', $str); $str = preg_replace('/\s{2,}/', ' ', $str); diff --git a/lib/copy_this/www/lib/TMDb.php b/lib/copy_this/www/lib/TMDb.php index eb7682bff..6893e2a86 100644 --- a/lib/copy_this/www/lib/TMDb.php +++ b/lib/copy_this/www/lib/TMDb.php @@ -1,4 +1,6 @@ _timestamps = array_fill(0, TMDB::REQUEST_LIMIT, 0.0); + $this->_apikey = (string) $apikey; $this->_apischeme = ($scheme == TMDb::API_SCHEME) ? TMDb::API_SCHEME : TMDb::API_SCHEME_SSL; $this->setLang($default_lang); @@ -86,18 +122,44 @@ class TMDb } } + /** + * Increment request counter and handle request limitation + * + * @return void + */ + protected function incRequests(){ + + /* Increment request counter */ + $this->_requests += 1; + + /* Calculate index for the oldest timestamp in the timestamps array */ + $idx = $this->_requests % TMDB::REQUEST_LIMIT; + + /* Save the oldest timestamp for debugging */ + $this->_timestamp = $this->_timestamps[ $idx ]; + + /* Calculate elapsed time */ + $timediff = microtime(true) - $this->_timestamp; + //$timediff = ( floor(microtime(true)*10) - ceil($this->_timestamp*10) ) / 10; + + /* Compare the elapsed time against the specified timespan */ + if ( $timediff < TMDB::REQUEST_TIMESPAN ){ + /* Calculate delay * 1 second and sleep */ + usleep( (TMDB::REQUEST_TIMESPAN - $timediff) *1000000 ); + } + + /* Save new timestamp */ + $this->_timestamps[ $idx ] = microtime(true); + } + /** * Search a movie by querystring * - * @param $query - * @param int $page Number of the page with results (default first page) - * @param bool $adult Whether of not to include adult movies in the results (default FALSE) - * @param null $year - * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages - * + * @param string $text Query to search after in the TMDb database + * @param int $page Number of the page with results (default first page) + * @param bool $adult Whether of not to include adult movies in the results (default FALSE) + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages * @return TMDb result array - * @throws TMDbException - * @internal param string $text Query to search after in the TMDb database */ public function searchMovie($query, $page = 1, $adult = FALSE, $year = NULL, $lang = NULL) { @@ -111,16 +173,33 @@ class TMDb return $this->_makeCall('search/movie', $params); } + /** + * Search a tv show by querystring + * + * @param string $text Query to search after in the TMDb database + * @param int $page Number of the page with results (default first page) + * @param bool $air_date_year Filter results that have air date with value (default NULL) + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function searchTV($query, $page = 1, $air_date_year = NULL, $lang = NULL) + { + $params = array( + 'query' => $query, + 'page' => (int) $page, + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + 'air_date_year' => $air_date_year + ); + return $this->_makeCall('search/tv', $params); + } + /** * Search a person by querystring * - * @param $query - * @param int $page Number of the page with results (default first page) - * @param bool $adult Whether of not to include adult movies in the results (default FALSE) - * + * @param string $text Query to search after in the TMDb database + * @param int $page Number of the page with results (default first page) + * @param bool $adult Whether of not to include adult movies in the results (default FALSE) * @return TMDb result array - * @throws TMDbException - * @internal param string $text Query to search after in the TMDb database */ public function searchPerson($query, $page = 1, $adult = FALSE) { @@ -135,12 +214,9 @@ class TMDb /** * Search a company by querystring * - * @param $query - * @param int $page Number of the page with results (default first page) - * + * @param string $text Query to search after in the TMDb database + * @param int $page Number of the page with results (default first page) * @return TMDb result array - * @throws TMDbException - * @internal param string $text Query to search after in the TMDb database */ public function searchCompany($query, $page = 1) { @@ -151,6 +227,120 @@ class TMDb return $this->_makeCall('search/company', $params); } + /** + * Retrieve all basic information for a particular tv show + * + * @param mixed $id TMDb-id or IMDB-id + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function getTV($id, $lang = NULL) + { + $params = array( + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + ); + return $this->_makeCall('tv/'.$id, $params); + } + + /** + * Retrieve all basic information for a particular tv show season + * + * @param mixed $id TMDb-id or IMDB-id + * @param int $season_id Season Id to query + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function getTVSeason($id, $season_id, $lang = NULL) + { + $params = array( + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + ); + return $this->_makeCall('tv/'.$id.'/season/'.$season_id, $params); + } + + /** + * Retrieve cast and credits for a particular tv show season + * + * @param mixed $id TMDb-id or IMDB-id + * @param int $season_id Season Id to query + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function getTVSeasonCredits($id, $season_id, $lang = NULL) + { + $params = array( + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + ); + return $this->_makeCall('tv/'.$id.'/season/'.$season_id.'/credits', $params); + } + + /** + * Retrieve images for a particular tv show season + * + * @param mixed $id TMDb-id or IMDB-id + * @param int $season_id Season Id to query + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function getTVSeasonImages($id, $season_id, $lang = NULL) + { + $params = array( + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + ); + return $this->_makeCall('tv/'.$id.'/season/'.$season_id.'/images', $params); + } + + /** + * Retrieve all basic information for a particular tv show episode + * + * @param mixed $id TMDb-id or IMDB-id + * @param int $season_id Season Id to query + * @param int $episode_id Episode Id to query + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function getTVEpisode($id, $season_id, $episode_id, $lang = NULL) + { + $params = array( + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + ); + return $this->_makeCall('tv/'.$id.'/season/'.$season_id.'/episode/'.$episode_id, $params); + } + + /** + * Retrieve cast and credits for a particular tv show episode + * + * @param mixed $id TMDb-id or IMDB-id + * @param int $season_id Season Id to query + * @param int $episode_id Episode Id to query + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function getTVEpisodeCredits($id, $season_id, $episode_id, $lang = NULL) + { + $params = array( + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + ); + return $this->_makeCall('tv/'.$id.'/season/'.$season_id.'/episode/'.$episode_id.'/credits', $params); + } + + /** + * Retrieve images for a particular tv show episode + * + * @param mixed $id TMDb-id or IMDB-id + * @param int $season_id Season Id to query + * @param int $episode_id Episode Id to query + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @return TMDb result array + */ + public function getTVEpisodeImages($id, $season_id, $episode_id, $lang = NULL) + { + $params = array( + 'language' => ($lang !== NULL) ? $lang : $this->getLang(), + ); + return $this->_makeCall('tv/'.$id.'/season/'.$season_id.'/episode/'.$episode_id.'/images', $params); + } + /** * Retrieve information about a collection * @@ -177,7 +367,6 @@ class TMDb { $params = array( 'language' => ($lang !== NULL) ? $lang : $this->getLang(), - 'append_to_response' => 'releases,trailers', ); return $this->_makeCall('movie/'.$id, $params); } @@ -186,7 +375,7 @@ class TMDb * Retrieve alternative titles for a particular movie * * @param mixed $id TMDb-id or IMDB-id - * @params string $country Only include titles for a particular country (ISO 3166-1) + * @param string $country Only include titles for a particular country (ISO 3166-1) * @return TMDb result array */ public function getMovieTitles($id, $country = NULL) @@ -197,6 +386,19 @@ class TMDb return $this->_makeCall('movie/'.$id.'/alternative_titles', $params); } + /** + * Retrieve all of the movie crew information for a particular movie. + * + * @see http://docs.themoviedb.apiary.io/#movies + * + * @param mixed $id TMDb-id or IMDB-id + * @return array TMDb result + */ + public function getMovieCredits($id) + { + return $this->_makeCall('movie/'.$id.'/credits'); + } + /** * Retrieve all of the movie cast information for a particular movie * @@ -331,35 +533,37 @@ class TMDb } /** - * Retrieve popular movies (list is updated daily) + * Retrieve popular content (list is updated daily) * - * @param int $page Number of the page with results (default first page) - * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @param string $type Type of content to search ('movie' or 'tv'; default movie) + * @param int $page Number of the page with results (default first page) + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages * @return TMDb result array */ - public function getPopularMovies($page = 1, $lang = NULL) + public function getPopular($type = 'movie', $page = 1, $lang = NULL) { $params = array( 'page' => (int) $page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('movie/popular', $params); + return $this->_makeCall($type.'/popular', $params); } /** - * Retrieve top-rated movies + * Retrieve top-rated content * - * @param int $page Number of the page with results (default first page) - * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @param string $type Type of content to search ('movie' or 'tv'; default movie) + * @param int $page Number of the page with results (default first page) + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages * @return TMDb result array */ - public function getTopRatedMovies($page = 1, $lang = NULL) + public function getTopRated($type = 'movie', $page = 1, $lang = NULL) { $params = array( 'page' => (int) $page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('movie/top_rated', $params); + return $this->_makeCall($type.'/top_rated', $params); } /** @@ -405,16 +609,17 @@ class TMDb /** * Retrieve all cast and crew information for a particular person * - * @param int $id TMDb person-id - * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages + * @param int $id TMDb person-id + * @param string $type Type of content to search ('combined', movie' or 'tv'; default combined) + * @param mixed $lang Filter the result with a language (ISO 3166-1) other then default, use FALSE to retrieve results from all languages * @return TMDb result array */ - public function getPersonCredits($id, $lang = NULL) + public function getPersonCredits($id, $type = 'combined', $lang = NULL) { $params = array( 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('person/'.$id.'/credits', $params); + return $this->_makeCall('person/'.$id.'/'.$type.'_credits', $params); } /** @@ -685,12 +890,10 @@ class TMDb /** * Add a rating to a movie * - * @param string $session_id Set session_id for the account you want to retrieve information from - * @param int $movie_id TMDb movie-id - * @param float|int $value Value between 1 and 10 - * + * @param string $session_id Set session_id for the account you want to retrieve information from + * @param int $movie_id TMDb movie-id + * @param float $value Value between 1 and 10 * @return TMDb result array - * @throws TMDbException */ public function addMovieRating($session_id = NULL, $movie_id = 0, $value = 0) { @@ -721,12 +924,10 @@ class TMDb /** * Get Image URL * - * @param string $filepath Filepath to image - * @param const $imagetype Image type: TMDb::IMAGE_BACKDROP, TMDb::IMAGE_POSTER, TMDb::IMAGE_PROFILE - * @param string $size Valid size for the image - * + * @param string $filepath Filepath to image + * @param const $imagetype Image type: TMDb::IMAGE_BACKDROP, TMDb::IMAGE_POSTER, TMDb::IMAGE_PROFILE + * @param string $size Valid size for the image * @return string - * @throws TMDbException */ public function getImageUrl($filepath, $imagetype, $size) { @@ -755,10 +956,8 @@ class TMDb /** * Get available image sizes for a particular image type * - * @param const $imagetype Image type: TMDb::IMAGE_BACKDROP, TMDb::IMAGE_POSTER, TMDb::IMAGE_PROFILE - * + * @param const $imagetype Image type: TMDb::IMAGE_BACKDROP, TMDb::IMAGE_POSTER, TMDb::IMAGE_PROFILE * @return array - * @throws TMDbException */ public function getAvailableImageSizes($imagetype) { @@ -789,13 +988,11 @@ class TMDb /** * Makes the call to the API * - * @param string $function API specific function name for in the URL - * @param array $params Unencoded parameters for in the URL - * @param string $session_id Session_id for authentication to the API for specific API methods - * @param const|string $method TMDb::GET or TMDb:POST (default TMDb::GET) - * + * @param string $function API specific function name for in the URL + * @param array $params Unencoded parameters for in the URL + * @param string $session_id Session_id for authentication to the API for specific API methods + * @param const $method TMDb::GET or TMDb:POST (default TMDb::GET) * @return TMDb result array - * @throws TMDbException */ private function _makeCall($function, $params = NULL, $session_id = NULL, $method = TMDb::GET) { @@ -811,11 +1008,16 @@ class TMDb if($method === TMDb::GET) { - if(isset($params['language']) && $params['language'] === FALSE) + if(isset($params['language']) AND $params['language'] === FALSE) { unset($params['language']); } + if(isset($params['include_adult'])) + { + $params['include_adult'] = ($params['include_adult'] ? 'true' : 'false'); + } + $url .= ( ! empty($params)) ? '&'.http_build_query($params, '', '&') : ''; } @@ -848,18 +1050,34 @@ class TMDb curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $this->incRequests(); + curl_setopt_array($ch, Utility::curlSslContextOptions()); $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); + $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error_number = curl_errno($ch); $error_message = curl_error($ch); + // If temp banned, you need to wait for 10 sec + if($http_status == 503 or $http_status == 0) + { + if ( $this->_retries < 3 ) + { + $this->_retries += 1; + echo "\nTMDB limits exceeded, sleeping for 10 seconds."; + usleep( 10 *1000*1000 ); + return $this->_makeCall($function, $params, $session_id, $method); + } + } + $this->_retries = 0; + if($error_number > 0) { - throw new TMDbException('Method failed: '.$function.' - '.$error_message); + throw new TMDbException('Method failed: '.$function.' - HTTP Status '.$http_status.' Curl Errno '.$error_number.' Curl Error '.$error_message); } curl_close($ch); @@ -887,7 +1105,7 @@ class TMDb } else { - //throw new TMDbException('Server error on "'.$url.'": '.$response); + throw new TMDbException('Server error on "'.$url.'": '.$response); } } @@ -972,4 +1190,6 @@ class TMDb * * @author Jonas De Smet - Glamorous */ -class TMDbException extends Exception{} \ No newline at end of file +class TMDbException extends Exception +{ +} \ No newline at end of file diff --git a/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl b/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl index 711e5babe..9bc5cf698 100644 --- a/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl +++ b/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl @@ -657,14 +657,6 @@
The url to use to translate allfilled style reqid usenet posts into real release titles. Leave blank to not perform lookup.
- - : - - {html_radios id="lookupnfo" name='lookupnfo' values=$yesno_ids output=$yesno_names selected=$fsite->lookupnfo separator='
'} -
Whether to attempt to retrieve the an nfo file from usenet when processing binaries.
NOTE: disabling nfo lookups will disable movie lookups.
- - - @@ -1264,18 +1256,6 @@ - - - - - -
The maximum amount of NFO files to process per run. This uses NNTP an connection, 1 - per thread. This does not query Amazon. -
- - - @@ -1373,6 +1353,51 @@ +
+ NFO Processing Settings + + + + + + + + + + + + + + + + + + + + + +
+ {html_radios id="lookupnfo" name='lookupnfo' values=$yesno_ids output=$yesno_names selected=$fsite->lookupnfo separator='
'} +
Whether to attempt to retrieve an nfo file from usenet.
+ NOTE: disabling nfo lookups will disable movie lookups. +
+
+ +
The maximum amount of NFO files to process per run. This uses NNTP an connection, 1 + per thread. This does not query Amazon. +
+
+ +
The maximum size in gigabytes of a release to process it for NFOs. If set to 0, then ignored.
+
+ +
The minimum size in megabytes of a release to process it for NFOs. If set to 0, then ignored.
+
+ +
How many times to retry when a NFO fails to download. If set to 0, we will not retry. The max is 7.
+
+
+
Connection Settings