Get title from YouTube videos

I want to extract the Title of YouTube's videos. How can I do this?

Thanks.


Easiest way to obtain information about a youtube video afaik is to parse the string retrieved from: http://youtube.com/get_video_info?video_id=XXXXXXXX

Using something like PHP's parse_str(), you can obtain a nice array of nearly anything about the video:

$content = file_get_contents("http://youtube.com/get_video_info?video_id=".$id);
parse_str($content, $ytarr);
echo $ytarr['title'];

That will print the title for the video using $id as the video's id.


One way to do this would be to retrieve the video from youtube as shown here

Then extract the title out of the atom feed sent by youtube. A sample feed is shown here


Using JavaScript data API:

var loadInfo = function (videoId) {
    var gdata = document.createElement("script");
    gdata.src = "http://gdata.youtube.com/feeds/api/videos/" + videoId + "?v=2&alt=jsonc&callback=storeInfo";
    var body = document.getElementsByTagName("body")[0];
    body.appendChild(gdata);
};

var storeInfo = function (info) {
    console.log(info.data.title);
};

Then you just need to call loadInfo(videoId) .

More informations are available on the API documentation.

链接地址: http://www.djcxy.com/p/28906.html

上一篇: YouTube嵌入视频:设置不同的缩略图

下一篇: 从YouTube视频获取标题