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

查看:88
本文介绍了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 ,它是 suppose ,仅用于提供特定于您的结果除了包含关键字音乐视频"之外,还属于该类别(但我认为它现在已经有些问题了),希望可以为您带来更多相关的结果.如果您想尝试一下,则音乐的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天全站免登陆