我目前正在根据给定的网络条件对 YouTube 视频的质量进行测量。我编写了一个自定义 Chrome 扩展来播放视频并获取缓冲信息,这要归功于 youtube player api .
我现在需要的是右键单击视频 ( example ) 时出现的“ Nerd 统计信息”面板的内容。 由于 UI 自动化,我可以显示它。但是,当我尝试使用 JavaScript 访问此面板的内容时,由于跨源资源共享 (CORS),我收到错误。
我只想读取面板的Current/OptimalRes
。 你有办法获得它吗?
我长期以来一直在寻找这个问题的答案。已经提到了here ,但这篇文章的答案不是我想要的,因为它只提供有关视频的一般信息,而不是实际播放的分辨率。
最佳答案
抱歉,此代码位于“AutoIT”中,但应该很容易通过管道传输到 Javascript 或任何其他类似语言。这是“ Nerd 统计”数据的完整列表:
#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)
关于javascript - 在youtube iFrame中访问 'Stats for nerds'数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48985063/