使用API​​从视频ID获取youtube文件的网址 [英] Get youtube file URL from video ID using API

查看:330
本文介绍了使用API​​从视频ID获取youtube文件的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 SoundManager2 音频播放器来再现网站上嵌入的所有youtube文件.如何通过视频ID访问Youtube文件的网址?

I want to reproduce all youtube files embedded on a site using SoundManager2 audio player. How can I get access to Youtube file URL from video ID?

注意:Soundcloud提供了从歌曲URL获取直接流URL的可能性.这是一个使用Soundmanager2和Angular的工作示例.现在我想对Youtube做同样的事情.

Note: Soundcloud offers the possibility to get the direct streaming URL from the song URL. Here is a working example with Soundmanager2 and Angular. Now I want to do the same for Youtube.

推荐答案

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

Your title said using API. It's not possible to get access to YouTube file URL from video ID by that. By mean, with file URL you can also download it, distribute content etc while it's against YouTube 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);

这篇关于使用API​​从视频ID获取youtube文件的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆