|
|
|||||||||
| Features | |
|
|
|
For a complete list of changes to PHP Youtube Tools click here |
|
/* #####################################################
FUNCTION get_feed_data();
Variables
$username - Value should be the username of the youtube user's feed you wish to retrieve
Returned Data
Data type: Array of Array
Access
[index][key]
Keys / Definitions
'id' = Youtube video ID
'title' = Video title
'description' = Video description
'date' = Video post date
'length' = Video length in seconds
'rating' = Average video rating
'viewcount' = Total number of video views
'commentsCount' = Total number of comments
'watchURL' = URL to view the video on Youtube
'commentsURL' = API URL for the videos comments
##################################################### */
function get_feed_data($userName){
//get youtube video feed array
$sxml=simplexml_load_file('http://gdata.youtube.com/feeds/api/users/'.$userName.'/uploads?orderby=updated');
$youtubeFeed = array();
foreach ($sxml->entry as $entry) {
//get media: nodes
$media = $entry->children('http://search.yahoo.com/mrss/');
//get video url
$watchURL = $media->group->player->attributes();
$watchURL = $watchURL['url'];
//get yt:duration node for video length (in seconds)
$length = $media->children('http://gdata.youtube.com/schemas/2007');
$length = $length->duration->attributes();
$length = $length['seconds'];
//get yt:stats node for viewer statistics
$viewCount = $entry->children('http://gdata.youtube.com/schemas/2007');
$viewCount = $viewCount->statistics->attributes();
$viewCount = $viewCount['viewCount'];
//get gd:comments node for comment count & comments url
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->comments->feedLink) {
$gd = $gd->comments->feedLink->attributes();
$commentsURL = $gd['href'];
$commentsCount = $gd['countHint'];
}
//get gd:rating node for avg video ratings
$rating = $entry->children('http://schemas.google.com/g/2005');
if ($rating->rating) {
$rating = $rating->rating->attributes();
$rating = $rating['average'];
} else {
$rating = 0;
}
//create video array to return to user
$videoEntry = array (
'id' => end(explode("/", $entry->id)),
'title' => $entry->title,
'description' => $entry->content,
'date' => explode("-", $entry->published),
'length' => $length,
'rating' => $rating,
'viewcount' => $viewCount,
'commentsCount' => $commentsCount,
'watchURL' => $watchURL,
'commentsURL' => $commentsURL
);
$videoEntry['date'][2]=substr($videoEntry['date'][2], 0, 2);
array_push($youtubeFeed, $videoEntry);
}
//return videos array
return $youtubeFeed;
}
/* #####################################################
FUNCTION get_video_data();
Variables
$videoID - The ID of the Youtube video you wish to retrieve data for
Returned Data
Data type: Array
Keys / Definitions
'title' = Video title
'description' = Video description
'date' = Video post date
'length' = Video length in seconds
'rating' = Average video rating
'commentsCount' = Total number of comments
'watchURL' = URL to view the video on Youtube
'commentsURL' = API URL for the videos comments
##################################################### */
function get_video_data($videoID){
//get youtube video feed array
$sxml=simplexml_load_file('https://gdata.youtube.com/feeds/api/videos/'.$videoID.'?v=2');
//get media: nodes
$media = $sxml->children('http://search.yahoo.com/mrss/');
//get video url
$watchURL = $media->group->player->attributes();
$watchURL = $watchURL['url'];
//get yt:duration node for video length (in seconds)
$length = $media->children('http://gdata.youtube.com/schemas/2007');
$length = $length->duration->attributes();
$length = $length['seconds'];
//get gd:comments node for comment count & comments url
$gd = $sxml->children('http://schemas.google.com/g/2005');
if ($gd->comments->feedLink) {
$gd = $gd->comments->feedLink->attributes();
$commentsURL = $gd['href'];
$commentsCount = $gd['countHint'];
}
//get gd:rating node for avg video ratings
$rating = $sxml->children('http://schemas.google.com/g/2005');
if ($rating->rating) {
$rating = $rating->rating->attributes();
$rating = $rating['average'];
} else {
$rating = 0;
}
//create video array to return to user
$videoEntry = array (
'title' => $sxml->title,
'description' => $media->group->description,
'date' => explode("-", $sxml->published),
'length' => $length,
'rating' => $rating,
'commentsCount' => $commentsCount,
'watchURL' => $watchURL,
'commentsURL' => $commentsURL
);
$videoEntry['date'][2]=substr($videoEntry['date'][2], 0, 2);
//return videos array
return $videoEntry;
}










