gpt4 book ai didi

php - 使用此代码检查YouTube视频是否可嵌入

转载 作者:行者123 更新时间:2023-12-03 06:04:00 25 4
gpt4 key购买 nike

函数parseVideoEntry($ entry)
{

  $obj= new stdClass;

// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
$obj->title = $media->group->title;
$obj->description = $media->group->description;

// get video player URL
$attrs = $media->group->player->attributes();
$obj->watchURL = $attrs['url'];

// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$obj->thumbnailURL = $attrs['url'];

// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$obj->length = $attrs['seconds'];

// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$obj->viewCount = $attrs['viewCount'];

// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$obj->rating = $attrs['average'];
} else {
$obj->rating = 0;
}

// get <gd:comments> node for video comments
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->comments->feedLink) {
$attrs = $gd->comments->feedLink->attributes();
$obj->commentsURL = $attrs['href'];
$obj->commentsCount = $attrs['countHint'];
}

//Get the author
$obj->author = $entry->author->name;
$obj->authorURL = $entry->author->uri;


// get feed URL for video responses
$entry->registerXPathNamespace('feed', 'http://www.w3.org/2005/Atom');
$nodeset = $entry->xpath("feed:link[@rel='http://gdata.youtube.com/schemas/
2007#video.responses']");
if (count($nodeset) > 0) {
$obj->responsesURL = $nodeset[0]['href'];
}

// get feed URL for related videos
$entry->registerXPathNamespace('feed', 'http://www.w3.org/2005/Atom');
$nodeset = $entry->xpath("feed:link[@rel='http://gdata.youtube.com/schemas/
2007#video.related']");
if (count($nodeset) > 0) {
$obj->relatedURL = $nodeset[0]['href'];
}

// return object to caller
return $obj;

}
    $vid = stripslashes($_POST['url']);
$string = $vid;
$url = parse_url($string);
parse_str($url['query']);

if(isset($v))
{

// set video data feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'. $v;

// read feed into SimpleXML object
$entry = simplexml_load_file($feedURL);

// parse video entry
$video = parseVideoEntry($entry);


//These variables include the video information
$video_title = $video->title;
$video_lenght =$video->length;

我曾尝试查看API和相关内容,但我不习惯使用这些Apis,因此我无法依靠解决方案,我必须说的是设计师而不是开发人员,如果有人可以帮助我,我将非常感谢它...

我想检查视频是否完全可嵌入,没有区域限制和其他内容

谢谢

最佳答案

您可以通过将format限制为5来检查是否允许视频嵌入,还可以通过将restriction设置为ip address来查看视频在特定区域是否可用,如下所示:

http://gdata.youtube.com/feeds/api/videos?restriction=xxx.xxx.xxx.xxx&format=5&orderby=relevance&q=xxx

这将通过查询 "xxx"查找视频,这些视频可在ip地址 xxx.xxx.xxx.xxx所在的区域中播放并允许嵌入,并按相关性对其进行排序。

格式= 5的引用: http://code.google.com/apis/youtube/2.0/reference.html#format

关于php - 使用此代码检查YouTube视频是否可嵌入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8113930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com