View Single Post
  #23  
Old 05-24-2014, 03:23 PM
Nopt Nopt is offline
Member
 
Join Date: May 2014
Posts: 37
Nopt is on a distinguished road
Default

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


Quote:
Originally Posted by Dune View Post
Thank you very much for the Python port! I'm gonna try this ASAP.
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()
Reply With Quote