View Single Post
  #25  
Old 05-24-2014, 03:50 PM
Dune Dune is offline
Member
 
Join Date: May 2014
Posts: 39
Dune is on a distinguished road
Default

Re: Decrypt AES-128 encrypted video files from a m3u8


Quote:
Originally Posted by Nopt View Post
I'm not sure what you mean by "port", it has nothing to do with the earlier ruby code (which only handle a classic HLS stream)
My code specifically and only address the problem of the encrypted .key file. (it even includes the secret - well not that secret anymore - key !)

If you want a python port of the ruby code (to dump a classic HLS stream like ffmpeg would do) it's more like that :
Code:
import m3u8
from Crypto.Cipher import AES
f = open('file.ts','rb')
playlist = m3u8.loads(playlist) 
key = urllib2.urlopen(playlist.key.uri).read() # <- swap that line with my earlier snippet to handle encrypted keys
iv = ('%x' % int(playlist.key.iv,16)).decode("hex")
aes = AES.new(key, AES.MODE_CBC, iv)
for x in playlist.segments :
	r = urllib2.urlopen(x.uri)
	d = r.read()
	d = aes.decrypt(d)
	f.write(d)
f.close()
Oh I'm sorry I didn't look too puch into the Ruby code and thought all you did was porting.

Thank you a HUGE lot for your investment!
I just tested it, and it works!!! It is going to help a lot of us, that's for sure

Dat key though

Huge thanks again!

Edit: as Spyne said, it would help us a bunch in the future if you could give a few directions&tip as to how to get this key.
Reply With Quote