html - YouTube 的 get_video_info 端点不再工作

标签 html api youtube

我正在使用 YouTube 的 get_video_info获取视频分辨率的非官方端点。最近的某个时候,这已经停止工作并给了我:

We're sorry...... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.
是否有另一个公共(public)端点可以获取视频的大小/纵横比?我需要无需使用某些登录名或开发人员 key 即可访问端点。

最佳答案

我花了几个小时调试 youtube-dl ,我发现对于所有视频,您都可以简单地获取网页的内容,即

(async () => {
  // From the back-end
  const urlVideo = "https://www.youtube.com/watch?v=aiSla-5xq3w";
  const html = await (await fetch(urlVideo)).text();
  console.log(html);
})();

然后将内容与以下 RegExp 进行匹配:/ytInitialPlayerResponse\s*=\s*({.+?})\s*;\s*(?:var\s+meta|<\/script|\n)/示例 HTML:

(async () => {
  const html = await (await fetch("https://gist.githubusercontent.com/avi12/0255ab161b560c3cb7e341bfb5933c2f/raw/3203f6e4c56fff693e929880f6b63f74929cfb04/YouTube-example.html")).text();
  const matches = html.match(/ytInitialPlayerResponse\s*=\s*({.+?})\s*;\s*(?:var\s+meta|<\/script|\n)/);
  const json = JSON.parse(matches[1]);

  const [format] = json.streamingData.adaptiveFormats;
  console.log(`${format.width}x${format.height}`);
})();

关于html - YouTube 的 get_video_info 端点不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68537608/

相关文章:

android - 用新的视频ID刷新后,YouTube Player会播放以前的视频ID

windows - 如何创建一个.bat文件,允许我输入输入(或者更好的是,从剪贴板获取输入)?

javascript - 如何将所有按顺序排列的元素分组为由分隔符类分隔的同一类?

html - 为什么 top-margin 会压低一个以上的 div?

php - 尝试在 codeigniter 中获取 Assets CSS 时出现 404 错误?

android - 如何在本地高效保存 Drawables?

javascript - 使用 JavaScript 时如何保护 API Key?

HTML 网页全屏第 2 部分

php - Soundcloud (Oauth2) API 获取访问 token 失败

python - 有没有办法获得 YouTube 的两个特定用户从职业生涯开始到最近可能的订阅者数量?