我的问题是我想获得YouTube视频的直接链接以及不同质量的不同链接。例如,如果我有此网址www.youtube.com/watch?v=VCQ24gXfRrc,则此视频的不同质量的直接链接如下
有谁能告诉我如何从Youtube直接获取YouTube视频的链接?我一直在搜索,但无法找到任何解决方案。 PHP和JavaScript中的任何解决方案都会有所帮助。
答案 0 :(得分:-1)
您可以使用此代码:
videoUrls = ytplayer.config.args.adaptive_fmts
.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_label || curr.type]: curr
}), {} );
输出是json的不同质量:
{720p: {…}, 480p: {…}, 360p: {…}, 240p: {…}, 144p: {…}, …}
144p
:
{bitrate: "105451", lmt: "1501151759670299", quality_label: "144p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
240p
:
{bitrate: "236138", lmt: "1501151763073149", quality_label: "240p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
360p
:
{bitrate: "431019", lmt: "1501151763523043", quality_label: "360p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
480p
:
{bitrate: "751515", lmt: "1501151761884798", quality_label: "480p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
720p
:
{bitrate: "1530639", lmt: "1501151774338090", quality_label: "720p", type: "video/webm;+codecs="vp9"", projection_type: "1", …}
audio/mp4;+codecs="mp4a.40.2"
:
{url: "https://redirector.googlevideo.com/videoplayback?k…70E2C77F1747DA9B3&source=youtube&mime=audio%2Fmp4", type: "audio/mp4;+codecs="mp4a.40.2"", init: "0-591", projection_type: "1", bitrate: "96956", …}
audio/webm;+codecs="opus"
:
{url: "https://redirector.googlevideo.com/videoplayback?k…AEF92557AE5C5581&source=youtube&mime=audio%2Fwebm", type: "audio/webm;+codecs="opus"", init: "0-271", projection_type: "1", bitrate: "116254", …}
audio/webm;+codecs="vorbis"
:
{url: "https://redirector.googlevideo.com/videoplayback?k…FA29AC0F6C925E21&source=youtube&mime=audio%2Fwebm", type: "audio/webm;+codecs="vorbis"", init: "0-4082", projection_type: "1", bitrate: "77114", …}
__proto__
:
Object