Search code examples
youtube-data-api

YouTube API returns wrong video duration


I'm using the YouTube API to get the duration of videos. However, the API response does not correspond to video length.

Example: https://www.youtube.com/watch?v=g5xNzUA5Qf8

Length on YouTube 3:33 Screen shot of video on YouTube

Duration in YouTube API: 1 day, 2 hours 34 minutes and 17 seconds

    {
      "kind": "youtube#video",
      "etag": "tWwii1RezGsoNlQtpFjI00I5gog",
      "id": "g5xNzUA5Qf8",
      "contentDetails": {
        "duration": "P1DT2H34M17S",
        "dimension": "2d",
        "definition": "sd",
        "caption": "false",
        "licensedContent": false,
        "contentRating": {},
        "projection": "rectangular"
      }
    }

Other example:

https://www.youtube.com/watch?v=KZeXI0iHsAA

3 minutes vs 1 hour

Is this a YouTube API bug, or is there something I don't understand? I didn't find anyone reporting a similar problem.


Solution

  • It seems that one more time YouTube Data API v3 doesn't work as documented.

    I would recommend you to use my open-source YouTube operationnal API at https://yt.lemnoslife.com/videos?part=contentDetails&id=g5xNzUA5Qf8

    It will return you the correct duration in seconds and not in the ISO 8601 format (if you really need this format please leave a comment).