Youtube API - 仅搜索音乐视频 [英] Youtube API - search only music videos

查看:17
本文介绍了Youtube API - 仅搜索音乐视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索音乐视频会产生许多非音乐视频的结果 - 例如采访被搜索的艺术家.在我看来,只有音乐视频应该属于音乐类别,或者音乐视频应该有一个单独的类别,或者视频应该被标记为多个类别,我们可以根据逻辑进行过滤.

Searching for music videos yields many results that are not music videos - e.g. interviews with the searched for artist. In my opinion only music videos should be in the Music category, or there should be a separate category for Music videos, or videos should be tagged with multiple categories upon which we can logically filter.

是否有任何功能/过滤器可以与 API 一起使用以仅返回音乐视频.

Is there any functionality/filter which I can use along with the API to return only the music videos.

以下是我的代码:-

def search_videos(self,keyword,maxResults=10):
    youtube = build('youtube','v3',developerKey=KEY)

    response = youtube.search().list(q=keyword,
                                     part="id,snippet",
                                     maxResults=maxResults
                                     ).execute().get("items", [])

    videos = []

    for record in response:
        if record["id"]["kind"] == "youtube#video":
            title = record["snippet"]["title"].encode(encoding='UTF-8',errors='strict')
            youtube_id = record["id"]["videoId"].encode(encoding='UTF-8',errors='strict')
            videos.append({
                'youtube_id': youtube_id,
                'title' : title
            })

    return videos

推荐答案

在您的搜索中,您可以指定 videoCategoryId应该 只为您提供特定的结果除了具有关键字音乐视频"之外,我还希望为您提供更多相关结果.如果您想尝试一下,音乐的 videoCategoryId 为10"(假设您在美国).请注意,您还必须指定 type=video.除此之外,我不确定除了试图提高其他人发布的问题的知名度之外,您还能做什么.

In your search, you could specify the videoCategoryId, which is supposed to only give you results specific to that category (but I think it's slightly bugged now) in addition to having the keyword "music video", which I hope gives you more relevant results. If you want to try it, the videoCategoryId for music is "10" (assuming you're in the US). Note that you will also have to specify type=video. Other than that, I'm not sure what else you can do besides trying to get more visibility on the issue the others have posted.

这篇关于Youtube API - 仅搜索音乐视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆