जब से मैं बर्बाद सारा दिन "बस अपना वेबसाइट पर दिखाने के लिए अपने वीडियो की एक सूची प्राप्त करने की कोशिश", मैंने सोचा कि मैं कुछ नमूना कोड है कि बस मुझे बहुत कुछ सिखाया तक चिपका था। और जैसा कि अपेक्षित है, Zend_Gdata_YouTube::
पहले से ही Magento प्रतिष्ठानों में है। नीचे दिए गए कोड "वीडियो", जहां प्लेलिस्ट एक दूसरे के साथ अन्य वीडियो के रूप में सूची में एक ही दिखाई देते हैं का एक एकीकृत सूची पेश करेंगे। अपडेट: मैंने Magento extension out of my answer बनाया है।
यह सिर्फ एक सामान्य php मैं var/निर्यात में गिरा दिया है। शीर्ष पर, आपको app/Mage.php
शामिल करना होगा।
<?
$userName='cacycleworksdotcom';
$yt = new Zend_Gdata_YouTube();
//////////////////////////////////////////////////////////////////////
// Get playlists.
$playlistListFeed = $yt->retrieveAllEntriesForFeed($yt->getPlaylistListFeed($userName));
$playlist=Array();
$videoEntry=NULL;
$playlistvideos=Array();
यहाँ, आप $playlistListFeed
में Zend वस्तुओं की एक सरणी मिल गया है।
foreach ($playlistListFeed as $idx=>$playlistListEntry) {
// process each playlist
$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) {
// info of each video inside this playlist
$_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 का उपयोग थंबनेल डेटा प्राप्त करने के लिए समाप्त हो गया।
//////////////////////////////////////////////////////////////////////
// Videos themselves
$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();
// these need resizing to width="320" height="180"
$playlists[$idx]['thumb']=$thumbs[0]['url'];
$playlists[$idx]['time']=$videoEntry->getVideoDuration();
} // else { echo "$_id already in playlist\n"; }
}
यहाँ हम शीर्ष पर, हमारे यूट्यूब वीडियो की एक सरणी है playlsits द्वारा आदेश दिया जाता है:
$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'];
}
प्लेलिस्ट नियंत्रित किया जाता है, अब के शेष वीडियो कि प्लेलिस्ट में नहीं हैं मिलता है सबसे पहले सबसे पहले, उपयोगकर्ता के वीडियो के बाद प्लेलिस्ट में समान पुराने क्रम में दिखाई नहीं दे रहा था। इसलिए मुझे आदेश बदलने के लिए यह सरल सॉर्ट कोड मिला। वहाँ महान लेख छंटाई और पढ़ने अगर आप यहाँ बहुआयामी सरणियों सॉर्ट करने के लिए कोशिश कर रहे हैं लायक के बारे में।
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";
}
}
यहाँ संरचना दिखाने के लिए सरणी प्रविष्टियों में से दो हैं:
//////////////////////////////////////////////////////////////////////
// http://www.the-art-of-web.com/php/sortarray/
function orderBy($data, $field) {
$code = "return strnatcmp(\$a['$field'], \$b['$field']);";
// swap $a and $b to make descending instead of ascending
usort($data, create_function('$b,$a', $code)); //('$a,$b', $code));
return $data;
}
$playlists = orderBy($playlists, 'views');
//////////////////////////////////////////////////////////////////////
echo "\n\n";
print_r($playlists);
यहाँ कोड है कि मदद की मुझे इन नासमझ GData यूट्यूब Zend वस्तुओं के साथ काम शुरू करने है। नोट प्लेलिस्ट इसके अंदर वीडियो की एक सरणी के साथ एक videos
कुंजी है।videos
कुंजी के लिए परीक्षण आपको बता सकता है कि यह एक प्लेलिस्ट है। url
वह यूट्यूब साइट पर वीडियो या प्लेलिस्ट खोलने के लिए क्लिक कर सकता है।
[1] => Array
(
[title] => Ducatitech.com "HowTo" Adjust your Valves
[id] => 970EC735D36A95E8
[time] => 855
[views] => 144847
[rating] => 4.9322033
[videos] => Array
(
[dIj3nSJGPZw] => http://www.youtube.com/watch?v=dIj3nSJGPZw&feature=youtube_gdata_player
[3WQY1MRlmH4] => http://www.youtube.com/watch?v=3WQY1MRlmH4&feature=youtube_gdata_player
)
[thumb] => http://i.ytimg.com/vi/dIj3nSJGPZw/mqdefault.jpg
[url] => http://www.youtube.com/watch?v=dIj3nSJGPZw&list=PL970EC735D36A95E8
)
[thumb] => http://i.ytimg.com/vi/mcnIAErKc-g/mqdefault.jpg
[url] => http://www.youtube.com/watch?v=mcnIAErKc-g&list=PLEDADE9CA0E65BA78
)
[7] => Array
(
[id] => 80yCiFkOB9g
[url] => http://www.youtube.com/watch?v=80yCiFkOB9g&feature=youtube_gdata_player
[title] => Ducatitech.com: ExactFit Timing Belt Tensile Test
[views] => 7589
[rating] => 4.25
[thumb] => http://i.ytimg.com/vi/80yCiFkOB9g/0.jpg
[time] => 625
)
और अंत में, आप 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
मैं यह कहा जाना चाहिए लगता है, मुझे पता है कि मैं तदनुसार कहा पैरामीटर पर ध्यान देने और उसके बाद संशोधित यूआरआई getPlaylistListFeed को संशोधित कर सकता है , लेकिन मुझे लगता है कि मुझे लगता है कि मुझे ज़ेंड उत्पाद में इतनी सरल कमी नहीं मिली है। – poolnoodl