爱奇艺Widevine的下载步骤

Posted by

之前只是简单地获取了key,没有进行下载,今天因为一些奇怪的需求(?)试着下载了一下,还是比较麻烦的,在这里记录一下大致的处理步骤。(日后可能会写自动化脚本,也可能不写,看用处多不多了。)

首先说明,本文不提供任何获取key的教学,请勿询问key的获取方式。

首先定位到获取播放链接的请求。播放爱奇艺Widevine加密的视频页,F12调用开发者面板,Network下筛选关键字dash,定位到请求。
1
复制请求的response,将内容格式化为json。
2
3

容易观察到,所有关于播放的信息都放在”m3u8″下,最开始的位置是视频的音频信息,可以查看到音频的init信息和音频文件的地址。
4
所以你可以使用如下的代码来生成init_audio.mp4文件(音频)。

import base64
data = b"AAAAJGZ0eXBpc29tAAAAAGlzbzhtcDQxZGFzaGF2YzFjbWZjAAAGmm1vb3YAAABsbXZoZAAAAADZkAKj2ZACowAAYagAAAAAAAEAAAEAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAACNbWV0YQAAAAAAAAAgaGRscgAAAAAAAAAASUQzMgAAAAAAAAAAAAAAAAAAAGFJRDMyAAAAABXHSUQzBAAAAAAASVBSSVYAAAA/AABodHRwczovL2dpdGh1Yi5jb20vZ29vZ2xlL3NoYWthLXBhY2thZ2VyAHYyLjIuMS0zNTQxMTY2LXJlbGVhc2UAAALddHJhawAAAFx0a2hkAAAAB9mQAqPZkAKjAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAeAAAAEOAAAAAACVW1kaWEAAAAgbWRoZAAAAADZkAKj2ZACowAAYagAAAAAVcQAAAAAAC1oZGxyAAAAAAAAAAB2aWRlAAAAAAAAAAAAAAAAVmlkZW9IYW5kbGVyAAAAAgBtaW5mAAAAJGRpbmYAAAAcZHJlZgAAAAAAAAABAAAADHVybCAAAAABAAABwHN0YmwAA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AEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4AbwBDAEQAVwBBADIAKwBjAEYAdQBkAEgAagBBADcARwBSADcAWABKAEEAZwA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBWADUAcwBxAHMAeAB2AFUAaQA5AFEAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgAAAABKcHNzaAAAAADt74upedZKzqPIJ9zVHSHtAAAAKhIQA9YgoJxv5xZHjA7GR7XJABIQA9YgoJxv5xZHjA7GR7XJAkjj3JWbBg=="
with open("init_audio.mp4", "wb+") as file:
    file.write(base64.b64decode(data))

然后下载音频文件,因为演示用的这个视频音频质量挺差的(64kbps),所以只有一个分片,直接下载就好,为了方便可以重命名成auduo.mp4。

然后我们观察视频的信息。
5
视频的最开始,也是init信息,可以用上面的方法生成init_video.mp4。
6
因为视频的体积比较大,所以视频网站进行了分片,但还是容易看明白的。每一个分段都是369秒长,然后一个接着一个,通过观察发现都是这种规律,所以可以将每个分片下载下来,然后copy/b进行二进制合并(注意一定要按顺序)。当然手动操作很麻烦,也可以把视频信息整成一个m3u8文件,调用现有的下载器下载(注意二进制合并)。得到了video.mp4(自己命名)。

接下来,你可以从init_audio.mp4和init_video.mp4获取到解密的key(这部分不解释)。形式大概是这样:

1c9de4f131494437cc9d63774df00400:105d76c2f64410c3f28b958dc2c7e127
1c9de4f131494437cc9d63774df00402:8e0a84607949c266066b4e1e9b9ea7b2

但是昨天试的时候发现只有第一个是有用的,第二个我也不知道是做什么用的。

然后是生成视频和音频的待解密文件,就是把init文件和视频/音频文件二进制合并在一起。

copy/b init_video.mp4+video.mp4 video_enc.mp4
copy/b init_audio.mp4+audio.mp4 audio_enc.mp4

这样我们得到了待解密的audio_enc.mp4和video_enc.mp4,获取到了各自的key,就可以使用mp4decrypt分别进行解密(类似于如下)。

mp4decrypt --show-progress --key 1c9de4f131494437cc9d63774df00400:105d76c2f64410c3f28b958dc2c7e127 video_enc.mp4 video_dec.mp4
mp4decrypt --show-progress --key dd5cdb4bd1265166655646565165151:63e215155565515514444 audio_enc.mp4 audio_dec.mp4

这时我们已经得到了未加密的video_dec.mp4和audio_dec.mp4,用ffmpeg进行整流就可以了。

ffmpeg -i video_dec.mp4 -i audio_dec.mp4 -c copy out.mp4

最后生成的out.mp4就是处理好的文件啦。

31 comments

  1. Very great post. I simply stumbled upon your blog and wished to say that I have really enjoyed browsing your weblog posts. Rubi Cyrus Ardelis

  2. That will be the end of this report. Right here youll find some web-sites that we assume youll appreciate, just click the links. Agna Othello Landrum

  3. Way cool! Some extremely valid points! I appreciate you penning this write-up and also the rest of the site is very good. Nana Abey Chemush

  4. Keep up the fantastic work , I read few blog posts on this web site and I conceive that your blog is real interesting and has lots of good info . Peria Colet Bobbye

  5. Hi there mates, how is everything, and what you desire to say concerning this post, in my view its genuinely amazing designed for me. Joellyn Hadley Kirstyn

  6. Hi there to every one, the contents present at this site are genuinely remarkable for people knowledge, well, keep up the nice work fellows. Emera Frank Acie

  7. Just wanna comment that you have a very decent internet site , I like the style and design it actually stands out. Elsbeth Christophe Jaquenetta

  8. Prof The correct concern for a simmering piddle burn crapper simplicity the pain sensation and dilute the hazard of good complications. Madlin Domingo Dayle

  9. You made some decent points there. I looked on the internet for the subject matter and found most people will approve with your blog. Olympie Tamas Iey

  10. No matter if some one searches for his vital thing, therefore he/she needs to be available that in detail, thus that thing is maintained over here. Mandy Elihu Jemie

Leave a Reply

邮箱地址不会被公开。 必填项已用*标注