youtube api 过滤搜索

发布于 2024-12-31 23:56:24 字数 1940 浏览 0 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

完美的未来在梦里 2025-01-07 23:56:25

无法从搜索结果中排除高清视频。摘自文档:

要仅检索高清视频,请将 hd 参数值设置为 true 或在请求中包含该参数但不指定参数值。请注意,false 不是有效的参数值,并且您不能限制搜索结果以排除高清视频。 API 的默认行为是返回所有视频,无论其分辨率如何。在视频源条目中, 标签表示视频包含高清内容。

YouTube 播放器 JavaScript API 提供了设置视频质量的方法,您可以在视频加载时执行此操作。

也不可能排除音乐视频以外的内容。不过,据我所知,您可以搜索仅由 YouTube 合作伙伴上传的视频,其中包括 VEVO:

uploader 参数仅支持搜索请求,可让您将查询限制为 YouTube 合作伙伴视频。 YouTube 合作伙伴是指已获准加入并参与 YouTube 合作伙伴计划的个人或组织。 uploader 参数的值必须是 partner

文档中提供了用于搜索视频的所有选项

It's not possible to exclude HD videos from search results. Taken from docs:

To only retrieve HD videos, set the hd parameter value to true or include the parameter in your request but do not specify a parameter value. Note that false is not a valid parameter value, and you cannot restrict search results to exclude HD videos. The API's default behavior is to return all videos, regardless of their resolution. In a video feed entry, the <yt:hd> tag indicates that a video contains HD content.

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:

The uploader parameter, which is only supported for search requests, lets you restrict a query to YouTube partner videos. A YouTube partner is a person or organization that has been accepted into and participates in the YouTube Partner Program. The uploader parameter's value must be partner.

All the options for searching videos are present in the docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文