Obtaining video duration

183 views Asked by At

A search is made to obtain videos. How do I obtain the duration of the video?

            for search_result in search_response.get("items", []):
            if search_result["id"]["kind"] == "youtube#video":
                VideoID.append(search_result["id"]["videoId"])
                ChannelID.append(search_result["snippet"]["channelId"])
                VideoName.append(search_result["snippet"]["title"])
                ChannelName.append(search_result["snippet"]["channelTitle"])
                videoDuration.append(search_result["contentDetails"]["duration"])

The last line returns a key error. Judging by the API on the website this is how it should be done but the documentation is pretty weird to be honest.

https://developers.google.com/youtube/v3/docs/videos

Cheers

1

There are 1 answers

0
johnh10 On BEST ANSWER

The search.list endpoint does not accept/provide contentDetails. You will need to take the id results from search and make another call to the videos.list endpoint for that.