获取视频时长

时间:2015-06-09 18:06:49

标签: python-3.x youtube-api

搜索以获取视频。如何获取视频的持续时间?

            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"])

最后一行返回一个键错误。从网站上的API来看,这是应该怎么做的,但说实话文档非常奇怪。

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

干杯

1 个答案:

答案 0 :(得分:1)

search.list endpoint不接受/提供contentDetails。您需要从搜索中获取ID结果,并再次调用videos.list endpoint