Bonjour j'ai un script php qui me récupère les informations sur le site imdb style :
1) note
2) votes
3) année
4) genre
exemple : http://www.levagecontrole.fr/imdbvotes.php?u=Meres.Et.Filles.
Depuis quelques temps il ne veut plus me récupérer certaines informations comme la note le réalisateur.
Voici mon code :
<?
class imdb
{
function imdb_id_url($url)
{
if(preg_match("/Title\?/",$url)) { $url=preg_replace("/Title\?/","title/",$url); }
if(preg_match("/\?fr=(.{1,})$/",$url)) { $url=preg_replace("/\?fr=(.{1,})$/","",$url); }
if(!preg_match("/\/$/",$url)) { $url.="/"; }
$tab=explode("/",$url);
$c=count($tab);
$id=$tab[$c-2];
return $id;
}
function imdb_source($id)
{
$fp=@fsockopen("www.imdb.com",80, $errno, $errstr, 6);
if($fp)
{
$req ="GET /title/$id/ HTTP/1.0\n";
$req.="Host: www.imdb.com\n";
$req.="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2\n";
$req.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\n";
$req.="Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3\n\n";
fputs($fp,$req);
$source='';
while(!feof($fp)) { $source.=fgets($fp,1024); }
}
return $source;
}
function imdb_infos($source)
{
$ret=array();
//Titre et date
$tab=explode("<meta name=\"title\" content=\"",$source);
$tab2=explode("\"",$tab[1]);
$titre=explode("(",$tab2[0]);
$ret[0]=html_entity_decode($titre[0]);
$date=explode(")",$tab2[0]);
$date2=explode("(",$date[0]);
$ret[1]=html_entity_decode($date2[1]);
//Directed by ou Réalisé par
$tab=explode("<h5>Director:</h5>",$source);
$tab2=explode("</a><br/>",$tab[1]);
$tab2=preg_replace("/(\r|\n)/","",$tab2[0]);
$tab2=explode("\">",$tab2);
$tab2=explode("<",$tab2[1]);
$ret[2]=html_entity_decode($tab2[0]);
//genre
$tab=explode("<h5>Genre:</h5>",$source);
$tab2=explode("</div>", $tab[1]);
if(preg_match("/<a class=\"tn15more/", $tab2[0]))
{
$tab3 = explode("<a class=\"tn15more", $tab2[0]);
$l = $tab3[0];
}
else
{
$l = $tab2[0];
}
$tab3 = explode(" | ", $l);
for($i = 0, $c = count($tab3), $liste = ""; $i < $c; $i++)
{
$liste .= "(".trim(preg_replace("/<a href=\"(.{1,})\">(.{1,})<\/a>/","$2", $tab3[$i])).") ";
}
$ret[3]= html_entity_decode($liste);
//votes
if(!preg_match("/awaiting/", $source))
{
$tab=explode("<div class=\"meta\">",$source);
$tab1=explode("<b>", $tab[1]);
$tab2=explode("</b>",$tab1[1]);
$ret[4] = $tab2[0];
if($ret[4] == "") $ret[4] = "n/a";
$tab = explode("bsp; <a href=\"ratings\" class=\"tn15more\">", $source);
$tab2 = explode(" votes", $tab[1]);
$ret[5] = $tab2[0];
if($ret[5] == "") $ret[5] = "0";
}
else
{
$ret[4] = "n/a";
$ret[5] = "0";
}
$tab = explode("<a name=\"poster\"", $source);
$tab2 = explode("src=\"", $tab[1]);
$tab3 = explode("\"", $tab2[1]);
$ret[6] = trim($tab3[0]);
return $ret;
}
function imdb_search($title)
{
if(preg_match("/\./",$title))
{
$motcle="DVDRip|SVCD|FR|FANSUB|FULL|SUBFRENCH|PAL|NTSC|MULTi|DVDR";
$tab=preg_split("/(\.)/",$title);
for($i=0;$i<count($tab);$i++)
{
if(preg_match("/($motcle)/",$tab[$i])) { $i=count($tab); }
else { $test.=$tab[$i]."."; }
}
$title=preg_replace("/\.$/","",$test);
$title=preg_replace("/\./"," ",$title);
}
$title=trim($title);
$title=rawurlencode($title);
$fp=@fsockopen("www.imdb.com",80, $errno, $errstr, 6);
if($fp)
{
$req ="GET /find?nr=1;fi=1;s=tt;q=$title HTTP/1.0\n";
$req.="Host: www.imdb.com\n";
$req.="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2\n";
$req.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\n";
$req.="Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3\n\n";
fputs($fp,$req);
$source='';
while(!feof($fp)) { $source.=fgets($fp,1024); }
$tab=explode("(Displaying ",$source);
$tab2=explode("<a href=\"",$tab[1]);
$tab3=explode("\"",$tab2[1]);
$id=preg_replace("/\/title\/(.{1,})\//","$1",$tab3[0]);
if(preg_match("/tt(\d{1,})/",$id))
{
return $id;
}
}
return "";
}
function imdb_reg($inf,$id_imdb)
{
$url=$inf[6];
$tab=explode("/",$url);
$server=$tab[2];
for($i=3;$i<count($tab);$i++) { $urll.="/".$tab[$i]; }
print("Titre@".addslashes($inf[0])." | Votes@".$inf[4]." | NombreVotes@".$inf[5]." | Annee@".$inf[1]." | Realisateur@".$inf[2]." | Genre@".$inf[3]."");
}
}
$u = isset($_GET['u']) ? $_GET['u'] : "";
$inf=array();
$c=new imdb;
$idimdb=$c->imdb_search($u);
$sc=$c->imdb_source($idimdb);
$inf=$c->imdb_infos($sc);
$c->imdb_reg($inf,$idimdb);
?>
j'ai deux questions :
1) comment faire pour pouvoir récuperer les informations qu'il me manque je tourne depuis plus d'un mois et je n'y arrive pas
( je suis un vrai newbie dans le php)
2) est il possible de faire le meme script mais pour allociné ?
Je vous remerci à tous car meme si je suis un vrai débutant ce forum m'apprend beaucoup de chose.