diff --git a/blocks/tag_youtube/block_tag_youtube.php b/blocks/tag_youtube/block_tag_youtube.php index 6a976be97bc..50a7706d2d9 100644 --- a/blocks/tag_youtube/block_tag_youtube.php +++ b/blocks/tag_youtube/block_tag_youtube.php @@ -3,7 +3,6 @@ require_once($CFG->dirroot.'/tag/lib.php'); require_once($CFG->libdir . '/filelib.php'); -define('YOUTUBE_DEV_KEY', 'Dlp6qqRbI28'); define('DEFAULT_NUMBER_OF_VIDEOS', 5); class block_tag_youtube extends block_base { @@ -65,11 +64,11 @@ class block_tag_youtube extends block_base { $numberofvideos = $this->config->numberofvideos; } - $request = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_playlist'; - $request .= '&dev_id=' . YOUTUBE_DEV_KEY; - $request .= "&id={$this->config->playlist}"; - $request .= "&page=1"; - $request .= "&per_page={$numberofvideos}"; + $request = 'http://gdata.youtube.com/feeds/api/playlists/' . + $this->config->playlist . + '?start-index=1&max-results=' . + $numberofvideos . + '&format=5'; return $this->fetch_request($request); } @@ -96,11 +95,11 @@ class block_tag_youtube extends block_base { $numberofvideos = $this->config->numberofvideos; } - $request = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag'; - $request .= '&dev_id='. YOUTUBE_DEV_KEY; - $request .= "&tag={$querytag}"; - $request .= "&page=1"; - $request .= "&per_page={$numberofvideos}"; + $request = 'http://gdata.youtube.com/feeds/api/videos?vq=' . + $querytag . + '&start-index=1&max-results=' . + $numberofvideos . + '&format=5'; return $this->fetch_request($request); } @@ -127,12 +126,14 @@ class block_tag_youtube extends block_base { $numberofvideos = $this->config->numberofvideos; } - $request = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_category_and_tag'; - $request .= '&category_id='.$this->config->category; - $request .= '&dev_id=' . YOUTUBE_DEV_KEY; - $request .= "&tag={$querytag}"; - $request .= "&page=1"; - $request .= "&per_page={$numberofvideos}"; + $request = 'http://gdata.youtube.com/feeds/api/videos?category=' . + $this->category_map_old2new($this->config->category) . + '&vq=' . + $querytag . + '&start-index=1&max-results=' . + $numberofvideos . + '&format=5'; + return $this->fetch_request($request); } @@ -152,18 +153,86 @@ class block_tag_youtube extends block_base { $text = ''; $text .= '
\n"; return $text; } + + function get_categories() { + // TODO: Right now using sticky categories from + // http://gdata.youtube.com/schemas/2007/categories.cat + // This should be performed from time to time by the block insead + // and cached somewhere, avoiding deprecated ones and observing regions + return array ( + '0' => get_string('anycategory', 'block_tag_youtube'), + 'Film' => get_string('filmsanimation', 'block_tag_youtube'), + 'Autos' => get_string('autosvehicles', 'block_tag_youtube'), + 'Music' => get_string('music', 'block_tag_youtube'), + 'Animals'=> get_string('petsanimals', 'block_tag_youtube'), + 'Sports' => get_string('sports', 'block_tag_youtube'), + 'Travel' => get_string('travel', 'block_tag_youtube'), + 'Games' => get_string('gadgetsgames', 'block_tag_youtube'), + 'Comedy' => get_string('comedy', 'block_tag_youtube'), + 'People' => get_string('peopleblogs', 'block_tag_youtube'), + 'News' => get_string('newspolitics', 'block_tag_youtube'), + 'Entertainment' => get_string('entertainment', 'block_tag_youtube'), + 'Education' => get_string('education', 'block_tag_youtube'), + 'Howto' => get_string('howtodiy', 'block_tag_youtube'), + 'Tech' => get_string('scienceandtech', 'block_tag_youtube') + ); + } + + /** + * Provide conversion from old numeric categories available in youtube API + * to the new ones available in the Google API + * + * @param int $oldcat old category code + * @return mixed new category code or 0 (if no match found) + * + * TODO: Someday this should be applied on upgrade for all the existing + * block instances so we won't need the mapping any more. That would imply + * to implement restore handling to perform the conversion of old blocks. + */ + function category_map_old2new($oldcat) { + $oldoptions = array ( + 0 => '0', + 1 => 'Film', + 2 => 'Autos', + 23 => 'Comedy', + 24 => 'Entertainment', + 10 => 'Music', + 25 => 'News', + 22 => 'People', + 15 => 'Animals', + 26 => 'Howto', + 17 => 'Sports', + 19 => 'Travel', + 20 => 'Games' + ); + if (array_key_exists($oldcat, $oldoptions)) { + return $oldoptions[$oldcat]; + } else { + return $oldcat; + } + } } diff --git a/lang/en_utf8/block_tag_youtube.php b/lang/en_utf8/block_tag_youtube.php index 8221ca154ef..2b52e12bf4c 100644 --- a/lang/en_utf8/block_tag_youtube.php +++ b/lang/en_utf8/block_tag_youtube.php @@ -9,6 +9,7 @@ $string['includeonlyvideosfromplaylist'] = 'Include only videos from the playlis $string['filmsanimation'] = 'Films & Animation'; $string['autosvehicles'] = 'Autos & Vehicles'; $string['comedy'] = 'Comedy'; +$string['education'] = 'Education'; $string['entertainment'] = 'Entertainment'; $string['music'] = 'Music'; $string['newspolitics'] = 'News & Politics'; @@ -18,5 +19,6 @@ $string['howtodiy'] = 'How-to & DIY'; $string['sports'] = 'Sports'; $string['travel'] = 'Travel & Places'; $string['gadgetsgames'] = 'Gadgets & Games'; +$string['scienceandtech'] = 'Science & Tech'; ?>