Revision: 50979
Updated Code
at September 26, 2012 12:35 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //Change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumbnail url: ' . $thumb_url . '<br />'; echo 'thumbnail width: ' . $thumb_width . '<br />'; echo 'thumbnail height: ' . $thumb_height . '<br />'; echo 'thumbnail time: ' . $thumb_time . '<br />'; echo 'video duration: ' . $vid_duration . '<br />'; echo 'video duration formatted: ' . $duration_formatted; ?>
Revision: 50978
Updated Code
at December 18, 2011 01:08 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 viÃ��Ã�ÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumbnail url: ' . $thumb_url . '<br />'; echo 'thumbnail width: ' . $thumb_width . '<br />'; echo 'thumbnail height: ' . $thumb_height . '<br />'; echo 'thumbnail time: ' . $thumb_time . '<br />'; echo 'video duration: ' . $vid_duration . '<br />'; echo 'video duration formatted: ' . $duration_formatted; ?>
Revision: 50977
Updated Code
at September 10, 2011 07:35 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 viÃ�ÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumbnail url: ' . $thumb_url . '<br />'; echo 'thumbnail width: ' . $thumb_width . '<br />'; echo 'thumbnail height: ' . $thumb_height . '<br />'; echo 'thumbnail time: ' . $thumb_time . '<br />'; echo 'video duration: ' . $vid_duration . '<br />'; echo 'video duration formatted: ' . $duration_formatted; ?>
Revision: 50976
Updated Code
at September 10, 2011 04:13 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 viÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50975
Updated Code
at September 10, 2011 04:12 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 viÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50974
Updated Code
at September 10, 2011 04:11 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 vÃ���Ã�¯Ã�¿Ã�½Ã��Ã�¯Ã��Ã�¿Ã��Ã�½Ã���Ã�¯Ã�¿Ã�½Ã���Ã��Ã�ÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50973
Updated Code
at September 10, 2011 04:09 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 vÃ���Ã�¯Ã�¿Ã�½Ã���Ã��Ã�ÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50972
Updated Code
at September 10, 2011 04:02 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 vÃ���Ã��Ã�ÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50971
Updated Code
at September 10, 2011 04:01 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 vÃ��Ã�ÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50970
Updated Code
at September 10, 2011 04:00 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 vÃ�ÂÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50969
Updated Code
at September 10, 2011 03:58 by TimoZachi
Updated Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 vÃÂdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Revision: 50968
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 10, 2011 03:51 by TimoZachi
Initial Code
<?php //The Youtube's API url define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q='); //change below the video id. $video_id = '66Wi3isw3NY'; //Using cURL php extension to make the request to youtube API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //$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]; $media = $entry->children('media', true); $group = $media[0]; $title = $group->title;//$title: The video title $desc = $group->description;//$desc: The video description $vid_keywords = $group->keywords;//$vid_keywords: The video keywords $thumb = $group->thumbnail[0];//There are 4 thumbnails, The first 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 vÃdeo 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%60, 2, '0', STR_PAD_LEFT); //echoing the variables for testing purposes: echo 'title: ' . $title . '<br />'; echo 'desc: ' . $desc . '<br />'; echo 'video keywords: ' . $vid_keywords . '<br />'; echo 'thumb_url: ' . $thumb_url . '<br />'; echo 'thumb_width: ' . $thumb_width . '<br />'; echo 'thumb_height: ' . $thumb_height . '<br />'; echo 'thumb_time: ' . $thumb_time . '<br />'; echo 'video_duration: ' . $vid_duration . '<br />'; echo 'video_duration_formatted: ' . $duration_formatted; ?>
Initial URL
Initial Description
This code snippet gets all information from a YouTube video (title, description, duration, thumbnail url, thumbnail width, thumbnail height, etc..) using the video id and YouTube API.
Initial Title
Get All information from youtube video
Initial Tags
video, api
Initial Language
PHP