|
[تحسين] دالة رائعة لجلب الفيديوهات من يوتيوب و دايلي و قوقل و فيمو
السلام عليكم و هدية لهذا الموقع الرائع دالة متكاملة تقوم بجلب الفيديو من عدة مواقع منها يوتيوب أو دايلي موشن أو قوقل فيديو أو فيمو, و هي أكبر مواقع الفيديو المعروفة حاليا function getVideoInfo($url){
$type = "";
$id = -1;
$titre = "no title";
$description = "no description";
$code = "no code";
$img = "no image";
//Détermination du "type" de vidéo :
if(eregi("youtube",$url)) $type="youtube";
else if(eregi("dailymotion",$url)) $type="dailymotion";
else if(eregi("google",$url)) $type="google";
else if(eregi("vimeo",$url)) $type="vimeo";
else return false;
//Détermination de l'"ID" de la vidéo :
if($type=="youtube"){
$debut_id = explode("v=",$url,2);
$id_et_fin_url = explode("&",$debut_id[1],2);
$id = $id_et_fin_url[0];
}
else if($type=="dailymotion"){
$debut_id = explode("/video/",$url,2);
$id_et_fin_url = explode("_",$debut_id[1],2);
$id = $id_et_fin_url[0];
}
else if($type=="google"){
$debut_id = explode("docid=",$url,2);
$id_et_fin_url = explode("&",$debut_id[1],2);
$id = $id_et_fin_url[0];
}
else if($type=="vimeo"){
$l_id= eregi("([0-9]+)$",$url,$lid);
$id = $lid[0];
}
//Analyse et stockage des informations de la vidéo
if($type=="youtube"){
$xml = @file_get_contents("http://gdata.youtube.com/feeds/api/videos/".
$id);
//titre
preg_match('#<title(.*?)>(.*)<\/title>#is',$xml,$resultTitre);
$titre = $resultTitre[count($resultTitre)-1];
//description
preg_match('#<content(.*?)>(.*)<\/content>#is',$xml,$resultDescription);
$description = $resultDescription[count($result)-1];
//Image
$img = "http://img.youtube.com/vi/".$id."/1.jpg";
//Code HTML
$code =
'<object width="425" height="355"><param name="movie"' .
' value="http://www.youtube.com/v/'.$id.
'&hl=fr"></param><param name="wmode" value="transparent"></param><embed' .
' src="http://www.youtube.com/v/'.$id.
'&hl=fr" type="application/x-shockwave-flash" wmode="transparent" width="425"' .
' height="355"></embed></object>';
}
else if ($type=="dailymotion"){
$tags = get_meta_tags("http://www.dailymotion.com/video/".$id);
//titre
$titre = htmlspecialchars(trim(str_replace("Dailymotion -","",$tags[
"title"])));
//description
$description = $tags["description"];
//image
$img = "http://www.dailymotion.com/thumbnail/160x120/video/".$id;
// code HTML
$code =
'<div><object width="420" height="357"><param name="movie"' .
' value="http://www.dailymotion.com/swf/'.$id.
'&v3=1&related=1"></param><param name="allowFullScreen"' .
' value="true"></param><param name="allowScriptAccess" value="always"></param>' .
'<embed src="http://www.dailymotion.com/swf/'.$id.
'&v3=1&related=1" type="application/x-shockwave-flash" width="420"' .
' height="357" allowFullScreen="true" allowScriptAccess="always"></embed></obj' .
'ect></div>';
}
else if ($type=="google"){
$xml_string = @file_get_contents(
"http://video.google.com/videofeed?docid=".$id);
//titre
$xml_title_debut = explode("<title>",$xml_string,2);
$xml_title_fin = explode("</title>",$xml_title_debut[1],2);
$titre = $xml_title_fin[0];
//description
$xml_description_debut = explode("<description>",$xml_string,2);
$xml_description_fin = explode("</description>",$xml_description_debut[1
],2);
$description = $xml_description_fin[0];
//image
$xml_image_debut = explode('<img src="',$xml_string,2);
$xml_image_fin = explode('" width="',$xml_image_debut[1],2);
$img = $xml_image_fin[0];
//code HTML
$code =
'<embed style="width:400px; height:326px;" id="VideoPlayback"' .
' type="application/x-shockwave-flash" src="http://video.google.com/googleplay' .
'er.swf?docId='.$id.'&hl=fr" flashvars=""> </embed>';
}
else if ($type=="vimeo"){
$xml_string = @file_get_contents("http://vimeo.com/api/clip/".$id.".xml"
);
//titre
$xml_title_debut = explode("<title>",$xml_string,2);
$xml_title_fin = explode("</title>",$xml_title_debut[1],2);
$titre = $xml_title_fin[0];
//description
$xml_description_debut = explode("<caption>",$xml_string,2);
$xml_description_fin = explode("</caption>",$xml_description_debut[1],2)
;
$description = $xml_description_fin[0];
//image
$xml_image_debut = explode("<thumbnail_large>",$xml_string,2);
$xml_image_fin = explode("</thumbnail_large>",$xml_image_debut[1],2);
$img = $xml_image_fin[0];
//code HTML
$xml_code = @file_get_contents(
"http://vimeo.com/api/oembed.xml?url=http%3A//vimeo.com/".$id);
$xml_code_debut = explode("<html>",$xml_code,2);
$xml_code_fin = explode("</html>",$xml_code_debut[1],2);
$code = str_replace("<![CDATA[","",str_replace("]]>","",$xml_code_fin[0]
));
}
return array("id"=>$id,"type"=>$type,"titre"=>$titre,"description"=>
$description,"img"=>$img,"code"=>$code);
}
|
الموقع الآن فى الفترة التجريبية وهذا الجزء غير كامل وجارى العمل عليه، للراغبين في المساعدة برجاء التقدم

