There is a davolno old code that parsit YouTube video by reference

<? require_once('libs/JSON.php'); $json = new Services_JSON(); function youtube($url){ global $uid, $json; if(!ereg("http://", $url))$url = "http://".$url; $pars_url = parse_url($url); parse_str($pars_url["query"]); $html = str_replace('$', '', @file_get_contents("http://gdata.youtube.com/feeds/api/videos/".$v."?alt=json")); $video = $json->decode($html); $video_array = (array) $video->entry; //print_R($video_array["title"]->t); //print_R($video->entry->content); if($video_array["title"]->t){ $video_image = "http://img.youtube.com/vi/".$v."/0.jpg"; $video_simage = "http://img.youtube.com/vi/".$v."/2.jpg"; $out["url"] = $url; $out["title"] = iconv("utf-8", "windows-1251", str_replace(array("\n" ,"\r", '"',"/"),array('\n' ,'\r', '\"', ""), $video_array["title"]->t)); $out["description"] = iconv("utf-8", "windows-1251", str_replace(array("\n" ,"\r", '"',"/"),array('\n' ,'\r', '\"', "\/"),$video_array["content"]->t)); $out["images"] = array($video_image, $video_simage); $out["domain"] = $pars_url["host"]; $out["duration"] = $video_array["mediagroup"]->ytduration->seconds; $out["error"] = "1"; $out["vid"] = $v; $out["uid"] = $uid; $out["hash"] = md5($uid.$out["vid"]."youtube_add".date("ym").$out["duration"].$video_image.$video_simage); }else{ $out["error"] = "2"; } //print_R($out); return $out; } ?> 

This method has not worked for a long time. Where do I need to rule, what would work? Thank you in advance..

  • And where exactly does not work? Did you watch the errors that the script shows? Understandably, since there is no response at the output, it does not work. What is contained in the returned $out ? - DaemonHK
  • The $ out information about the video (title, description, preview and vid (go video)). This engine is completely samopis. - Andrew Tereshin
  • It doesn’t matter whether it’s self-written or not, and $out clear information about the video. At the moment, what does the script return and what kind of errors? - DaemonHK
  • To get started: 1. Replace the function ereg with preg_match , ereg is a deprecated function. 2. The function does not know the $ v variable. 3. Get Rid of the Error Suppressor @ - DaemonHK

1 answer 1

Found in the open spaces of enSO (may the community forgive me). Alternative option :

 function get_youtube($url){ $youtube = "http://www.youtube.com/oembed?url=". $url ."&format=json"; $curl = curl_init($youtube); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $return = curl_exec($curl); curl_close($curl); return json_decode($return, true); } $url = // youtube video url // Display Data print_r(get_youtube($url)); 

Checked works. Specifically according to your code: if you go into the brazenly by the generated link, the service responds that the service is not working (but my hands may be clumsy).

There is another option , at the most glance, the most hemorrhoids: use Google Youtube API

  • Yes, no, not really hemorrhoid use api youtube. The only thing is that there are some restrictions in the free version, but if you don’t ask yourself to gut the whole YouTube from the beginning of time, then the rules. - Alexander Belinsky