public function get_kinopoisk_info_by_id()
 {
     if (!$this->isAjax || $this->method != 'POST' || empty($this->postData['data'])) {
         $this->app->abort(404, $this->setlocalization('Page not found'));
     }
     if ($no_auth = $this->checkAuth()) {
         return $no_auth;
     }
     $data = array();
     $data['action'] = 'getKinopoiskInfoById';
     $error = $this->setLocalization('No data');
     try {
         $data['result'] = \Kinopoisk::getInfoById($this->postData['data']);
         $error = '';
     } catch (\KinopoiskException $e) {
         $error = $e->getMessage();
         $logger = new \Logger();
         $logger->setPrefix("kinopoisk_");
         // format: [date] - error_message - [base64 encoded response];
         $logger->error(sprintf("[%s] - %s - \"%s\"\n", date("r"), $e->getMessage(), base64_encode($e->getResponse())));
     }
     $response = $this->generateAjaxResponse($data, $error);
     return new Response(json_encode($response), empty($error) ? 200 : 500);
 }
<?php

include "../common.php";
if (!Config::getSafe('kinopoisk_rating', true)) {
    _log('Notice: kinopoisk rating disabled');
    return;
}
$movies = Mysql::getInstance()->from('video')->where(array('accessed' => 1, 'status' => 1, 'rating_last_update<' => date("Y-m-d H:i:s", time() - 30 * 24 * 3600)))->get()->all();
foreach ($movies as $movie) {
    try {
        if (!empty($movie['kinopoisk_id'])) {
            $rating = Kinopoisk::getRatingById($movie['kinopoisk_id']);
        } else {
            $rating = Kinopoisk::getRatingByName($movie['o_name']);
        }
    } catch (KinopoiskException $e) {
        _log('Error: ' . $movie['path'] . ' (' . $movie['id'] . ') - ' . $e->getMessage());
        $logger = new Logger();
        $logger->setPrefix("kinopoisk_");
        // format: [date] - error_message - [base64 encoded response];
        $logger->error(sprintf("[%s] - %s - \"%s\"\n", date("r"), $e->getMessage(), base64_encode($e->getResponse())));
        continue;
    }
    if ($rating && !empty($rating['kinopoisk_id']) && !empty($rating['rating_kinopoisk']) && $rating['rating_kinopoisk'] != $movie['rating_kinopoisk']) {
        Mysql::getInstance()->update('video', array('kinopoisk_id' => $rating['kinopoisk_id'], 'rating_kinopoisk' => empty($rating['rating_kinopoisk']) ? '' : $rating['rating_kinopoisk'], 'rating_count_kinopoisk' => empty($rating['rating_count_kinopoisk']) ? '' : $rating['rating_count_kinopoisk'], 'rating_imdb' => empty($rating['rating_imdb']) ? '' : $rating['rating_imdb'], 'rating_count_imdb' => empty($rating['rating_count_imdb']) ? '' : $rating['rating_count_imdb'], 'rating_last_update' => 'NOW()'), array('id' => $movie['id']));
        _log('Update: movie ' . $movie['path'] . ' (' . $movie['id'] . ')');
    } else {
        _log('Ignore: movie ' . $movie['path'] . ' (' . $movie['id'] . ') rating updated');
    }
    sleep(1);
}
Esempio n. 3
0
<?php

include "Curl.php";
class Kinopoisk
{
    private $refer = 'http://www.kinopoisk.ru/';
    private $loginUrl = "http://www.kinopoisk.ru/login/";
    function __construct($username, $password)
    {
        $curl = new Curl($this->loginUrl);
        $curl->setRefer($this->refer);
        $formData = array("shop_user" => array("login" => $username, "pass" => $password, "mem" => "on"), "auth" => "войти на сайт");
        $curl->setReturnTransfer(true);
        $curl->sendPostForm($formData);
        $curl->exec();
        echo curl_getinfo($curl, CURLINFO_HEADER_OUT);
        $curl->close();
    }
    function getPage($url)
    {
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_REFERER, $url);
        $out = curl_exec($curl);
        return $out;
    }
}
$Kino = new Kinopoisk('Zir4onah', '540919zir');
echo $Kino->getPage('http://www.kinopoisk.ru/');
Esempio n. 4
0
 /**
  * @expectedException KinopoiskException
  */
 public function testGetRatingByIdException()
 {
     Kinopoisk::getRatingById(0);
 }