-
Notifications
You must be signed in to change notification settings - Fork 0
/
omdb_v1.php
81 lines (73 loc) · 2.06 KB
/
omdb_v1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
//
// The Open Movie Database API by Brian Fritz
//
// Parameter Value Description
// s string (optional) title of a movie to search for
// i string (optional) a valid IMDb movie id
// t string (optional) title of a movie to return
// y year (optional) year of the movie
// r JSON, XML response data type (JSON default)
// plot short, full short or extended plot (short default)
// callback name (optional) JSONP callback name
// tomatoes true (optional) adds rotten tomatoes data
class OMDBv1
{
#<CONSTANTS>
#@var string url of API OMDB
// const _API_URL_ = "http://www.omdbapi.com/?apikey=289ba303&";
// const _API_URL_ = "http://www.omdbapi.com/?apikey=fcbd49b5&";
const _API_URL_ = "http://www.omdbapi.com/?apikey=";
public function movieDetail($idMovie)
{
return $this->_call('i=', $idMovie);
}//end of movieDetail
private function _GetApiKey()
{
$apikey = "";
$rh = fopen("http://www.omdbapi.com/src/application.js", "r");
if ($rh !==false)
{
while (!feof($rh))
{
if (($zeile = fgets($rh)) !== false)
{
$pos = stripos($zeile, "&apikey=");
if ($pos !== false)
{
$pos += 8;
$pos2 = stripos($zeile, "'", $pos);
if ($pos2 !== false)
{
$apikey = substr($zeile, $pos, $pos2-$pos);
break;
}
}
}
}
fclose($rh);
}
error_log($apikey);
return $apikey;
}
private function _call($action, $text)
{
$url=OMDBv1::_API_URL_.$this->_GetApiKey()."&".$action.$text;
// echo "<pre>$url</pre>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
$results = curl_exec($ch);
$headers = curl_getinfo($ch);
$error_number = curl_errno($ch);
$error_message = curl_error($ch);
curl_close($ch);
// header('Content-Type: text/html; charset=iso-8859-1');
//echo"<pre>";print_r(($results));echo"</pre>";
$results = json_decode(($results),true);
return (array) $results;
}//end of _call
}
?>