I'm trying to build a Youtube query in python that filters out, for instance, category 39 - Horror. I'm looking to something similar to this:
searchResults = YouTube.Search.list('id,snippet', {
maxResults: "10",
q: "The ring",
type: "video",
videoCategoryId: "-10"
});
Or any kind of workaround.
I even contemplated searching without filter and then try to exclude the ones from that category, but the information provided by the query does not include the category of the video. And it's pretty ugly as I really want 10 results, and I may need to make more queries in order to fill the list.
All I've found googling is how to get videos from the specified category.
Can you help me on how to achieve this?
By using the YouTube Data API, you can check here the existing videoCategories.
In this demo available in the Google API Explorer, you can retrieve the videoCategories.
Once you have selected the videoCategoryId
, use the following search request:
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=The+ring®ionCode=US&type=video&videoCategoryId=1&fields=items(id(channelId%2CvideoId)%2Csnippet(channelId%2CchannelTitle%2Cdescription%2Ctitle))%2CnextPageToken%2CpageInfo%2CprevPageToken%2CregionCode&key={YOUR_API_KEY}
Here, I'm using the search.list
request for get videos "from the US region", with videoCategoryId
1 = (Film & Animation)
and retrieving the title
of the YouTube video, its videoId
, the channel title
and channel_id
from the channel who uploaded the video.
Here is the demo.
It seems that the videoCategoryId
is not supported in all regions (this might be the reason I couldn't retrieve videos with videoCategoryId=39
"which is the Horror category in the US").
For more information, read this answer.