Python 2 compat fixes for MyVideo.de rtmpdump downloads

This commit is contained in:
Filippo Valsorda 2013-05-20 11:57:10 +02:00
parent f008688520
commit b31756c18e
2 changed files with 22 additions and 20 deletions

View file

@ -1983,26 +1983,26 @@ class MyVideoIE(InfoExtractor):
IE_NAME = u'myvideo'
# Original Code from: https://github.com/dersphere/plugin.video.myvideo_de.git
# Copyright (C) 2013 Tristan Fischer (sphere@dersphere.de) - GPLv3
# Released into the Public Domain by Tristan Fischer on 2013-05-19
# https://github.com/rg3/youtube-dl/pull/842
def __rc4crypt(self,data, key):
x = 0
box = list(range(256))
for i in list(range(256)):
x = (x + box[i] + ord(key[i % len(key)])) % 256
x = (x + box[i] + compat_ord(key[i % len(key)])) % 256
box[i], box[x] = box[x], box[i]
x = 0
y = 0
out = []
out = ''
for char in data:
x = (x + 1) % 256
y = (y + box[x]) % 256
box[x], box[y] = box[y], box[x]
# out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))
out.append(chr(char ^ box[(box[x] + box[y]) % 256]))
return ''.join(out)
out += chr(compat_ord(char) ^ box[(box[x] + box[y]) % 256])
return out
def __md5(self,s):
return hashlib.md5(s).hexdigest()
return hashlib.md5(s).hexdigest().encode()
def _real_extract(self,url):
mobj = re.match(self._VALID_URL, url)
@ -2046,9 +2046,13 @@ class MyVideoIE(InfoExtractor):
}]
# try encxml
mobj = re.search('var flashvars={(.+?)}', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract video')
params = {}
encxml = ''
sec = re.search('var flashvars={(.+?)}', webpage).group(1)
sec = mobj.group(1)
for (a, b) in re.findall('(.+?):\'(.+?)\',?', sec):
if not a == '_encxml':
params[a] = b
@ -2071,7 +2075,7 @@ class MyVideoIE(InfoExtractor):
base64.b64decode(base64.b64decode(GK)) +
self.__md5(
str(video_id).encode('utf-8')
).encode('utf-8')
)
)
dec_data = self.__rc4crypt(enc_data_b, sk)
@ -2098,11 +2102,6 @@ class MyVideoIE(InfoExtractor):
raise ExtractorError(u'unable to extract swfobj')
video_file = compat_urllib_parse.unquote(mobj.group(1))
# mobj = re.search('path=\'(.*?)\'', dec_data)
# if mobj is None:
# raise ExtractorError(u'unable to extract filepath')
# video_filepath = mobj.group(1)
if not video_file.endswith('f4m'):
ppath, prefix = video_file.split('.')
video_playpath = '%s:%s' % (prefix, ppath)
@ -2133,7 +2132,6 @@ class MyVideoIE(InfoExtractor):
'ext': u'flv',
'play_path': video_playpath,
'video_file': video_file,
# 'file_path': video_filepath,
'video_hls_playlist': video_hls_playlist,
'player_url': video_swfobj,
}]

View file

@ -150,6 +150,10 @@ try:
except NameError:
compat_chr = chr
def compat_ord(c):
if type(c) is int: return c
else: return ord(c)
std_headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',