Prevent live broadcast in search result using Youtube api v3 - youtube-api

I am using YouTube API v3 to search for videos using Type = "video" with
snippet result.
Is there a way to tell YouTube API to ignore Live or Upcoming or Completed broadcasts videos in the result? Just need regular video search.

You may check the Search:list to know the parameters that this query supports.
eventType - The eventType parameter restricts a search to broadcast events. If you specify a value for this parameter, you must also set the type parameter's value to video.
Acceptable values are:
completed – Only include completed broadcasts.
live – Only include active broadcasts.
upcoming – Only include upcoming broadcasts.
Also from this post Exclude live events from YouTube data api search query:
on closer inspection, not all livestreams even seem to have the marker [liveBroadcastContent] set. I have found some that are set to none as with ordinary videos.

Related

How do I get channel IDs for all YouTube channels in Japan?

I want to get channel IDs for all YouTube channels in Japan.
I tried to set the following parameters and call /search of YouTube Data API v3.
part: id
maxResults: 50
regionCode: jp
type: channel
pageInfo.totalResults in the API response is about 200,000 but actually I can only get 583 channel IDs.
583 is too little even if pageInfo.totalResults is an approximate value.
I would like to know how to get all the channel IDs in Japan, either by using the API or not.
I hope you will be able to provide the related information.
I tried to do almost the same for France. As said #stvar there isn't any appropriate endpoint to do so. However with patience and work we can make a kind of work around. My method only retrieves Japanese YouTube channels having indirectly publicly interacted with your starting set (see below).
Get a good starting set (in order to maximize the discover of the Japanese YouTube channels graph). I recommend you for instance to retrieve the top 100 Japanese YouTube channels sorted by view count by using SocialBlade.
For each channel discovered by the comments retrieved at step 3 (automatically) choose whether or not it is a Japanese YouTube channel. You can retrieve this piece of information if it is available for the channel in the "About" tab. To do it in an automatic way check whether or not snippet["country"] == "JP" in https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=CHANNEL_ID&key=YOUR_API_KEY If country isn't defined you can try to guess (automatically) whether or not it is a Japanese YouTube channel by making more complex checks see isFrench function. These checks are based on "About" tab and uploaded videos.
If the channel is interesting you (is Japanese) retrieve all comments (and so the YouTube channel about channel's videos and in the community tab using CommentThreads: list with part containing snippet and allThreadsRelatedToChannelId filter. If this method doesn't return any data because a video has disabled comments then retrieve the videos list and comments associated using (a) then CommentThreads: list with filter videoId. The approach (a) consists in getting the uploads auto-created playlist id of the YouTube channel by using Channels: list with contentDetails in part and then use PlaylistItems: list to retrieve all public videos uploaded on this YouTube channel. And if the YouTube channel contains more than 20 000 videos which is the upper limit for playlist size, use this script instead of (a). The script consists in faking requests done when browsing videos on a YouTube channel.
Then continue to dive into the Japanese YouTube channel graph by discovering Japanese YouTube channels through the comments found in your starting set and so on.
You can have a look for more details and some helping tools on my GitHub repository dedicated to the same approach for France (I was trying to list all comments let on French YouTube videos).
Of course you might need multithreading and group your YouTube Data API v3 request to reach maxResults upper limit in order to maximize your quota efficiency. Good luck.

Is there a way to get a list of Youtube videos sorted by view count

I am trying to collect a large list of YouTube's most watched videos for a data science application. I tried to use the YouTube Data API with the following query:
https://www.googleapis.com/youtube/v3/search&order=viewCount&type=video&regionCode=US&key=API_KEY,
but it does not seem to give me the same video ideas as in this list: https://en.wikipedia.org/wiki/List_of_most-viewed_YouTube_videos
Could someone tell me how I should do it?
Using the Search.list API endpoint is one way to search for the most viewed videos pertaining to a given region.
There's another endpoint -- Videos.list -- that, when queried with chart set to mostPopular, gives back:
chart (string)
The chart parameter identifies the chart that you want to retrieve.
Acceptable values are:
mostPopular – Return the most popular videos for the specified content region and video category.
As per the specification of videoCategoryId:
By default, charts are not restricted to a particular category.
Therefore, you may safely invoke Videos.list with chart=mostPopular and regionCode=US, without passing to it any videoCategoryId.
These two are the only API means that accomplish the task described by your post.

Including topics in search results

I'm interested in getting topics as part of the results when searching with:
https://www.googleapis.com/youtube/v3/search?
For instance, when searching Dance Music on the YouTube website, it shows some videos and on the side there's a Electronic Dance Music topic showing up.
How can I get that using the API?
I'll also be fine search for topics in a different API call.
Use the Search: list method which returns a collection of search results that match the query parameters specified in the API request. By default, a search result set identifies matching video, channel, and playlist resources, but you can also configure queries to only retrieve a specific type of resource such as the topicId parameter.
The topicId parameter indicates that the API response should only contain resources associated with the specified topic. The value identifies a Freebase topic ID.
Important: Due to the deprecation of Freebase and the Freebase API, the topicId parameter started working differently as of February 27, 2017. At that time, YouTube started supporting a small set of curated topic IDs, and you can only use that smaller set of IDs as values for this parameter.
You may use the API Explorer to try the sample request.

YouTube Data API (v3) search filters are broken

Note: I am using a YouTube Iframe from a webview inside a Chrome App.
This is what YouTube's API states:
videoSyndicated
The videoSyndicated parameter lets you to restrict a search to only
videos that can be played outside youtube.com. If you specify a value
for this parameter, you must also set the type parameter's value to
video.
videoLicense
The videoLicense parameter filters search results to only include
videos with a particular license. YouTube lets video uploaders choose
to attach either the Creative Commons license or the standard YouTube
license to each of their videos. If you specify a value for this
parameter, you must also set the type parameter's value to video.
videoEmbeddable
The videoEmbeddable parameter lets you to restrict a search to only
videos that can be embedded into a webpage. If you specify a value for
this parameter, you must also set the type parameter's value to video.
Even if I turn them all on, I still get error messages like
This video contains content from X
Example video: https://www.youtube.com/watch?v=TMSIR210mRg
Q: Why is this the case, and how do I ensure that the search results only include the videos that are playable from my website?
I realized it's not that the filters are broken, it's that the videos have domain-specific blacklists. For example, certain videos cannot be played from mobile devices or in my case, from a chrome app that has chrome-extension:// domain.
There is a separate check for copyright claims. The legal copyright holder of some content on the video ( usually the music ) has the legal right to restrict or block the embed on certain sites. This info is currently not available through the YouTube API.

Youtube API 2.0 Checking if a video is age restricted

I would like to check and see if a youtube video is age restricted. There are not many videos that are, but some are. I have been digging around in the youtube api documents and on the internet, but can't seem to find a way to detect this.
I am using the Youtube API V2 and only looking for one video at a time.
To check whether a video is (age) restricted in a given region, you can take a look at the media:rating attribute of the video entry, which is documented at
https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_media:rating
If you want to do a search and filter out videos that are age restricted, you can use the safeSearch=strict parameter:
https://developers.google.com/youtube/2.0/reference#safeSearchsp
I agree to Greg Schechter. The actual question was like if we have a video id (eg: In the link http://www.youtube.com/watch?v=RyDY0hiMZy8 the video id is RyDY0hiMZy8), how can we get the age restriction details based on that?
There is an API provided by Youtube to get the details based on the video id. For the above example the API link is:
http://gdata.youtube.com/feeds/api/videos/RyDY0hiMZy8?v=2&alt=json
But there is no information about the age restriction in the response.
Update on the above post:
In the API response from http://gdata.youtube.com/feeds/api/videos/tA4wytG3uh0?v=2&alt=json
we have a media$rating content coming and the data coming there can be compared with the rules mentioned in the link https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_media:rating
For non restricted videos, the media$rating value is not coming in the response. eg: in the link http://gdata.youtube.com/feeds/api/videos/RyDY0hiMZy8?v=2&alt=json
Any updates are welcome.
Age gating is not supported for embedded playbacks; so it's not something that is returned in the YouTube data api.
You can un-restrict those videos by following this link:
https://www.quora.com/How-do-you-change-the-settings-of-the-the-age-restrictrincts-on-my-YouTube-videos/answer/Doyle-Lorraine
Then your iframes should be back to normal.

Resources