Created
December 23, 2010 05:04
-
-
Save unixpickle/752585 to your computer and use it in GitHub Desktop.
A PHP script to get the latest video on a channel
This file contains hidden or 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
function latestYoutube ($channel) { | |
error_reporting(E_ALL); | |
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $channel . '/uploads?max-results=20'; | |
$sxml = simplexml_load_file($feedURL); | |
$i = 0; | |
foreach ($sxml->entry as $entry) { | |
$media = $entry->children('media', true); | |
$url = (string)$media->group->player->attributes()->url; | |
$index = strrpos($url, "&"); | |
$url = substr($url, 0, $index); | |
$index = strrpos($url, "watch"); | |
$url = substr($url, 0, $index) . "v/" . substr($url, $index + 8, strlen($url) - ($index + 8)); | |
echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="250" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="' . $url . '" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="400" height="250" src="' . $url . '" allowscriptaccess="always" allowfullscreen="true"></embed></object>'; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment