本文实例讲述了php获取YouTube视频信息的方法。分享给大家供大家参考。具体分析如下:
YouTube的视频地址格式
https://www.youtube.com/watch?v=[VIDEO_ID]
例子:https://www.youtube.com/watch?v=psvkyf3PzjE
代码如下://根据video id 获取YouTube视频信息
function getYouTubeInfo($video_id){
$content = file_get_contents("http://youtube.com/get_video_info?video_id=" . $video_id);
parse_str($content, $ytarr);
return $ytarr;
}
$video_id = 'psvkyf3PzjE';
$ytinfo = getYouTubeInfo($video_id);
echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';
echo '<p><strong>'.$ytinfo['title'].'</strong></p>'; // 标题
echo '<p><img src="'.$ytinfo['thumbnail_url'].'"></p>'; // 缩略图
echo '<p><img src="'.$ytinfo['iurlmq'].'"></p>'; // 中图
echo '<p><img src="'.$ytinfo['iurl'].'"></p>'; // 大图
echo '<pre>';
print_r($ytinfo);
echo '</pre>';
输出如下图所示:
更多信息如下:
代码如下:Array
(
[ttsurl] => http://www.youtube.com/api/timedtext?v=psvkyf3PzjE&expire=1405449775&asr_langs=fr%2Cpt%2Cnl%2Ces%2Cit%2Cde%2Cen%2Cja%2Cru%2Cko&caps=asr&sparams=asr_langs%2Ccaps%2Cv%2Cexpire&signature=20784B16B4F6C4CF09E27D1267B033EE39ECAD7F.2815379028207B479B0DFC818804EE8B07EFDA96&key=yttt1&hl=zh_HK
[hl] => zh_HK
[iv_load_policy] => 1
[length_seconds] => 151
[adsense_video_doc_id] => yt_psvkyf3PzjE
[iv_allow_in_place_switch] => 1
[plid] => AAT-OeiZGx1hsKAp
[title] => 10 Amazing Practical Jokes
[ptchn] => vGMGQC8gNkd4gwxSbABIlw
[sw] => 1.0
[pyv_in_related_cafe_experiment_id] =>
[ad_device] => 1
[rmktPingThreshold] => 0
[use_cipher_signature] => False
[account_playback_token] => QUFFLUhqay1iUzhSU0V5RUZreHlFb3JDcUx3eVJOSnVRd3xBQ3Jtc0trVHRiY1RxejNPNmt4ZHlUS0dNSzgzOUFTOW5Pd05mN2kxenNaWU12UGxzWExRVzlFZG1vdmxFRDZpNXBfVUQzdGpYbEZNbXZ3SG9PX0VucHlaQmJxWEtJbWNUVk9qYTFiUi03NGpJNU5pbkNhaXdMOA==
新闻热点
疑难解答