Youtube API get video duration from the XML

孤街醉人 提交于 2019-12-22 00:52:38

问题


Consider Youtube API XML files like http://gdata.youtube.com/feeds/api/videos/$id One particular XML data file is http://gdata.youtube.com/feeds/api/videos/GI6CfKcMhjY The following function gets the title of the video according to the XML url:

function ytTitle($ytid,$ytURLConstant){
    $url = $ytURLConstant.$ytid;
    $doc = new DOMDocument;
    $doc->load($url);
    echo $title = $doc->getElementsByTagName("title")->item(0)->nodeValue;
}

As I see there is video duration in the XML file:

<media:title type='plain'>Jack Sparrow (feat. Michael Bolton)</media:title><yt:duration seconds='197'/>

As I am an XML newbie any help concerning getting the video duration will be greatly appreciated.


回答1:


I had a similar problem with Youtube API and I find this very helpful site

http://viewsboard.com/boards/view/discussion/2/263



来源:https://stackoverflow.com/questions/7378116/youtube-api-get-video-duration-from-the-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!