-
Notifications
You must be signed in to change notification settings - Fork 2
/
lib_omdb.php
executable file
·47 lines (36 loc) · 1.11 KB
/
lib_omdb.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
<?php
/**
* holt zu einer IMDB-ID alle gewünschten Filmdaten
* und packt sie in die passende Struktur
*
* @param Integer $imdb_id
* @return Array Filmdaten
*/
function getOMDbRatings ( $imdb_id )
{
$env = parse_ini_file ( '.env' );
$url = sprintf ( 'https://www.omdbapi.com/?i=tt%s&apikey=%s',
str_pad ( $imdb_id, 8, '0', STR_PAD_LEFT ),
$env [ 'APIKEY_OMDB' ] );
$ch = curl_init();
// set url
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 5 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
$buffer = curl_exec ( $ch );
curl_close ( $ch );
$json = json_decode ( $buffer, true );
if ( $json [ 'Response' ] == 'False' )
return array();
else
{
$ratings = array
(
'metacritic' => intval ( $json [ 'Metascore' ] )
);
foreach ( $json [ 'Ratings' ] as $omdb_rating )
if ( $omdb_rating [ 'Source' ] == 'Rotten Tomatoes' )
$ratings [ 'rottentomatoes' ] = intval ( $omdb_rating [ 'Value' ] );
return $ratings;
}
}