栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

YouTube API-提取视频ID

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

YouTube API-提取视频ID

以下是使用正则表达式从URL提取youtube ID的示例函数:

function youtube_id_from_url($url) {    $pattern =         '%^# Match any youtube URL        (?:https?://)?  # Optional scheme. Either http or https        (?:www.)?      # Optional www subdomain        (?:  # Group host alternatives          youtu.be/    # Either youtu.be,        | youtube.com  # or youtube.com          (?:# Group path alternatives /embed/     # Either /embed/          | /v/         # or /v/          | /watch?v=  # or /watch?v=          )  # End path alternatives.        )    # End host alternatives.        ([w-]{10,12})  # Allow 10-12 for 11 char youtube id.        $%x'        ;    $result = preg_match($pattern, $url, $matches);    if ($result) {        return $matches[1];    }    return false;}echo youtube_id_from_url('http://youtu.be/NLqAF9hrVbY'); # NLqAF9hrVbY

它不是您要查找的API的直接来源,但可能会有所帮助。Youtube有一项固定服务:

$url = 'http://youtu.be/NLqAF9hrVbY';var_dump(json_depre(file_get_contents(sprintf('http://www.youtube.com/oembed?url=%s&format=json', urlenpre($url)))));

其中提供了有关URL的更多元信息:

object(stdClass)#1 (13) {  ["provider_url"]=>  string(23) "http://www.youtube.com/"  ["title"]=>  string(63) "Hang Gliding: 3 Flights in 8 Days at Northside Point of the Mtn"  ["html"]=>  string(411) "<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/NLqAF9hrVbY?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscr-iptaccess" value="always"></param><embed src="http://www.youtube.com/v/NLqAF9hrVbY?version=3" type="application/x-shockwave-flash" width="425" height="344"  allowfullscreen="true"></embed></object>"  ["author_name"]=>  string(11) "widgewunner"  ["height"]=>  int(344)  ["thumbnail_width"]=>  int(480)  ["width"]=>  int(425)  ["version"]=>  string(3) "1.0"  ["author_url"]=>  string(39) "http://www.youtube.com/user/widgewunner"  ["provider_name"]=>  string(7) "YouTube"  ["thumbnail_url"]=>  string(48) "http://i3.ytimg.com/vi/NLqAF9hrVbY/hqdefault.jpg"  ["type"]=>  string(5) "video"  ["thumbnail_height"]=>  int(360)}

但是ID并不是响应的直接部分。但是,它可能包含您要查找的信息,并且可能对验证youtube URL有用。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/597055.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号