By using search example, i am able to get video details like name, id, thumb nail URL. But how can i get video total duration using YouTube Data API. Thanks in advance.
You will have to make a call to the Youtube Data API's Video resource after you make the search call. You can put up to 50 video id's in search, so you wont have to call it for each element.
https://developers.google.com/youtube/v3/docs/videos/list
You'll want to set part=contentDetails, because duration is there.
For example the following call:
https://www.googleapis.com/youtube/v3/videos?id=9bZkp7q19f0&part=contentDetails&key={YOUR_API_KEY}
Gives this result:
{
"kind": "youtube#videoListResponse",
"etag": "\"XlbeM5oNbUofJuiuGi6IkumnZR8/ny1S4th-ku477VARrY_U4tIqcTw\"",
"items": [
{
"id": "9bZkp7q19f0",
"kind": "youtube#video",
"etag": "\"XlbeM5oNbUofJuiuGi6IkumnZR8/HN8ILnw-DBXyCcTsc7JG0z51BGg\"",
"contentDetails": {
"duration": "PT4M13S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true,
"regionRestriction": {
"blocked": [
"DE"
]
}
}
}
]
}
Related
As you may know some Content-Creators on YouTube not only got one Channel. Some Channels have a Channel-Tab where you can see the other channels hosted by the creator. I would like to get these channels, but unfortunately the YouTube-API can't retrieve the data via channels: list. Is there a parameter or another function how I can get this information?
Channel example: https://www.youtube.com/c/DunklerParabelritter/channels
Thank you in advance,
Aaron!
It seems that once again YouTube Data API v3 doesn't provide a basic feature.
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/channels?part=channels&id=CHANNEL_ID the data you are looking for are in item["channelSections"].
Note that the channel id associated to the channel you shared is UCK4LDHLxBqiAtcwCm4z7DRg, so you would obtain:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UCK4LDHLxBqiAtcwCm4z7DRg",
"channelSections": [
{
"title": "Mit Empfehlung des Dunklen!",
"sectionChannels": [
{
"channelId": "UCWZu-P34DVZUVrYAROU3Cmw",
"title": "Prinz",
"thumbnails": [
{
"url": "https:\/\/yt3.googleusercontent.com\/knQfgyidSRlVLQfAw64R9DFWmnQt3BwdJUaRW1zHEVRgLswRcR9lsan_S4tGe4BfYJyo9Jppbg=s48-c-k-c0x00ffffff-no-rj-mo",
"width": 48,
"height": 48
},
...
],
"videoCount": 128,
"subscriberCount": 111000
},
...
],
"nextPageToken": null
}
]
}
]
}
Is there any way to know whether a video is free or paid?
What property is indicates videos which needs Payment?
https://www.youtube.com/watch?v=wWu03qUnHlk
{
"kind": "youtube#video",
"etag": "\"_gJQceDMxJ8gP-8T2HLXUoURK8c/9J_Rsvw1p9XGci8Ne9GRDP6m6NE\"",
"id": "wWu03qUnHlk",
"contentDetails": {
"duration": "PT1H11M51S",
"dimension": "2d",
"definition": "hd",
"caption": "true",
"licensedContent": true,
"regionRestriction": {
"allowed": [
"US"
]
},
"projection": "rectangular"
}
}
No such feature in the Youtube API. All the video properties are found in Youtube Resource Representation and there's no property that indicates if it's paid or not.
This is confirmed by a Google Engineer in this post.
I am currently using the Youtube data API trying to get localised subtitle data and while this works for most videos it isn't working for this one: https://www.youtube.com/watch?v=Q0FhXknxYj4. The video has Danish subtitles but when you use the API or API demo (setting part as localization) here: https://developers.google.com/youtube/v3/docs/videos/list there is no subtitle data.
Example response for working video:
{
"kind": "youtube#videoListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/zgsYC3imu6Fd_dFVfGFSGv4yads\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/3xUeT9GTC6osUJsmbTXqY1OMfsc\"",
"id": "S3YnYrcD1sQ",
"localizations": {
"da": {
"title": "København: Europas første markedsplads for byrelaterede data - Hitachi",
"description": "Hitachi skaber en datamarkedsplads for Danmarks hovedstad, der skal styrke innovationen.\n\nhttp://www.hitachi.eu/en/case_studies/city-data-exchange"
},
"en": {
"title": "Copenhagen: Europe's first city data exchange - Hitachi",
"description": "Hitachi is creating a data marketplace for Denmark's capital, to help power innovation.\n\nhttp://www.hitachi.eu/en/case_studies/city-data-exchange"
}
}
}
]
}
Example response for broken video (Q0FhXknxYj4):
{
"kind": "youtube#videoListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/UrnoPP0xkF1sGZFODge_h_h01KU\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/Y82zqHiktkqS1qFvTSCoJ5BEJas\"",
"id": "Q0FhXknxYj4"
}
]
}
Does anyone know why the API might not pull in the localisation data even though the subtitles are there?
Many thanks,
Emily
Your first example does not contain any subtitle data either. It only contains localizations of the video title and description.
You need to be using captions, not list, to list subtitle details.
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.
I'm having some problems with the v3 API when getting playlists by ID.
I have a javascript app that allows you to search for playlists (via a call to www.googleapis.com/youtube/v3/search) then save those playlists to one of several "devices", which is then persisted on the server. When you return, the page gets the devices and the list of Youtube playlist IDs associated. To display more details (name, image, etc), call(s) are made to www.googleapis.com/youtube/v3/playlists.
The problem is that /playlists doesn't seem to be returning valid playlists. The most bare-bones test-case is a call to:
https://www.googleapis.com/youtube/v3/playlists?key=KEY&part=id%2Csnippet&id=PL736C3116AD309B58
which returns
{
"kind": "youtube#playlistListResponse",
"etag": "\"5cYuq_ImPkYn_h2RKDdX8DHvM2g/T0etSAnItCRUAPOtHRCu92sMKQU\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": []
}
Note that it shows "totalResults: 1", but 0 actual results.
A call to the youtube website for the same playlist ID (http://www.youtube.com/playlist?list=PL736C3116AD309B58) shows a valid playlist.
This used to work.
I'm not authenticating with oauth, but I'm comparing the results against non-authenticated web requests or against the non-oauthed API searches.
I have no idea why this is the case, but when clicking on one of the videos in the playlist you linked to, it shows SP736C3116AD309B58 as the playlistId (notice the prepending SP instead of PL). However, I verified that the PL id was indeed to the one showing up in search...
But a call to this endpoint gives you the data you're looking for...
Call:
https://www.googleapis.com/youtube/v3/playlists?key={API_KEY}&part=id%2Csnippet&id=SP736C3116AD309B58
Response:
{
"kind": "youtube#playlistListResponse",
"etag": "\"5cYuq_ImPkYn_h2RKDdX8DHvM2g/iOZzhrEf1VYbGO25CZhT4ga_Gw4\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"id": "SP736C3116AD309B58",
"kind": "youtube#playlist",
"etag": "\"5cYuq_ImPkYn_h2RKDdX8DHvM2g/U04KGNFEmQkvMoEC7XrbSayIGUY\"",
"snippet": {
"publishedAt": "2009-04-21T15:23:31.000Z",
"channelId": "UCNYrK4tc5i1-eL8TXesH2pg",
"title": "Auto-Tune the News",
"description": "The only news you need has a bass line",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/hMtZfW2z9dw/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/hMtZfW2z9dw/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/hMtZfW2z9dw/hqdefault.jpg"
}
}
},
"status": {
"privacyStatus": "public"
}
}
]
}
Is there any reason you aren't just capturing this data in the actual Search call?