如何获取 YouTube 视频在特定时间范围内的观看次数?
我正在使用 YouTube v3 API 来获取用户在频道上上传的视频。
我需要视频中特定时间范围的视频统计信息(主要是观看次数)。例如:视频中的10秒到15秒。或者也许在第 10 秒。
如何才能实现这一目标?我已经浏览了 API 文档,但没有看到任何可以提供该数据的参数或部分。
用于获取已完成的直播/直播数据的代码片段:
request = youtube.liveBroadcasts().list(
part="snippet, status",
broadcastStatus="completed",
broadcastType="all"
)
response = request.execute()
然后,对于返回的列表数据中的每个视频,我运行以下 API 来获取视频相关数据:
request = youtube.videos().list(
part="snippet, contentDetails, statistics, liveStreamingDetails, status",
id=videoID
)
response = request.execute()
return response
示例响应
{
"kind": "youtube#videoListResponse",
"etag": "JI93kvK9Gsz3h2R_OvkmgPkUrqs",
"items": [
{
"kind": "youtube#video",
"etag": "NfG5gw0fBnjykGf8db9FiaBXw3M",
"id": "FNS_JCM-H3U",
"snippet": {
"publishedAt": "2022-02-27T19:20:15Z",
"channelId": "UCVxNxW5_GhdS_o8m4PyHsmg",
"title": "Time Check Test",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/default_live.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/mqdefault_live.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/hqdefault_live.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/sddefault_live.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/maxresdefault_live.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Streampala",
"categoryId": "20",
"liveBroadcastContent": "none",
"localized": {
"title": "Time Check Test",
"description": ""
},
"defaultAudioLanguage": "en-US"
},
"contentDetails": {
"duration": "PT1M20S",
"dimension": "2d",
"definition": "sd",
"caption": "false",
"licensedContent": False,
"contentRating": {},
"projection": "rectangular",
"hasCustomThumbnail": False
},
"status": {
"uploadStatus": "uploaded",
"privacyStatus": "public",
"license": "youtube",
"embeddable": False,
"publicStatsViewable": True,
"madeForKids": False,
"selfDeclaredMadeForKids": False
},
"statistics": {
"viewCount": "4",
"likeCount": "0",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "0"
},
"liveStreamingDetails": {
"actualStartTime": "2022-02-27T19:20:33Z",
"actualEndTime": "2022-02-27T19:21:53Z",
"scheduledStartTime": "2022-02-27T19:20:12Z"
}
}
],
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
}
}
I'm using the YouTube v3 API to fetch the user's videos uploaded on the channel.
I need the video statistics (mainly the view count) for specific time-frames in a video. For example: from 10 second to 15 second in the video. Or maybe at the 10th second.
How can this be achieved? I have gone through the API docs but don't see any parameter or section that can provide that data.
Code snippet to fetch the data of completed livestreams / liveBroadcasts:
request = youtube.liveBroadcasts().list(
part="snippet, status",
broadcastStatus="completed",
broadcastType="all"
)
response = request.execute()
Then for each video from the list data returned, I'm running the following API to fetch the video related data:
request = youtube.videos().list(
part="snippet, contentDetails, statistics, liveStreamingDetails, status",
id=videoID
)
response = request.execute()
return response
Sample Response
{
"kind": "youtube#videoListResponse",
"etag": "JI93kvK9Gsz3h2R_OvkmgPkUrqs",
"items": [
{
"kind": "youtube#video",
"etag": "NfG5gw0fBnjykGf8db9FiaBXw3M",
"id": "FNS_JCM-H3U",
"snippet": {
"publishedAt": "2022-02-27T19:20:15Z",
"channelId": "UCVxNxW5_GhdS_o8m4PyHsmg",
"title": "Time Check Test",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/default_live.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/mqdefault_live.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/hqdefault_live.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/sddefault_live.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/FNS_JCM-H3U/maxresdefault_live.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Streampala",
"categoryId": "20",
"liveBroadcastContent": "none",
"localized": {
"title": "Time Check Test",
"description": ""
},
"defaultAudioLanguage": "en-US"
},
"contentDetails": {
"duration": "PT1M20S",
"dimension": "2d",
"definition": "sd",
"caption": "false",
"licensedContent": False,
"contentRating": {},
"projection": "rectangular",
"hasCustomThumbnail": False
},
"status": {
"uploadStatus": "uploaded",
"privacyStatus": "public",
"license": "youtube",
"embeddable": False,
"publicStatsViewable": True,
"madeForKids": False,
"selfDeclaredMadeForKids": False
},
"statistics": {
"viewCount": "4",
"likeCount": "0",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "0"
},
"liveStreamingDetails": {
"actualStartTime": "2022-02-27T19:20:33Z",
"actualEndTime": "2022-02-27T19:21:53Z",
"scheduledStartTime": "2022-02-27T19:20:12Z"
}
}
],
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论