youtube api 过滤搜索
我有一个使用 Youtube Api 的音乐网站。我想按大小过滤视频。因为当有高质量视频、音乐会表演等时,流媒体可能会在低速互联网连接下出现问题。 另外,我想展示纯音乐视频。我不想展示音乐会唱片、翻唱或混音等。我可以通过哪种方式来过滤原始音乐唱片。
顺便说一句,我使用的搜索代码是
/*
$params: string, artist_name - song
returns an array >> video_id, video name, video length
*/
function youtube_find_video($params)
{
str_replace("'", "", $params);
$q = preg_replace('/[[:space:]]/', '/', trim($params));
$q = utf8_decode(utf8_encode($q));
$replacements = array(',', '?', '!', '.');
$q = str_replace($replacements, "", $q);
$feedURL = "http://gdata.youtube.com/feeds/api/videos/-/{$q}?orderby=relevance&max-results=1";
$sxml = simplexml_load_file($feedURL);
if(!$sxml)
{
return false;
}
else{
$entry = $sxml->entry;
if(!$entry)
{
return false;
}
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
if($media)
{
// get video player URL
$attrs = $media->group->player->attributes();
$url = $attrs['url'];
if(!$url)
{
return false;
break;
}
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
$watch['id'] = $my_array_of_vars['v'];
// get video name
$watch['name'] = $media->group->title;
// get <yt:duration> node for video length[minute]
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$watch['length'] = sprintf("%0.2f", $attrs['seconds']/60);
$watch = simplexml_kurtul($watch);
return $watch;
}
else
{
return false;
}
}
}
I have a music site that use Youtube Api. I want to filter the videos by size. Because when there is a high quality video, concert shows etc. streaming can hobble at low speed internet connections.
Also, i want to show pure music videos. I don't want show concert record, cover or remix etc. Which way do i fallow to filter original music records.
By the way search codes i am using are
/*
$params: string, artist_name - song
returns an array >> video_id, video name, video length
*/
function youtube_find_video($params)
{
str_replace("'", "", $params);
$q = preg_replace('/[[:space:]]/', '/', trim($params));
$q = utf8_decode(utf8_encode($q));
$replacements = array(',', '?', '!', '.');
$q = str_replace($replacements, "", $q);
$feedURL = "http://gdata.youtube.com/feeds/api/videos/-/{$q}?orderby=relevance&max-results=1";
$sxml = simplexml_load_file($feedURL);
if(!$sxml)
{
return false;
}
else{
$entry = $sxml->entry;
if(!$entry)
{
return false;
}
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
if($media)
{
// get video player URL
$attrs = $media->group->player->attributes();
$url = $attrs['url'];
if(!$url)
{
return false;
break;
}
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
$watch['id'] = $my_array_of_vars['v'];
// get video name
$watch['name'] = $media->group->title;
// get <yt:duration> node for video length[minute]
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$watch['length'] = sprintf("%0.2f", $attrs['seconds']/60);
$watch = simplexml_kurtul($watch);
return $watch;
}
else
{
return false;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法从搜索结果中排除高清视频。摘自文档:
YouTube 播放器 JavaScript API 提供了设置视频质量的方法,您可以在视频加载时执行此操作。
也不可能排除音乐视频以外的内容。不过,据我所知,您可以搜索仅由 YouTube 合作伙伴上传的视频,其中包括 VEVO:
文档中提供了用于搜索视频的所有选项。
It's not possible to exclude HD videos from search results. Taken from docs:
The YouTube player JavaScript API has a method for setting the video quality, which you could do upon video load.
It's not possible to exclude other than music videos either. However, you can search for videos uploaded only by YouTube partners, and that includes VEVO, as far as I know:
All the options for searching videos are present in the docs.