Mit 2 kleinen Parametern ein YT-Video analysieren

11/22/2013 14:59 Ravenstorm#1
Um mit 2 kleinen Parametern ein YT-Video analysieren kann:
PHP Code:
 public function getVideoDetails($url,$getMethode){
    
//The Youtube"s API url
    
define("YT_API_URL""http://gdata.youtube.com/feeds/api/videos?q=");
     
    
//Change below the video id.
    
$video_id $url;
     
    
//Using cURL php extension to make the request to youtube API
    
$ch curl_init();
    
curl_setopt($chCURLOPT_URLYT_API_URL $video_id);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
//$feed holds a rss feed xml returned by youtube API
    
$feed curl_exec($ch);
    
curl_close($ch);
     
    
//Using SimpleXML to parse youtube"s feed
    
$xml simplexml_load_string($feed);
     
    
$entry $xml->entry[0];
    
//If no entry whas found, then youtube didn"t find any video with specified id
    
if(!$entry) exit("Error: no video with id " $video_id " whas found. Please specify the id of a existing video.");
    
$media $entry->children("media"true);
    
$group $media->group;
     
    
$title $group->title;
    
$desc $group->description;
    
$vid_keywords $group->keywords;
    
$thumb $group->thumbnail[0];
    
//There are 4 thumbnails, the first one (index 0) is the largest.
    //$thumb_url: the url of the thumbnail. $thumb_width: thumbnail width in pixels.
    //$thumb_height: thumbnail height in pixels. $thumb_time: thumbnail time in the video
    
list($thumb_url$thumb_width$thumb_height$thumb_time) = $thumb->attributes();
    
$content_attributes $group->content->attributes();
    
//$vid_duration: the duration of the video in seconds. Ex.: 192.
    
$vid_duration $content_attributes["duration"];
    
//$duration_formatted: the duration of the video formatted in "mm:ss". Ex.:01:54
    
$duration_formatted str_pad(floor($vid_duration/60), 2'0'STR_PAD_LEFT) . ":" str_pad($vid_duration%602"0"STR_PAD_LEFT);
     
    if(
$getMethode == "title"){
        return 
$title;
    }elseif(
$getMethode == "desc"){
        return 
$desc;
    }elseif(
$getMethode == "keywords"){
        return 
$vid_keywords;
    }elseif(
$getMethode == "TUrl"){
        return 
$thumb_url;
    }elseif(
$getMethode == "TWidth"){
        return 
$thumb_width;
    }elseif(
$getMethode == "THeight"){
        return 
$thumb_height;
    }elseif(
$getMethode == "TTime"){
        return 
$thumb_time;
    }elseif(
$getMethode == "VDuration"){
        return 
$vid_duration;
    }elseif(
$getMethode == "VDurationFormatted"){
        return 
$duration_formatted;
    }else {
        return 
false;
    }