youtube-apiplaylistduration

Youtube API v3 Duration PlaylistItem


If I get all Playlist Items with the Youtube Data API v3, I am getting this format for all videos:

   "contentDetails": {
    "videoId": "KUL_AHeC4zw",
    "startAt": "PT0S",
    "endAt": "PT21M12.667S"
   }

Whats that thingie next to endAt? Why is there a point in the middle? I expect some kind of PT21M54S. I just want the duration as I would get it when I am fetching a single video. Is that a bug or am I just not able to understand that ISO Date Format?


Solution

  • This field "endAt" is not the same as the "duration" of the video, but where the playlist owner wants it to stop playing. The video duration is located in the video resource (contentDetails.duration) and not in the playlistItem. And it requieres another lookup request.

    You can find the definitions of the fields in the YouTube documentation. See for those resource definitions: https://developers.google.com/youtube/v3/docs/playlistItems#resource and https://developers.google.com/youtube/v3/docs/videos#resource