获取视频时长
Obtaining video duration
搜索获取视频。如何获取视频时长?
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"])
最后一行returns一个按键错误。从网站上的 API 来看,这是应该如何完成的,但老实说,文档非常奇怪。
https://developers.google.com/youtube/v3/docs/videos
干杯
那个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 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"])
最后一行returns一个按键错误。从网站上的 API 来看,这是应该如何完成的,但老实说,文档非常奇怪。
https://developers.google.com/youtube/v3/docs/videos
干杯
那个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。