I've been using the following method to retrieve all video IDs, titles, and default thumbnail images contained within a specific YouTube playlist for use in a dynamic playlist carousel (The IDs are then passed to an array which is used to dynamically create a thumbnail carousel. Note the 'playlist' variable is defined via an externalized XML value):
// Get YouTube Playlist values
var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/' + playlist + '?v=2&alt=json&callback=?';
var videoURL = 'http://www.youtube.com/watch?v=';
$.getJSON(playListURL, function(data) {
var list_data = "";
$.each(data.feed.entry, function(i, item) {
var feedTitle = item.title.$t;
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
var thumb = ""+ videoID +"/sddefault.jpg";
if (videoID !='videos') {
yt_videos.push(videoID);
}
yt_thumb.push(thumb);
yt_title.push(feedTitle);
});
$(list_data).appendTo(".cont");
populateCarousel();
});
YouTube has depricated the v1-2 APIs and the method is longer working. Does the YouTube API v3 provide an equivalent method? Specifically replacing the call:
var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/' + playlist + '?v=2&alt=json&callback=?';
You will need to switch to the new PlaylistItems/list endpoint to get video information from a playlist.
Request:
HTTP GET: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+id&playlistId=PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk&key={YOUR_API_KEY}
Response (for id= PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk):
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/pBQT3k1NWD9D6HOvzNhT4QS1-W0\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 10,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/wu_RMwA6QYinWSMrYXyOugKDbyI\"",
"id": "PLl3eZeHB033DOxfNMOVENodvC_4QtQ-r2bxEjeNprDxQ",
"snippet": {
"publishedAt": "2014-12-10T21:16:39.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "4bVgilYncao"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/DPNyicQckvtlwgMTintYEwYsE6g\"",
"id": "PLl3eZeHB033DOxfNMOVENoaZ-Ybk0W0zkTL1Sliq5xeA",
"snippet": {
"publishedAt": "2014-12-10T21:16:58.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "David Letterman Announces His Retirement from the Late Show",
"description": "David Letterman announces that he will retire from the Late Show in 2015.\n\nLive on Letterman is up for a Webby award! Let your voice be heard and vote now! http://bit.ly/1l4oktE #WebbyAwards",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/H9eYkpgeeI8/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "H9eYkpgeeI8"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/aL6XWPV0PoM50wQcyclAxsvtWy4\"",
"id": "PLl3eZeHB033DOxfNMOVENobu4IxNcwxZw1eEEoLqHjhY",
"snippet": {
"publishedAt": "2014-12-10T21:17:14.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 2,
"resourceId": {
"kind": "youtube#video",
"videoId": "ONgN2Hgz3XE"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/YF1JYH8bTG20vjuPLeMR-2xkxjo\"",
"id": "PLl3eZeHB033DOxfNMOVENoQncF7sXo86YALoy5U4yqlU",
"snippet": {
"publishedAt": "2014-12-10T21:17:30.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "David Letterman - Future Islands: \"Seasons (Waiting On You)\"",
"description": "Making their network TV debut, Future Islands performed \"Seasons (Waiting On You)\" from their album, \"Singles.\"",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/1Ee4bfu_t3c/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 3,
"resourceId": {
"kind": "youtube#video",
"videoId": "1Ee4bfu_t3c"
}
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/_Ft_7ujRwQbP7-altelmVnzwQx0\"",
"id": "PLl3eZeHB033DOxfNMOVENoYQ9Z55P4r2KhvkV5yx-okc",
"snippet": {
"publishedAt": "2014-12-10T21:17:47.000Z",
"channelId": "UCVUx0VcNxnHx7ZjuZK5Sthw",
"title": "Private video",
"description": "This video is private.",
"channelTitle": "Late Show with David Letterman",
"playlistId": "PLCJLiJ8uSJrCpxwz4lmnz1NvvF2SzXbhk",
"position": 4,
"resourceId": {
"kind": "youtube#video",
"videoId": "Bzr5VtFvSyw"
}
}
}
]
}
The id value for each object in the items array should be the videoId value that you want.
api_key = 'YOUR_API_KEY'
api_service_name = 'youtube'
api_version = 'v3'
playlist_id = 'SOME_PLAYLIST_ID'
# build a connected client
youtube = googleapiclient.discovery.build(api_service_name, api_version, developerKey=api_key)
# make a request (note, only the 'snippet' part has been requested)
request = youtube.playlistItems().list(part=['snippet'], playlistId=playlist_id)
response = request.execute()
# scrape out the actual video ids (probably could be safer)
for (k, v) in response.items():
if(k == 'items'):
video_ids = [pli['snippet']['resourceId']['videoId'] for pli in v if pli['snippet']['resourceId']['kind']=='youtube#video']
print(video_ids)
Related
I'm trying to find video "Desposito" on yuotube with API. It was published on January 13, 2017. The query string is as follows:
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&order=viewCount&publishedAfter=2017-01-13T00%3A00%3A00.000Z&publishedBefore=2017-01-13T23%3A59%3A00.000Z&key=[YOUR_API_KEY]
But the response doesn't include the video I need. What am I doing wrong?
The video you want isn't on the first page of results. Limit it with a search param.
This works fine:
https://www.googleapis.com/youtube/v3/search?q=desposito&part=snippet&maxResults=1&order=viewCount&publishedAfter=2017-01-13T00%3A00%3A00.000Z&publishedBefore=2017-01-13T23%3A59%3A00.000Z&key=[API_KEY]
Response:
{
"kind": "youtube#searchListResponse",
"etag": "\"tnVOtk4NeGU6nDncDTE5m9SmuHc/RpayhI7uhEMSDFk9CHdtyV62vi0\"",
"nextPageToken": "CAEQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 356,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"tnVOtk4NeGU6nDncDTE5m9SmuHc/3g-rbj2UgHGdPTC1Nk7zLAWtTHU\"",
"id": {
"kind": "youtube#video",
"videoId": "kJQP7kiw5Fk"
},
"snippet": {
"publishedAt": "2017-01-13T05:00:02.000Z",
"channelId": "UCLp8RBhQHu9wSsq62j_Md6A",
"title": "Luis Fonsi - Despacito ft. Daddy Yankee",
"description": "Despacito” disponible ya en todas las plataformas digitales: https://UMLE.lnk.to/DOoUzFp “Imposible” disponible ya en todas las plataformas digitales: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/kJQP7kiw5Fk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/kJQP7kiw5Fk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/kJQP7kiw5Fk/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "LuisFonsiVEVO",
"liveBroadcastContent": "none"
}
}
]
}
We are using youtube v3 search API. We are getting mismatch in the "totalResults" count and the list of items returned in the response.items field. I am requesting 50 videos in the request. Response returned shows totalResults count as 65 but the response payload has only 3 videos.
API : www.googleapis.com/youtube/v3/search/list
Request Payload
{key=API_KEY, maxResults=50, order=date, part=snippet, publishedAfter=2017-03-20T23:59:59.999-04:00, publishedBefore=2017-04-19T23:59:59.001-04:00, q=( ( "Wood Mackenzie" OR "Wood Mac" OR Woodmac OR #woodmackenzie ) AND NOT (fleetwood OR "fleet wood" OR 9WoodMac ) ) , type=video}
Response Payload
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/HTW4WQODZeERIv51VrRfOhir8dg\"",
"nextPageToken": "CDIQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 65,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/lnNNrToZHGTehIEJ6bvEx5RZMo4\"",
"id": {
"kind": "youtube#video",
"videoId": "obzlB21t904"
},
"snippet": {
"publishedAt": "2017-04-14T11:38:08.000Z",
"channelId": "UC60Sa1LQjgy_a-K8ThN4eQw",
"title": "Fleet wood mac Live at Leeds",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/obzlB21t904/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/obzlB21t904/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/obzlB21t904/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "KEVIN MARSHALL",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/uYuuTAL3vtnFI1WOYjth0cso2Xo\"",
"id": {
"kind": "youtube#video",
"videoId": "gHAn0SbwKMg"
},
"snippet": {
"publishedAt": "2017-04-06T22:17:31.000Z",
"channelId": "UC3_MxBSSbmGznoSTgoBQ7_w",
"title": "Beat Club: British Invasion 60's, Pt-2; Animals-Move-Fleet Wood Mac-J.Mayall-Who-Pacemakers-Kinks",
"description": "Eric Burdon & Animals: C.C. Rider 0:01 The Move: Wild Tiger Woman 3:55 Fleet Wood Mac: Dragonfly 6:26 John Mayall: My Pretty Girl 9:47 Thunderclap ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/gHAn0SbwKMg/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/gHAn0SbwKMg/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/gHAn0SbwKMg/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "ROCK&POPS1_koba",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/tapelxOG4Q3gZRJCR2qaVdt-ZO8\"",
"id": {
"kind": "youtube#video",
"videoId": "5GvLbFBdcF4"
},
"snippet": {
"publishedAt": "2017-04-02T04:48:47.000Z",
"channelId": "UC6fn383TI1HVDYW4dSEIogQ",
"title": "\"Dreams\" by fleet wood mac (vocal cover)",
"description": "I do not own this song. I do not make a profit off of this song. It belongs to the person(s) who wrote it. Please subscribe and comment below any suggestions?!",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/5GvLbFBdcF4/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/5GvLbFBdcF4/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/5GvLbFBdcF4/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Musikallitee",
"liveBroadcastContent": "none"
}
}
]
}
As described in the documentation itself, the totalResults is:
integer
The total number of results in the result set.Please note that the value is an approximation and may not represent an exact value. In addition, the maximum value is 1,000,000.
You should not use this value to create pagination links. Instead, use the nextPageToken and prevPageToken property values to determine whether to show pagination links.
The value is only an approximation/estimate, but not the exact value for the total number of items returned. I've tested the API with the same details as yours and the value tends to change from 63, to 64, and 65.
With all that said, there is nothing wrong in your code. It's just the expected behavior. Unfortunately, it is not stated anywhere as to where the value of totalResults is based on or where it is best used. It's best to proceed with an implementation that doesn't rely on this parameter.
I had created an live event on youtube and i had associated a custom ingestion (live stream) to that live event.
I am able to get the list of live events by calling
https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=all
Response
{
"kind": "youtube#liveBroadcastListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/6LS8J5LIkMcXRAIUEViaRonO_jk\"",
"items": [
{
"kind": "youtube#liveBroadcast",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/eSW3gnAC5A4iNg4xj-r8vvP4ha8\"",
"id": "M96Pswa174I",
"snippet": {
"publishedAt": "2015-08-27T09:26:52.000Z",
"channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
"title": "My new event",
"description": "This is test event",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/default_live.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/mqdefault_live.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/M96Pswa174I/hqdefault_live.jpg",
"width": 480,
"height": 360
}
},
"scheduledStartTime": "2015-08-27T09:30:00.000Z",
"isDefaultBroadcast": false
}
}
]
}
then i am able to get the live stream by calling
https://www.googleapis.com/youtube/v3/liveStreams?part=cdn%2Csnippet&mine=true
Response
- SHOW HEADERS -
{
"kind": "youtube#liveStreamListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/ctbzD5B9MI-wBMxDXCWCto2oFO8\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#liveStream",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/LEFmnjMqvHydtqmxovlaXCai3vM\"",
"id": "x_ZkmygOl4Bc0PHV8zXeag1440668944469033",
"snippet": {
"publishedAt": "2015-08-27T09:49:04.000Z",
"channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
"title": "My new stream",
"description": "this is demo stream",
"isDefaultStream": false
},
"cdn": {
"format": "720p_hfr",
"ingestionType": "rtmp",
"ingestionInfo": {
"streamName": "rathodm63.6584-jszu-8p4h-43yg",
"ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
"backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1"
}
}
}
]
}
but how to identify that this steam belongs to above specified live event ?
You must use LiveBroadcasts.bind to bind a YouTube broadcast to a stream. Note that a broadcast can only be bound to one video stream, although a video stream may be bound to more than one broadcast. Then, you can use the LiveBroadcasts.list request and check the contentDetails.boundStreamId, which will be the stream associated with that livebroadcast. You'll have to specify part=contentDetails if you want to do this through an HTTP request.
I tried to use this:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails&{playlist_id}&key={key}&maxResults=50
and
https://www.googleapis.com/youtube/v3/search?part=snippet&q=YouTube+Data+API&type=video&videoCaption=closedCaption&key={key}&maxResults=50
It says in the documentation it is contentDetails.duration but this doesn't seem to be present in the data I receive.
In order to get the detailed information about a video in a playlist, you will need to hit the Videos.list method for every video in that playlist with the snippet and contentDetails values for part:
Request:
HTTP GET https://www.googleapis.com/youtube/v3/videos?part=snippet%2C+contentDetails&id=AKiiekaEHhI&key={YOUR_API_KEY}
Response (for id=AKiiekaEHhI):
{
"kind": "youtube#videoListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/Qz22l3E04nR4kuY2SGE5M_d1BMM\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/8X_byN22HJTh5FJyoMH9bFGR_Og\"",
"id": "AKiiekaEHhI",
"snippet": {
"publishedAt": "2015-05-04T10:01:43.000Z",
"channelId": "UCkvdZX3SVgfDW8ghtP1L2Ug",
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/AKiiekaEHhI/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Swordless Link",
"categoryId": "20",
"liveBroadcastContent": "none",
"localized": {
"title": "The Legend of Zelda: Majora's Mask With Glitches - Part 17: Going Against the Flow",
"description": "Follow me on Twitter! http://twitter.com/swordlesslink\n\nFollow me on TwitchTV for live video game streaming! http://twitch.tv/swordlesslink"
}
},
"contentDetails": {
"duration": "PT17M30S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true
}
}
]
}
The duration of the content can be found as the object for the duration key in the contentDetails dictionary.
The categoryId maps to your video category, which you will have to look up using the VideoCategories.list method.
Request:
HTTP GET https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id={CATEGORY_ID}&key={YOUR_API_KEY}
Response (for id=20:
{
"kind": "youtube#videoCategoryListResponse",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/cVclmqPmb6Xbwij8SctXRUrSVhw\"",
"items": [
{
"kind": "youtube#videoCategory",
"etag": "\"dhbhlDw5j8dK10GxeV_UG6RSReM/WmA0qYEfjWsAoyJFSw2zinhn2wM\"",
"id": "20",
"snippet": {
"channelId": "UCBR8-60-B28hp2BmDPdntcQ",
"title": "Gaming",
"assignable": true
}
}
]
}
The object for the title key in the snippet dictionary returns the String value of the video category that you want.
If you check search resource, you'll see its not in that response.
This was actually a feature request in: https://code.google.com/p/gdata-issues/issues/detail?id=4294
You can follow up that issue.
I'm using this url:
https://www.googleapis.com/youtube/v3/playlistItems?
playlistId=FLFe0SGNFqZ9E2owO5ZDZpeg&
part=snippet,contentDetails,status
to fetch YouTube playlistItems.
I included all the part I'm interested in, however I found no way to return the duration of the item.
https://developers.google.com/youtube/v3/docs/playlistItems/list
Is this possible?
currently I'm getting back only an item like this:
{
"status": {
"privacyStatus": "public"
},
"kind": "youtube#playlistItem",
"contentDetails": {
"videoId": "tL-Ba86UhoE"
},
"snippet": {
"playlistId": "FLFe0SGeFqZ9E2owO5ZDZpwg",
"thumbnails": {
"default": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/default.jpg",
"width": 120,
"height": 90
},
"high": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/hqdefault.jpg",
"width": 480,
"height": 360
},
"medium": {
"url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/mqdefault.jpg",
"width": 320,
"height": 180
}
},
"title": "Music Video",
"resourceId": {
"kind": "youtube#video",
"videoId": "tL-BA86Uhoh"
},
"channelId": "UCFe0SGNFqZ9E2owO5ZDZpwg",
"publishedAt": "2013-07-06T18:41:43.000Z",
"channelTitle": "channeltitle",
"position": 0,
"description": "Video for"
},
"etag": "\"ePFRUfYBkeQ2ncpP9OLHvB0fDw4/CJiCG6tvFw4quQlzJq3gTrhvCNo\"",
"id": "FL-fX6VqgtTfCJWKNE4aVRODKSrRgEdGvw"
},
With no time indication at all.
I'd rather avoid flooding YouTube with request to return a single video's duration.
Use link like this for get duration for many videos:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=idFirst,idSecond&key=YOUR_API_KEY
Use this Function : [ only used with Youtube Api v3 ]
Browser :
you have to make another http request
using :
https://www.googleapis.com/youtube/v3/videos?id={video id}&part=contentDetails&key={api Key}
and on
contentDetails
you will find the duration
Php :
function getDuration($apiKey,$video_id){
$link='https://www.googleapis.com/youtube/v3/videos?id='.$video_id.'&part=contentDetails&key='.$apiKey;
$data = json_decode(file_get_contents($link),true);
$duration = $data['items'][0]['contentDetails']['duration'];
return $duration;
}