YouTube Data API video duration is 1 second longer - youtube

For example, the HTTP request GET https://www.googleapis.com/youtube/v3/videos?id=kjDwZNs6GLs&part=contentDetails&key=[API_KEY] gives back the below response payload:
{
"kind": "youtube#videoListResponse",
"etag": "fMWPUAE-QPUqczFLIOqPLkA_HBs",
"items": [
{
"kind": "youtube#video",
"etag": "JVU1XymxBIBUDHOdlmlwJ1nlhTM",
"id": "4ZkEob55qso",
"contentDetails": {
"duration": "PT2M4S",
"dimension": "2d",
"definition": "sd",
"caption": "false",
"licensedContent": true,
"contentRating": {},
"projection": "rectangular"
}
}
],
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
}
}
The duration in the JSON payload is PT2M4S, but if you go check the actual video on YouTube https://www.youtube.com/watch?v=4ZkEob55qso the duration displayed in the video player is 2:03. I couldn't find any mention of this discrepancy in the API documentation https://developers.google.com/youtube/v3/docs/videos#contentDetails.duration, does anyone know exactly why the YT Data API gives back a 1-second longer video duration?

Related

Youtube Playlists API pageInfo.totalResults and items are inconsistent

The Youtube Playlists API playlistResponse.pageInfo.totalResults and playlistResponse.items are inconsistent.
pageInfo.totalResults includes the “Liked videos” playlist, however, items does not include this playlist.
This issue is easier to observe if the number of playlists in the account is less than maxResults.
Call the list method with the following request parameters:
maxResults: 50
mine: true
Actual result: totalResults includes the "Liked Videos" playlist. For example, if the user has 7 playlists, totalResults is 8 as it includes “Liked videos”
Expected result: Either totalResults does not include the “Liked videos” playlist, or items does.
For example, I have 7 playlists, 8 including "Liked Videos". Here totalResults includes the "Liked Vidoes" playlist, whereas items does not.
{
"kind": "youtube#playlistListResponse",
"etag": "MRBqnBy-Y8RQ0TpqYmpqAE_05Lw",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 8,
"resultsPerPage": 7
},
"items": [
{
"kind": "youtube#playlist",
"etag": "5-eWNGtmTPD4efCrIJvSCJwbYfE",
"id": "ozfDHFjXSdWdBqXDbH0W"
},
{
"kind": "youtube#playlist",
"etag": "vAMuqE_49abzgSQTTSroegIi2xU",
"id": "tglNJQrU86MyB7b3iqH5"
},
{
"kind": "youtube#playlist",
"etag": "D5Yv5VC-ZJ5wrJ6BV6Wbv0cSVXw",
"id": "6zz7DncBpOw8Uzx0hYeV"
},
{
"kind": "youtube#playlist",
"etag": "OyI6XYGqAITCIBIgNZhKZh9akXs",
"id": "Zbz6LcJlQYc2l3Wt73kr"
},
{
"kind": "youtube#playlist",
"etag": "Mexdqkd9YgKdOcMtRM8joax6Jfs",
"id": "UjcPmVI0zukbmnvWXiEi"
},
{
"kind": "youtube#playlist",
"etag": "Mexdqkd9YgKdOcMtRM8joax6Jfs",
"id": "p6ocnzio8hKNKAe85m6m"
},
{
"kind": "youtube#playlist",
"etag": "Mexdqkd9YgKdOcMtRM8joax6Jfs",
"id": "OXCW0pdVWeYLjPsXN1mA"
}
]
}

How can I tell if a Youtube video cannot be viewed with Restricted Mode enabled?

Using the youtube Data API - videos: For a few videos using contentDetails.contentRating.ytRating shows that the video is ytAgeRestricted.
However most videos blocked in restricted mode do not have a contentRating in the JSON. E.g.:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=vBkBS4O3yvY&key={API_KEY}
Only the following is returned:
{
"kind": "youtube#videoListResponse",
"etag": "\"abQHWywil_AkNqdqji7_FqiK-u4/MGunVBb8A5UKg1uOrK7QknvhVZ8\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"abQHWywil_AkNqdqji7_FqiK-u4/n1iZ1JVdolHHrm8Nd2wvTRcfe5s\"",
"id": "vBkBS4O3yvY",
"contentDetails": {
"duration": "PT5M41S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true
}
}
]
}

Find out if youtube video is GEMA protected

I am looking to find out wether a video on youtube is blocked (in germany) because its GEMA protected. Ideally via the youtube API.
I would like to know if its protected before the player tells me so.
An example for an video which is GEMA protected (the protection only occurs with german ip):
https://www.youtube.com/watch?v=BgfcToAjfdc
You can check this in an HTTP request by using search.list and specifying part=contentDetails. contentDetails has a blocked section that gives you the region code of any countries where the video is blocked.
For example, for this video, you would call:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=BgfcToAjfdc&key=[API_KEY]
And you get:
{
"kind": "youtube#videoListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/wC5hYBNHuSGatyO7FsTaHrWY5HI\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/4dW1h00OUpXXhtaz2M71v9cXGsQ\"",
"id": "BgfcToAjfdc",
"contentDetails": {
"duration": "PT5M26S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false,
"regionRestriction": {
"blocked": [
"DE"
]
You can see in the blocked section that the video is blocked in Germany.

YouTube Data API V3 search list returns different results than youtube search

I'm trying to use the YouTube data api v3 to get the most viewed videos for a channel. This other SO question said the best way to do this is "search->list with specifying the channelId and order = viewcount".
What I've found is this result sometimes differs from what I see by directly going to a YouTube channel.
For a specific example, I'm looking at this channel:
https://www.youtube.com/user/TheGIIF/videos
It has 3 videos.
Compare that with the following request:
GET https://www.googleapis.com/youtube/v3/search?order=viewCount&part=id&channelId=UCKvRfU5Yaf8XijZPXFJfmlg&key={YOUR_API_KEY}
This returns the following json:
{
"kind": "youtube#searchListResponse",
"etag": "\"k1sYjErg4tK7WaQQxvJkW5fVrfg/xXXGtXCJVmIX8cvSbV7aTD43t0g\"",
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"k1sYjErg4tK7WaQQxvJkW5fVrfg/pX-Ao3RW_w2XWZZfiA3_50lj7Ks\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCKvRfU5Yaf8XijZPXFJfmlg"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"k1sYjErg4tK7WaQQxvJkW5fVrfg/5uoVIdj1bFGaDCWnwAVwP1RwTyI\"",
"id": {
"kind": "youtube#video",
"videoId": "EsX40Bu84O0"
}
}
]
}
So only one available video. Why the discrepancy?
And, not sure if this is just coincidental, but if I search the channel name within the channel:
https://www.youtube.com/user/TheGIIF/search?query=thegiif
I only get back 1 video, the same video as the json response above.

Youtube API 3.0 search videos and get video statistics at single request

I'm searching youtube videos with youtube api 3.0.
I'm using this type of example API request
https://www.googleapis.com/youtube/v3/search?part=snippet&key=[API_KEY]
But i want to get statistics of videos with in the same api request. How to solve this problem.
Note: When I'm using statistics key with part. I got error.
I'm also tried this request
https://www.googleapis.com/youtube/v3/search?part=snippet,statistics&key=[API_KEY]
The resource search.list don't have the part statistics.
Step 1 :
You need to get the videoId of the video: "videoId": "UHdgXkkVyl0" with search.list.
The request :
https://www.googleapis.com/youtube/v3/search?part=id&q=tuto&type=video&key={YOUR_API_KEY}
The response:
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/34CzOO9FXYQg7kdlOeoe59LsWVk\"",
"id": {
"kind": "youtube#video",
"videoId": "UHdgXkkVyl0"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/U303dB0TgZ89ODlqdwuKs5efOdk\"",
"id": {
"kind": "youtube#video",
"videoId": "LvEA2KHWQec"
}
},
Step 2 :
After you have searched videos with search.list you need to make a second call to the API with the resource video.list with parameters :
part: statistics
id: "id of the video found in previous request"
If you have more than one video id you can specify the id of videos with a comma-separated list like :
id: "Xxsdw6zG1bg, Xxsdw6zG1bg,...." )
The request: https://www.googleapis.com/youtube/v3/videos?part=statistics&id=UHdgXkkVyl0%2C+Xxsdw6zG1bg&key={YOUR_API_KEY}
The response will be like this :
{
"kind": "youtube#videoListResponse",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/rxvjZzq2nNqBg7Me5VQv1ToZm64\"",
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 2
},
"items": [
{
"kind": "youtube#video",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/3fah-cngFxFOnytseMYZU1TK_-8\"",
"id": "UHdgXkkVyl0",
"statistics": {
"viewCount": "3070836",
"likeCount": "72140",
"dislikeCount": "1132",
"favoriteCount": "0",
"commentCount": "7798"
}
},
{
"kind": "youtube#video",
"etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/J4xM7Dd23TGYU6on-PESyEIAE9A\"",
"id": "Xxsdw6zG1bg",
"statistics": {
"viewCount": "131487",
"likeCount": "1459",
"dislikeCount": "25",
"favoriteCount": "0",
"commentCount": "39"
}
}
]
}
And you have the statistics !
Unfortunately, dislikeCount attribute has became private, in december 2021. according the youtube api docs.

Resources