Get the music genres in YouTube

2020-05-28 11:05发布

When we view the YouTube page, and click Music, we are able to see them on different genre's like "Rap", "Rock", "Country", etc.

How can I retrieve this data (the genre-wise listing of videos) using the YouTube Apis.?

标签: youtube-api
3条回答
仙女界的扛把子
2楼-- · 2020-05-28 11:19

One way to do this is using the Topics API integration with V3 of the API. Take a look at the videos.list() API call. Plug in these values:

  • part: topicDetails
  • id: fWNaR-rxAic
  • fields: items/topicDetails/topicIds

The ID of that video corresponds to Carly Rae Jepsen's "Call Me Maybe". When you look at the JSON response, you'll see a list of topic IDs:

[ "/m/015f7", "/m/0h55y27", "/m/0gkxzs6", "/m/064t9" ]

These are Freebase machine IDs. You would then make a Freebase API call to retrieve information about that particular topic. For instance, /m/064t9 corresponds to "Pop Music".

Thise method won't work for 100% of videos on YouTube; Metallica's "Whiskey in a Jar" only returns topics for the song and the band, however, Britney Spear's "I Want to Go" correctly returns a machine ID for "Pop Music".

The reason for this is that the Topic is often machine generated, not human curated (though we do quality checks). We did a Google I/O talk about how this works. The good news is that once you DO have a machine ID, it's very easy to find other videos by topic ID. Our samples demonstrate how to do this.

查看更多
Luminary・发光体
3楼-- · 2020-05-28 11:19

For anyone wondering about this now (2017) freebase is deprecated and so instead you should use the list currently provided here: https://gist.github.com/stpe/2951130dfc8f1d0d1a2ad736bef3b703

Ikai Lan is still correct that the part is topicDetails to get this information from the API.

查看更多
冷血范
4楼-- · 2020-05-28 11:27

In freebase you can ask for music genre mids. For example in: http://www.freebase.com/search?query=rock you get that /m/06by7 = rock. With this id you do a query on youtube and get videos regarding this genre;

Try it https://developers.google.com/youtube/v3/docs/search/list#try-it with this conditions:

part: snippet
topicId: /m/06by7
查看更多
登录 后发表回答