【问题标题】:Access 'Stats for nerds' data in youtube iFrame在 youtube iFrame 中访问“书呆子的统计信息”数据
【发布时间】:2018-08-05 16:57:09
【问题描述】:

我目前正在根据给定的网络条件测量 youtube 视频的质量。感谢youtube player api,我编写了一个自定义 Chrome 扩展来播放视频并获取缓冲信息。

我现在需要的是右键单击视频 (example) 时出现的“书呆子统计”面板的内容。 由于 UI 自动化,我可以显示它。但是,当我尝试使用 javascript 访问此面板的内容时,由于跨域资源共享 (CORS) 而出现错误。

我只想阅读面板的Current/OptimalRes您知道获得它的方法吗?

我一直在寻找这个问题的答案。有人提到过here,但这篇文章的答案并不是我想要的,因为它只提供了有关视频的一般信息,而不是实际播放的分辨率。

【问题讨论】:

标签: javascript google-chrome youtube youtube-api


【解决方案1】:

很抱歉此代码在“AutoIT”中,但它应该很容易通过管道传输到 Javascript 或任何其他类似语言。这是“书呆子统计”数据的完整列表:

#include <IE.au3>

;Attach to open YouTube player within browser
$oIE = _IEAttach ("https://www.youtube.com", "url",1)

;Get a reference to the movie player
$oPlayerRef = $oIE.document.getElementById("movie_player")

;Video ID / sCPN
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).video_id_and_cpn)
;Viewport / Frames
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).dims_and_frames)
;Current / Optimal Res
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).resolution)
;Volume / Normalized
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).volume)
;Codecs
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).codecs)
;Connection Speed
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).bandwidth_kbps)
;Network Activity
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).network_activity_bytes)
;Buffer Health
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).buffer_health_seconds)
;Mystery Text
msgbox(0,"",$oPlayerRef.getStatsForNerds(0).debug_info)

【讨论】:

  • 我不知道参数的其余部分,但您可以使用 buffer_health_seconds 计算: player.getVideoLoadedFraction()*player.getDuration()-player.getCurrentTime()
猜你喜欢
  • 2018-03-30
  • 1970-01-01
  • 2018-12-31
  • 1970-01-01
  • 2019-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多