<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['getUtubePlaylist'] )) {
$link = $_POST['youtubePlaylist'];
$link = str_replace('http://www.youtube.com/playlist?list=PL', '', $link);
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/playlists/'.$link;
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
echo '<h1>'.$sxml->title.'</h1>';
// 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'];
// embed url usign $watch value
$embedUrl = str_replace('&feature=youtube_gdata_player', '', $watch);
$embedUrl = str_replace('http://www.youtube.com/watch?v=', '', $embedUrl);
$onlyUrl = $embedUrl;
$cleanEmbedUrl = 'httpv://youtu.be/'.$embedUrl;
$embedUrl = '<iframe width="320" height="280" src="http://www.youtube.com/embed/'.$embedUrl.'" frameborder="0" allowfullscreen></iframe>';
// 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;
}
?>
<div class="videoItem fullb p3 mb2">
<div class="videoTitle mb1">
<?php _e('Video Name: ', 'sagive'); ?><a href="<?php echo $watch; ?>"><?php echo $media->group->title; ?></a>
</div>
<div class="videoDesc mb1"><?php echo __('Video Description: ', 'sagive').$media->group->description; ?></div>
<div class="innerAttr mb1 p1" style="border: 1px solid #ccc;">
<form name="form<?php echo $onlyUrl; ?>" action="">
<?php echo __('Video Embed Code: ', 'sagive'); ?>
<input type="text" id="<?php echo $onlyUrl; ?>" name="<?php echo $onlyUrl; ?>" value="<?php echo $cleanEmbedUrl; ?>" />
<input type="button" value="<?php _e('Copy', 'sagive'); ?>" class="button orangeNum" />
</form>
</div>
<div class="videoContainer">
<div class="thumbnail fright w50 ml5">
<a href="<?php echo $watch; ?>"><img src="<?php echo $thumbnail;?>" /></a>
</div>
<div class="videoPlayer fright w45">
<?php echo $embedUrl; ?>
</div>
<div class="fix"></div>
</div>
<div class="attr mt1">
<div class="innerAttr fright"><?php _e('By:', 'sagive'); ?> <?php echo $entry->author->name; ?> </div>
<div class="innerAttr fright"><?php _e('Duration:', 'sagive'); ?> <?php printf('%0.2f', $length/60); ?> </div>
<div class="innerAttr fright"><?php _e('Views:', 'sagive'); ?> <?php echo $viewCount; ?> </div>
<div class="innerAttr fright"><?php _e('Rating:', 'sagive'); ?> <?php echo $rating; ?> </div>
<div class="fix"></div>
</div>
</div>
<?php
}
}
?>