且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用API​​从视频ID获取***文件的网址

更新时间:2023-02-20 23:42:44

您的标题是使用API​​表示的.这样就无法从视频ID访问***文件URL.相对而言,使用文件网址,您还可以在违反 ***条款的情况下下载文件,分发内容等.因此,尚无此类API.

Your title said using API. It's not possible to get access to *** file URL from video ID by that. By mean, with file URL you can also download it, distribute content etc while it's against *** Terms. So there is no such API for that.

由于使用Javascript进行了标记,因此可以直接访问文件URL.这可能不是您想要的那样,但是可以在任何浏览器中使用的开发人员工具控制台中完美地工作.有关详细信息,请您在这里

Since you're tagged with Javascript, there is possibility to get direct access to the file URL. This probably is not as you wanted exactly but it worked flawlessly from the developer tools console available in any browser. For details Here you go

const videoUrls = ytplayer.config.args.url_encoded_fmt_stream_map
  .split(',')
  .map(item => item
    .split('&')
    .reduce((prev, curr) => (curr = curr.split('='),
      Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
    ), {})
  )
  .reduce((prev, curr) => Object.assign(prev, {
    [curr.quality + ':' + curr.type.split(';')[0]]: curr
  }), {});
console.log(videoUrls);