public static function suggest($sugTitle, $sugYear, &$result) { $sugTitle = translit_utf8($sugTitle); $link = "http://www.imdb.com/xml/find?json=1&nr=1&tt=on&q=" . urlencode($sugTitle); $file = file_get_contents($link); $json = json_decode($file, true); $vector = array('title_popular', 'title_exact', 'title_approx'); $curDif = 2; foreach ($vector as $type) { if ($json and array_key_exists($type, $json)) { foreach ($json[$type] as $cur) { $year = (int) substr($cur['description'], 0, 4); $needYear = $sugYear ? $sugYear : $year; if (abs($year - $needYear) < $curDif) { $result['id'] = $cur['id']; $result['title'] = html_entity_decode($cur['title'], ENT_QUOTES, "UTF-8"); $result['year'] = $year; $curDif = abs($year - $needYear); } } } } return $curDif < 2 ? 0 : "could not suggest from IMDB"; }
function searchKinopoisk($title, &$movie) { $title = translit_utf8($title); $link = "http://www.kinopoisk.ru/index.php?first=no&what=&kp_query=" . urlencode($title); $response = getKinopoiskLink($link); //search for HTTP 302 $id = array(); $res = preg_match_all('/Location: \\/film\\/(\\d+)\\//isu', $response, $id); if ($id && count($id[0])) { $id = $id[1][0]; } else { $id = false; } if ($id) { $movie['movie']['kpid'] = $id; return; } include_once __DIR__ . '/simple_html_dom.php'; $html = str_get_html($response); if (!$html) { return false; } foreach ($html->find('div[class=element]') as $row) { $pName = $row->find('p[class=name]', 0); $link = $pName->find('a', 0)->href; $id = array(); $res = preg_match_all('/\\/film\\/(\\d+)\\//isu', $link, $id); if ($id && count($id[0])) { $id = $id[1][0]; } else { $id = false; } if ($id) { $name = $pName->find('a', 0)->plaintext; $year = $pName->find('span', 0)->plaintext; $rating = @$row->find('div[class=rating]', 0)->plaintext; $needYear = array_key_exists('year', $movie) ? (int) $movie['year'] : $year; if (abs($year - $needYear) <= 2) { $movie['movie']['kpid'] = $id; $movie['movie']['titleRu'] = iconv('windows-1251', 'UTF-8', $name); $movie['movie']['yearRu'] = $year; return; } } } return false; }