Created
July 30, 2010 18:19
-
-
Save lukegb/501047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path | |
Zend_Loader::loadClass('Zend_Gdata_YouTube'); | |
$yt = new Zend_Gdata_YouTube(); | |
$baseuri = 'http://golden.mtveurope.org/~lukegb/wiimc/youtube.php'; | |
// Tantric: CHANGE ME AND NOTHING ELSE ^_^ | |
//CHECKSUMBEGIN | |
function getAndPrintVideoFeed($location = Zend_Gdata_YouTube::VIDEO_URI) | |
{ | |
$yt = new Zend_Gdata_YouTube(); | |
$videoFeed = $yt->getVideoFeed($location); | |
foreach ($videoFeed as $count => $videoEntry) { | |
printVideoEntry($videoEntry, $count); // this function is documented fully here | |
} | |
} | |
function getStandardFeed($what) { | |
include_once 'youtube_categories.php'; | |
if (array_search($what, $feeds) !== FALSE) { | |
// Build URI | |
if (isset($_GET['region']) && (array_search($_GET['region'], $regions) !== FALSE)) { | |
$addregion = strtoupper($_GET['region']) .'/'; | |
} else { | |
$addregion = ''; | |
} | |
if (isset($_GET['category']) && isset($categories[$_GET['category']]) !== FALSE) { | |
$addcategory = '_'.$_GET['category']; | |
} else { | |
$addcategory = ''; | |
} | |
echo "# this is the:\n# $what feed\n"; | |
if (!empty($addregion)) { echo "# from {$_GET['region']}\n"; } | |
if (!empty($addcategory)) { echo "# in the {$_GET['category']} category\n"; } | |
echo "\n\n\n"; | |
getAndPrintVideoFeed('http://gdata.youtube.com/feeds/api/standardfeeds/'.$addregion.$what.$addcategory.'?v=2'); | |
} | |
} | |
function printVideoEntry($videoEntry, $count) | |
{ | |
echo 'type=video'."\n"; | |
echo 'URL=http://www.youtube.com/watch?v='. $videoEntry->getVideoId() . "\n"; | |
echo 'processor=youtube'."\n"; | |
echo 'name='.$videoEntry->getVideoTitle()."\n\n"; | |
} | |
function doNavigation() { | |
global $baseuri; | |
// Menu: | |
// Categories | |
// - Feed | |
// - - Country | |
// | |
// Is there a category, then? | |
include 'youtube_categories.php'; | |
if (isset($_GET['category']) && isset($categories[$_GET['category']])) { | |
// YES | |
// Is there a feed, then? | |
if (isset($_GET['feed']) && array_search($_GET['feed'], $feeds) !== FALSE) { | |
// YES | |
// output: list of countries applicable for category in feed | |
echo "type=playlist\nname=Worldwide\nURL={$baseuri}?category={$_GET['category']}&what={$_GET['feed']}&type=standard\n\n"; | |
foreach ($regions as $cname => $countries) { | |
echo "type=playlist\nname=$cname\nURL={$baseuri}?category={$_GET['category']}&what={$_GET['feed']}®ion=$countries&type=standard\n\n"; | |
} | |
} else { | |
// NO | |
// output: list of feeds for category: | |
foreach ($feeds as $feedln => $feedn) { | |
echo "type=playlist\nname=$feedln\nURL={$baseuri}?category={$_GET['category']}&feed=$feedn\n\n"; | |
} | |
} | |
} else { | |
// NO | |
// output: list of categories: | |
foreach ($categories as $categorien => $categoriescountry) { | |
echo "type=playlist\nname={$categoriescountry[0]}\nURL={$baseuri}?category={$categorien}\n\n"; | |
} | |
} | |
} | |
function doYouSearch($searchterm) { | |
echo "# YouTube Search: | |
# Looking for $searchterm | |
# Safe Search OFF | |
"; | |
// Okay, youtube searching... | |
// Initialise Zend_Gdata_YouTube | |
$zg = new Zend_Gdata_YouTube(); | |
// Set protocol version to version 2... | |
$zg->setMajorProtocolVersion(2); | |
// Get the new query | |
$search = $zg->newVideoQuery(); | |
// Set the search | |
$search->setVideoQuery($searchterm); | |
// Safe search? NO | |
$search->setSafeSearch('none'); | |
// Okay, order by RELEVANCE | |
$search->setOrderBy('relevance'); | |
// Now shoot! | |
getAndPrintVideoFeed($search->getQueryUrl(2).'&v=2'); | |
} | |
function doAbout() { | |
echo '<h1>About youtube.php</h1> | |
Written by Luke Granger-Brown (lukegb) using the Zend Gdata library for YouTube.<br /> | |
<br /> | |
Written for use by <a href="http://www.wiimc.org">WiiMC</a> <b>only</b> - this script is not <i>yet</i> open-source.<br /><br /> | |
© 2010 Luke Granger-Brown'; | |
// Nothing to see here :P Nah, just my version generator. | |
$a = array(36,115,101,108,102,32,61,32,102,105,108,101,95,103,101,116,95,99,111,110,116,101,110,116,115,40,36,95,83,69,82,86,69,82,91,39,83,67,82,73,80,84,95,70,73,76,69,78,65,77,69,39,93,41,59,36,115,101,108,102,32,61,32,115,117,98,115,116,114,40,36,115,101,108,102,44,32,115,116,114,112,111,115,40,36,115,101,108,102,44,32,39,47,47,67,72,69,67,75,83,85,77,66,69,71,73,78,39,41,41,59,101,99,104,111,32,39,60,98,114,32,47,62,60,98,114,32,47,62,86,101,114,115,105,111,110,58,32,39,46,115,104,97,49,40,36,115,101,108,102,41,59,105,102,32,40,115,104,97,49,40,39,97,110,116,105,100,105,115,101,115,116,97,98,108,105,115,104,109,101,110,116,97,114,105,97,110,105,115,109,39,46,115,104,97,49,40,36,115,101,108,102,41,41,32,61,61,32,36,95,71,69,84,91,39,113,99,104,101,99,107,39,93,41,32,123,101,99,104,111,32,39,60,98,114,32,47,62,60,98,114,32,47,62,60,112,114,101,62,39,46,102,105,108,101,95,103,101,116,95,99,111,110,116,101,110,116,115,40,36,95,83,69,82,86,69,82,91,39,83,67,82,73,80,84,95,70,73,76,69,78,65,77,69,39,93,41,59,125); | |
foreach($a as $b){$c.=chr($b);}eval($c); | |
} | |
// Okay, is this a search? | |
if (isset($_GET['q'])) { | |
doYouSearch($_GET['q']); | |
exit(); | |
} | |
switch ($_GET['type']) { | |
case 'standard': | |
getStandardFeed($_GET['what']); | |
break; | |
case 'about': | |
case 'copyright': | |
doAbout(); | |
break; | |
case 'navi': | |
default: | |
doNavigation(); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment