Details
Description
recently i noticed the the block tag_youtube does not show video thumbnails ![]()
it appears, Google no longer support the old RSS/XML format as described in:
http://code.google.com/apis/youtube/migration.html
so i read through the new API (version 2):
http://code.google.com/apis/gdata/docs/2.0/reference.html#Queries
and luckily, found IBM's implementation for it, too:
http://www.ibm.com/developerworks/xml/library/x-youtubeapi/
(thanks IBM, we love you)
and i have made a little patch to the moodle/blocks/tag_youtube/block_tag_youtube.php file
see comments with instructions of how to apply the patch
Issue Links
| This issue will help resolve: | ||||
| MDL-17386 | Notice in the tag page if youtube block is shown |
|
|
|
open file moodle/blocks/tag_youtube/block_tag_youtube.php
inside function get_videos_by_tag , remark around lines 103-107 and add the unremarked code :
now, add a new function :
function render_video_list_xml($feedURL){ $text = ''; $text .= '<ul class="yt-video-entry unlist img-text">'; // read feed into SimpleXML object $sxml = simplexml_load_file($feedURL); // iterate over entries in feed foreach ($sxml->entry as $entry) { // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); // get video player URL $attrs = $media->group->player->attributes(); $watch = $attrs['url']; // get video thumbnail $attrs = $media->group->thumbnail[0]->attributes(); $thumbnail = $attrs['url']; // get <yt:duration> node for video length $yt = $media->children('http://gdata.youtube.com/schemas/2007'); $attrs = $yt->duration->attributes(); $length = $attrs['seconds']; // get <yt:stats> node for viewer statistics $yt = $entry->children('http://gdata.youtube.com/schemas/2007'); $attrs = $yt->statistics->attributes(); $viewCount = $attrs['viewCount']; // get <gd:rating> node for video ratings $gd = $entry->children('http://schemas.google.com/g/2005'); if ($gd->rating) { $attrs = $gd->rating->attributes(); $rating = $attrs['average']; } else { $rating = 0; } $text .= '<li>'; $text .= '<div class="item">'; $text .= '<span class="title">'; $text .= "<a href=\"$watch\">{$media->group->title}</a>"; $text .= '</span>'; $text .= "<p>{$media->group->description}</p>"; $text .= "<a href=\"$watch\"><img src=\"$thumbnail\" /></a>"; $text .= '</div></li>\n'; } // if youtube is offline, or for whatever reason the previous // call doesn't work... //add_to_log(SITEID, 'blocks/tag_youtube', 'problem in getting videos off youtube'); $text .= "</ul><div class=\"clearer\"></div>\n"; return $text; }and you are ready to go
function render_video_list_xml($feedURL){ $text = ''; $text .= '<ul class="yt-video-entry unlist img-text">'; // read feed into SimpleXML object $sxml = simplexml_load_file($feedURL); // iterate over entries in feed foreach ($sxml->entry as $entry) { // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); // get video player URL $attrs = $media->group->player->attributes(); $watch = $attrs['url']; // get video thumbnail $attrs = $media->group->thumbnail[0]->attributes(); $thumbnail = $attrs['url']; // get <yt:duration> node for video length $yt = $media->children('http://gdata.youtube.com/schemas/2007'); $attrs = $yt->duration->attributes(); $length = $attrs['seconds']; // get <yt:stats> node for viewer statistics $yt = $entry->children('http://gdata.youtube.com/schemas/2007'); $attrs = $yt->statistics->attributes(); $viewCount = $attrs['viewCount']; // get <gd:rating> node for video ratings $gd = $entry->children('http://schemas.google.com/g/2005'); if ($gd->rating) { $attrs = $gd->rating->attributes(); $rating = $attrs['average']; } else { $rating = 0; } $text .= '<li>'; $text .= '<div class="item">'; $text .= '<span class="title">'; $text .= "<a href=\"$watch\">{$media->group->title}</a>"; $text .= '</span>'; $text .= "<p>{$media->group->description}</p>"; $text .= "<a href=\"$watch\"><img src=\"$thumbnail\" /></a>"; $text .= '</div></li>\n'; } // if youtube is offline, or for whatever reason the previous // call doesn't work... //add_to_log(SITEID, 'blocks/tag_youtube', 'problem in getting videos off youtube'); $text .= "</ul><div class=\"clearer\"></div>\n"; return $text; }