如何获取YouTube的视频的真正播放地址
通常YouTube的URL如下格式
有了这个地址,然后打开浏览器就可以播放。
但是如果我们使用任意支持https的播放器播放该视频,使用上面的URL是不行的,因为上面的地址只有YouTube的服务器才可以解析。此时我们需要知道真正的视频流的地址:
这个可以通过youtube-dl和工具获取。先下载这个工具:
https://rg3.github.io/youtube-dl/
然后通过下面的命令就可以获取真正的视频流的URL
$ youtube-dl -g https://www.youtube.com/watch?v=q_gr3dtBaic
https://r3—sn-htgx20capj-npol.googlevideo.com/videoplayback?id=abf82bdddb416a2
7&itag=243&source=youtube&requiressl=yes&mn=sn-htgx20capj-npol&mm=31&mv=m&ms=au&
pcm2cms=yes&pl=24&ratebypass=yes&mime=video/webm&gir=yes&clen=22425107&lmt=13991
70861049663&dur=839.080&mt=1440648827&fexp=9407465,9407535,9408505,9408710,94090
69,9412774,9413010,9415365,9415485,9416023,9416048,9416126,9416343,9416838,94171
57,9417269,9417707,9417721,9418153,9418448,9418643,9419446,9420022&signature=69D
CFF3B8455F628A8461B6C2270A869AB31D3B8.64B1CFD33839935A4FF7775A8778495A9074778C&s
ver=3&key=dg_yt0&upn=UXivxitREXM&ip=101.100.176.125&ipbits=0&expire=1440670533&s
params=ip,ipbits,expire,id,itag,source,requiressl,mn,mm,mv,ms,pcm2cms,pl,ratebyp
ass,mime,gir,clen,lmt,dur
https://r3—sn-htgx20capj-npol.googlevideo.com/videoplayback?id=abf82bdddb416a2
7&itag=141&source=youtube&requiressl=yes&mn=sn-htgx20capj-npol&mm=31&mv=m&ms=au&
pcm2cms=yes&pl=24&ratebypass=yes&mime=audio/mp4&gir=yes&clen=26757245&lmt=142996
4708415447&dur=839.238&mt=1440648827&fexp=9407465,9407535,9408505,9408710,940906
9,9412774,9413010,9415365,9415485,9416023,9416048,9416126,9416343,9416838,941715
7,9417269,9417707,9417721,9418153,9418448,9418643,9419446,9420022&signature=2CB0
9B1ACB4FBD1A927B6AB00E83E79C5E849109.6DF6159460E2ABDA6543A812E579CC8345FC95ED&sv
er=3&key=dg_yt0&upn=UXivxitREXM&ip=101.100.176.125&ipbits=0&expire=1440670533&sp
arams=ip,ipbits,expire,id,itag,source,requiressl,mn,mm,mv,ms,pcm2cms,pl,ratebypa
ss,mime,gir,clen,lmt,dur
这样我们得到2个URL,然后使用ffplay或者vlc或者mplayer等播放器播放视频
$ ffplay "https://r3—sn-htgx20capj-npol.googlevideo.com/videoplayback?id=abf82bdddb416a27&itag=243&source=youtube&requiressl=yes&ms=au&mv=m&pl=24&mn=sn-htgx20capj-npol&mm=31&pcm2cms=yes&ratebypass=yes&mime=video/webm&gir=yes&clen=22425107&lmt=1399170861049663&dur=839.080&fexp=9406012,9407991,9408710,9409069,9409206,9412927,9413318,9415365,9415485,9416023,9416126,9416324,9416554,9416729,9417118,9417203,9417689,9417707,9418082,9418153,9418448,9419444,9419752,9420019&mt=1440647875&key=dg_yt0&upn=k-HYVZbNrVs&sver=3&signature=0EF10DE6F3C28A22DE1DFE73A9CCA0C6EE57142D.9179FF178FDF4A1360B528B90B5971E8FAB437A7&ip=101.100.176.125&ipbits=0&expire=1440669505&sparams=ip,ipbits,expire,id,itag,source,requiressl,ms,mv,pl,mn,mm,pcm2cms,ratebypass,mime,gir,clen,lmt,dur"
记得一定要加双引号,否则会出错。
或者是使用HTML5的video tag播放后可以
<source src="https://r3—sn-htgx20capj-npol.googlevideo.com/videoplayback?id=abf82bdddb416a27&itag=243&source=youtube&requiressl=yes&ms=au&mv=m&pl=24&mn=sn-htgx20capj-npol&mm=31&pcm2cms=yes&ratebypass=yes&mime=video/webm&gir=yes&clen=22425107&lmt=1399170861049663&dur=839.080&fexp=9406012,9407991,9408710,9409069,9409206,9412927,9413318,9415365,9415485,9416023,9416126,9416324,9416554,9416729,9417118,9417203,9417689,9417707,9418082,9418153,9418448,9419444,9419752,9420019&mt=1440647875&key=dg_yt0&upn=k-HYVZbNrVs&sver=3&signature=0EF10DE6F3C28A22DE1DFE73A9CCA0C6EE57142D.9179FF178FDF4A1360B528B90B5971E8FAB437A7&ip=101.100.176.125&ipbits=0&expire=1440669505&sparams=ip,ipbits,expire,id,itag,source,requiressl,ms,mv,pl,mn,mm,pcm2cms,ratebypass,mime,gir,clen,lmt,dur" type="video/mp4">
</video>
版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章转载自:IT夜班车,否则按侵权处理.