Skip to content

Instantly share code, notes, and snippets.

@paulomcnally
Created August 3, 2012 06:52
Show Gist options
  • Save paulomcnally/3245187 to your computer and use it in GitHub Desktop.
Save paulomcnally/3245187 to your computer and use it in GitHub Desktop.
Simple Class IMDB
<?php
class Imdb{
private $url = "http://www.imdb.es/title/%s/";
private $imdb_id = NULL;
private $html = NULL;
public function setImdbId( $imdb_id ){
$this->imdb_id = $imdb_id;
}
public function getThumbnails(){
$this->html = $this->request();
if( !is_null( $this->html ) ){
@preg_match_all( "/(?:.*)(http:\/\/ia.media-imdb.com\/images\/.+_SX\d{1,}_SY\d{1,}_.jpg)(?:.*)/m", $this->html, $match );
$this->flushData();
if( isset( $match[1][0] ) ){
return $match[1][0];
}
else{
return NULL;
}
}
else{
return NULL;
}
}
private function flushData(){
$this->html = NULL;
}
private function request( ){
if( !is_null( $this->imdb_id ) ){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, vsprintf( $this->url, array( $this->imdb_id ) ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, "imdb " . time()); //prevent rate limit
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $safe);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return $data;
}
else{
return NULL;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment