Search code examples
youtubegdataduration

YouTube GData API - Query for videos with a specific duration


Is there a YouTube GData API parameter for a query that will only return entries with a minimum and/or a maximum given duration? I've found the "duration" parameter but it only accepts the values "short", "medium", and "long".


Solution

  • Ok, found it!

    You need to integrate such query conditions into the fields parameter, which operates on a syntax similar to xpath:

    http://gdata.youtube.com/feeds/api/videos?fields=entry[*videoVariable* operator *value*]
    

    So for what I was looking for, the fields parameter value would have been:

    entry[media:group/yt:duration/@seconds > *min_value* and media:group/yt:duration/@seconds < *max_value*]
    

    https://developers.google.com/youtube/2.0/developers_guide_protocol_partial