Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * KPFilms - Парсер фильмов с kinopoisk.ru.
- * =======================================================
- * Автор: ShineKami
- * URL: http://webgod-studio.ru/
- * email: sluciferk@gmail.ru
- * =======================================================
- * Файл: wgs_kpfilms.class.php
- * -------------------------------------------------------
- * Версия: 1.0.0 (26.09.2014)
- * -------------------------------------------------------
- * Назначение: Файл функционала модуля
- * =======================================================
- **/
- require_once "htmldom.class.php";
- class kpfilm{
- //Private
- private $ch;
- private $fTitle;
- private $html;
- private $sUrl;
- private $fUrl;
- private $FilmID;
- private $TrailerUrl;
- private function getPage($ulr){
- curl_setopt($this->ch, CURLOPT_URL, $ulr);
- curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
- curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($this->ch, CURLOPT_POST, 1);
- curl_setopt($this->ch, CURLOPT_REFERER, "http://www.kinopoisk.ru/");
- curl_setopt($this->ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
- curl_setopt($this->ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
- curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mozilla/4.0.' .'(compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)');
- $this->html = str_get_html(curl_exec($this->ch));
- return $this->html;
- }
- private function serchFilm(){
- $this->getPage($this->sUrl);
- $sdom = $this->html->find('.search_results');
- $slink = $sdom[0]->find('.pic a');
- $this->fUrl = "http://www.kinopoisk.ru".$slink[0]->href;
- preg_match('#([0-9]{2,7})#',$this->fUrl,$this->FilmID);
- $this->FilmID = $this->FilmID[0];
- return true;
- }
- private function getTrailerUrl(){
- $this->getPage("http://www.kinopoisk.ru/film/".$this->FilmID."/video/");
- parse_str($this->html->find('.news a.continue', 0)->href,$fInfoTrail);
- return $fInfoTrail["link"];
- }
- private function getActors(){
- $ul = $this->html->find('#actorList ul', 0);
- $actorList = '';
- foreach($ul->find('li') as $li)
- {
- $actorList .= $li->plaintext.', ';
- }
- return $actorList;
- }
- //Public
- public function __construct($_ch,$_title){
- $this->ch = $_ch;
- $this->html = new simple_html_dom();
- if(preg_match('/^(https?:\/\/)?([\w\.]+)\.([a-z]{2,6}\.?)(\/[\w\.]*)*\/?$/', $_title)){
- $this->fUrl = $_title;
- preg_match('#([0-9]{2,7})#',$this->fUrl,$this->FilmID);
- $this->FilmID = $this->FilmID[0];
- return true;
- } else {
- $this->fTitle = urlencode($_title);
- $this->sUrl = "http://www.kinopoisk.ru/index.php?first=no&what=&kp_query=".$this->fTitle;
- if(!$this->serchFilm()) return false;
- return true;
- }
- }
- public function getFilmInfo(){
- $this->getPage($this->fUrl);
- //GET Info Film
- $array = [
- "Title" => $this->html->find('[itemprop="name"]', 0)->plaintext,
- "EngTitle" => $this->html->find('[itemprop="alternativeHeadline"]', 0)->plaintext,
- "Poster" => $this->html->find('[itemprop="image"]', 0)->src,
- "Year" => $this->html->find('#infoTable tr', 0)->find('td',1)->plaintext,
- "Country" => $this->html->find('#infoTable tr', 1)->find('td',1)->plaintext,
- "Slogan" => $this->html->find('#infoTable tr', 2)->find('td',1)->plaintext,
- "Director" => $this->html->find('#infoTable [itemprop="director"]', 0)->plaintext,
- "Scenario" => $this->html->find('#infoTable tr', 4)->find('td',1)->plaintext,
- "Producer" => $this->html->find('#infoTable [itemprop="producer"]', 0)->plaintext,
- "Operator" => $this->html->find('#infoTable tr', 6)->find('td',1)->plaintext,
- "MusicBy" => $this->html->find('#infoTable [itemprop="musicBy"]', 0)->plaintext,
- "Artist" => $this->html->find('#infoTable tr', 8)->find('td',1)->plaintext,
- "Film_Editing" => $this->html->find('#infoTable tr', 9)->find('td',1)->plaintext,
- "Genre" => $this->html->find('#infoTable [itemprop="genre"]', 0)->plaintext,
- "Premiera_WD" => $this->html->find('#infoTable #div_world_prem_td2', 0)->plaintext,
- "Premiera_RU" => $this->html->find('#infoTable #div_rus_prem_td2', 0)->plaintext,
- "Premiera_UA" => $this->html->find('#infoTable #div_ua_prem_td2', 0)->plaintext,
- "Relis_BluRay" => $this->html->find('#infoTable .bluray', 0)->plaintext,
- "Relis_DVD" => $this->html->find('#infoTable .dvd', 0)->plaintext,
- "Rate" => $this->html->find('#infoTable .ratePopup td', 1)->plaintext,
- "Time" => $this->html->find('#infoTable #runtime', 0)->plaintext,
- "Rating" => $this->html->find('#block_rating .rating_ball', 0)->plaintext,
- "Descript" => $this->html->find('[itemprop="description"]', 0)->plaintext,
- "Actors" => $this->getActors(),
- "Trailer" => $this->getTrailerUrl()
- ];
- foreach ($array as $key => $value){
- $array[$key] = iconv(mb_detect_encoding($value,'UTF-8', true), 'utf-8',$value);
- }
- return $array;
- }
- public function getHTML(){
- return $this->html;
- }
- }
- function Login($ch,$login,$pass){
- curl_setopt($ch, CURLOPT_URL, "http://www.kinopoisk.ru/login/");
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, "shop_user[login]=".$login."&shop_user[pass]=".$pass."&shop_user[mem]=on&auth=");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
- curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
- return curl_exec($ch);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement