<?php
Class Kinopoisk
{
private $KP_APIURL = 'https://ext.kinopoisk.ru/ios/5.0.0/';
private $KP_SECRET = 'IDATevHDS7';
private $methods = array(
'getBestFilms' => 'getBestFilmsList',
/* Информация фильмов */
'getGallery' => 'getGallery',
'getWall' => 'getWall',
'getStaff' => 'getStaffList',
'getFilm' => 'getKPFilmDetailView',
'getSimilar' => 'getKPFilmsList',
/* Жанры */
'getGenres' => 'getKPGenresView',
'getTopGenre' => 'getKPTopGenre',
/* Отзывы */
'getReviews' => 'getKPReviews',
'getReviewDetail' => 'getKPReviewDetail',
/* Новости */
'getNews' => 'getKPNewsView',
'getNewsDetail' => 'getKPNewsDetail',
/* Скоро в прокате */
'getSoonFilms' => 'getKPSoonFilms',
'getSoonDVD' => 'getKPSoonDVD',
'getDatesForSoonFilms' => 'getDatesForSoonFilms',
'getDatesForSoonDVD' => 'getDatesForSoonDVD',
/* Кинотеатры */
'getTodayFilms' => 'getKPTodayFilms',
'getCinemas' => 'getKPCinemas',
'getCinemaDetail' => 'getKPCinemaDetailView',
'getSeance' => 'getSeance',
'getDatesForDetailCinema' => 'getDatesForDetailCinema',
'getDatesForSeance' => 'getDatesForSeance',
/* ТОП */
'getTop' => 'getKPTop',
/* Персоны */
'getPeople' => 'getKPPeopleDetailView',
'getPeopleView' => 'getKPPeopleView',
/* Поиск */
'searchGlobal' => 'getKPGlobalSearch',
'searchFilms' => 'getKPSearchInFilms',
'searchPeople' => 'getKPSearchInPeople',
'searchCinemas' => 'getKPSearchInCinemas',
'searchNavigator' => 'navigator',
'navigatorFilters' => 'navigatorFilters',
/* Гео */
'getCountryList' => 'getKPCountryView',
'getCityList' => 'getKPAllCitiesView',
'getPopularIndex' => 'getPopularIndex',
/* Проверить */
'getSpot' => 'getSpotlightView',
'getKPLiveSearch' => 'getKPLiveSearch',
'getBornIn' => 'getBornIn',
'getRated' => 'getRatedFilms',
'getAwards' => 'getKPAwards',
'getSeries' => 'getKPSeriesList',
);
public function __construct(){
$this->customFunctions = array(
'getPopularIndex'
);
$this->customOptions = array(
'getFilm' => function($options){
if(!isset($options['keyword'])){
$options['still_limit'] = '5';
}
if(!isset($options['keyword'])){
$options['cityID'] = '1';
}
return $options;
},
'getPeople' => function($options){
if(!isset($options['keyword'])){
$options['still_limit'] = '10';
}
if(!isset($options['keyword'])){
$options['cityID'] = '1';
}
return $options;
},
'getSimilar' => function($options){
if(isset($options['type'])) return $options;
return array('type' => 'kp_similar_films');
},
'searchGlobal' => function($options){
if(isset($options['keyword'])){
$options['keyword'] = str_replace('+', ' плюс ', $options['keyword']);
$options['keyword'] = str_replace(' ', '.', $options['keyword']);
}
return $options;
},
'searchFilms' => function($options){
if(isset($options['keyword'])){
$options['keyword'] = str_replace('+', ' плюс ', $options['keyword']);
$options['keyword'] = str_replace(' ', '.', $options['keyword']);
}
return $options;
},
'searchPeople' => function($options){
if(isset($options['keyword'])){
$options['keyword'] = str_replace('+', ' плюс ', $options['keyword']);
$options['keyword'] = str_replace(' ', '.', $options['keyword']);
}
return $options;
},
'searchCinemas' => function($options){
if(isset($options['keyword'])){
$options['keyword'] = str_replace('+', ' плюс ', $options['keyword']);
$options['keyword'] = str_replace(' ', '.', $options['keyword']);
}
return $options;
},
'searchNavigator' => function($options){
if(!isset($options['genre_or'])){
$options['genre_or'] = '0';
}
if(!isset($options['country_or'])){
$options['country_or'] = '0';
}
if(!isset($options['page'])){
$options['page'] = '1';
}
if(!isset($options['order'])){
$options['order'] = 'rating';
}
return $options;
},
);
}
public function getPopularIndex($options){
$top = array();
for($i = 1; $i <= 5; $i++){
$pageTop = $this->callMethod('getKPTop', [
'type' => 'kp_item_top_popular_films',
'page' => $i
]);
$pageTop = json_decode($pageTop)->data->items;
$top = array_merge($top, $pageTop['data']['items']);
}
$place = false;
$foundFilm = false;
foreach($top as $i => $film){
if($options['filmID'] == $film['id']){
$place = $i + 1;
$foundFilm = $film;
}
}
if($place){
$foundFilm['place'] = $place;
return $foundFilm;
}
return 'null';
}
public function call($method, $options = array())
{
if(empty($this->methods[$method])) return false;
if(!empty($this->customOptions[$method])){
$options = array_merge($options, $this->customOptions[$method]($options));
}
foreach($this->methods as $method_name => $method_original) {
if ($method == $method_name) $method = $method_original;
}
if (in_array($method, $this->customFunctions)) {
$result = $this->{$method}($options);
}
else {
$result = json_decode($this->callMethod($method, $options))->data;
}
if ($result == '[key:false]') {
return false;
}
return $result;
}
public function callMethod($method, $options)
{
$action = $method;
$query = http_build_query($options);
$timestamp = time() * 1000;
if (!empty($query)) {
$action.= '?' . $query;
}
$signature = md5($action . $timestamp . $this->KP_SECRET);
$url = $this->KP_APIURL . $action;
$randomIP = rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'REMOTE_ADDR: ' . $randomIP,
'HTTP_X_FORWARDED_FOR: ' . $randomIP,
'device: android',
'Accept: application/json',
'Android-Api-Version: 22',
'countryID: 2',
'ClientId: 55decdcf6d4cd1bcaa1b3856',
'clientDate: ' . date('H:i m.d.Y'),
'cityID: 1',
'Image-Scale: 3',
'Cache-Control: max-stale=0',
'User-Agent: Android client (4.4 / api22),ru.kinopoisk/4.2.1 (52)',
'X-TIMESTAMP: ' . $timestamp,
'X-SIGNATURE: ' . $signature
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec($ch);
curl_close($ch);
return $out;
}
}
$id = 666;
$kp = new Kinopoisk;
print_r($kp->call('getReviews', [
'filmID' => $id
]));
print_r($kp->call('getStaff', [
'filmID' => $id
]));
print_r($kp->call('getFilm', [
'filmID' => $id
]));
print_r($kp->call('getGallery', [
'filmID' => $id
]));
print_r($kp->call('getSimilar', [
'filmID' => $id,
'type' => 'kp_related_films'// kp_sequels_and_prequels_films, kp_related_films, kp_similar_films
]));
print_r($kp->call('getPeople', [
'peopleID' => 51921
]));
print_r($kp->call('getSeries', [
'serialID' => 243595,
'season' => 1
]));