, -, , , . , , Zend_Gdata_YouTube:: Magento. "", , . : Magento .
php, var/export. app/Mage.php.
<?
$userName='cacycleworksdotcom';
$yt = new Zend_Gdata_YouTube();
$playlistListFeed = $yt->retrieveAllEntriesForFeed($yt->getPlaylistListFeed($userName));
$playlist=Array();
$videoEntry=NULL;
$playlistvideos=Array();
Zend $playlistListFeed.
foreach ($playlistListFeed as $idx=>$playlistListEntry) {
$playlists[$idx]['title'] = $playlistListEntry->title->text;
$url=$playlistListEntry->getSelfLink()->href;
$id=explode("/PL",$url);
$playlists[$idx]['id'] = $id[1];
$playlistVideoFeed = $yt->getPlaylistVideoFeed($playlistListEntry->getPlaylistVideoFeedUrl());
$playlists[$idx]['time']=0;
$playlists[$idx]['views']=0;
$playlists[$idx]['rating']=0;
, , . , , .
foreach ($playlistVideoFeed as $videoEntry) {
$_id=substr($videoEntry->getVideoWatchPageUrl(),31,11);
$playlistvideos[]=$_id;
$_url=$videoEntry->getVideoWatchPageUrl();
$playlists[$idx]['videos'][$_id]=$_url;
$playlists[$idx]['time']+=$videoEntry->getVideoDuration();
$_views=$videoEntry->getVideoViewCount();
if( $_views > $playlists[$idx]['views'] )
$playlists[$idx]['views']=$_views;
$_rating=$videoEntry->getRating()->average;
if( $_rating > $playlists[$idx]['rating'] )
$playlists[$idx]['rating']=$_rating;
}
XML, .
$xml=$playlistListEntry->getXML();
// $playlists[$idx]['xml']=$xml; // store original XML for now
$xml = simplexml_load_string($xml); // transfer into object
$attrs=$xml->group->thumbnail[1];
$playlists[$idx]['thumb']=(string)$attrs['url'];
// 1st vid id playlist id
// http://www.youtube.com/watch?v=mcnIAErKc-g&list=PLEDADE9CA0E65BA78
$videoid=array_keys( $playlists[$idx]['videos']);
$videoid=$videoid[0];
$playlists[$idx]['url'] = "http://www.youtube.com/watch?v=$videoid&list=PL".$playlists[$idx]['id'];
}
, , :
$idx=count($playlists);
$userFeed = $yt->getUserUploads($userName);
foreach ($userFeed as $videoEntry) {
$idx++;
$_id=substr($videoEntry->getVideoWatchPageUrl(),31,11);
if( ! in_array($_id, $playlistvideos) ) {
$_url=$videoEntry->getVideoWatchPageUrl();
$playlists[$idx]['id']=$_id;
$playlists[$idx]['url']=$_url;
$playlists[$idx]['title']=$videoEntry->title->text;
$playlists[$idx]['views']=$videoEntry->getVideoViewCount();
$playlists[$idx]['rating']=$videoEntry->getRating()->average;
$thumbs=$videoEntry->getVideoThumbnails();
$playlists[$idx]['thumb']=$thumbs[0]['url'];
$playlists[$idx]['time']=$videoEntry->getVideoDuration();
}
}
youtube, - , , , . , . , .
function orderBy($data, $field) {
$code = "return strnatcmp(\$a['$field'], \$b['$field']);";
usort($data, create_function('$b,$a', $code));
return $data;
}
$playlists = orderBy($playlists, 'views');
echo "\n\n";
print_r($playlists);
, GData YouTube Zend:
echo "\n\n";
show_methods($videoEntry);
echo "\n\n";
show_methods($playlistListFeed[0]);
echo "\n\n";
show_methods($playlistListFeed);
function show_methods( $_a ) {
echo "<h3>Methods for ".get_class($_a)."</h3>";
$_a= get_class_methods($_a);
$_a=array_unique($_a);
array_multisort(&$_a);
$i=0;
foreach( $_a as $method ) {
$i++;
printf("%-30.30s",$method);
if($i%5==0)
echo "\n";
}
}
Here are two of the array entries to show the structure. Please note that playlists have a key videoswith an array of videos inside it. Testing the keys videoscan tell you a playlist. url- this is what your user can click to open a video or playlist on YouTube.
[1] => Array
(
[title] => Ducatitech.com "HowTo" Adjust your Valves
[id] => 970EC735D36A95E8
[time] => 855
[views] => 144847
[rating] => 4.9322033
[videos] => Array
(
[dIj3nSJGPZw] => http:
[3WQY1MRlmH4] => http:
)
[thumb] => http:
[url] => http:
)
[thumb] => http:
[url] => http:
)
[7] => Array
(
[id] => 80yCiFkOB9g
[url] => http:
[title] => Ducatitech.com: ExactFit Timing Belt Tensile Test
[views] => 7589
[rating] => 4.25
[thumb] => http:
[time] => 625
)
And finally, the kind of things you get from show_methods():
Methods for Zend_Gdata_YouTube_VideoEntry
__construct __get __isset __set __toString
__unset addVideoDeveloperTag delete encode ensureMediaGroupIsNotNull
flushNamespaceLookupCache getAlternateLink getAuthor getCategory getComments
getContent getContributor getControl getDOM getEditLink
getEtag getExtensionAttributes getExtensionElements getFeedLink getFlashPlayerUrl
getHttpClient getId getLicenseLink getLink getLocation
getMajorProtocolVersion getMediaGroup getMediaSource getMinorProtocolVersion getNextLink
getNoEmbed getPreviousLink getPublished getRacy getRating
getRecorded getRights getSelfLink getService getSource
getStatistics getSummary getText getTitle getTitleValue
getUpdated getVideoCategory getVideoCommentFeedUrl getVideoComplaintsLink getVideoDescription
getVideoDeveloperTags getVideoDuration getVideoGeoLocation getVideoId getVideoRatingInfo
getVideoRatingsLink getVideoRecorded getVideoResponsesLink getVideoState getVideoTags
getVideoThumbnails getVideoTitle getVideoViewCount getVideoWatchPageUrl getWhere
getXML isVideoEmbeddable isVideoPrivate lookupNamespace registerAllNamespaces