Python 2 compat fixes for MyVideo.de rtmpdump downloads

pull/8/head
Filippo Valsorda 12 years ago
parent f008688520
commit b31756c18e

@ -1982,27 +1982,27 @@ class MyVideoIE(InfoExtractor):
_VALID_URL = r'(?:http://)?(?:www\.)?myvideo\.de/watch/([0-9]+)/([^?/]+).*' _VALID_URL = r'(?:http://)?(?:www\.)?myvideo\.de/watch/([0-9]+)/([^?/]+).*'
IE_NAME = u'myvideo' IE_NAME = u'myvideo'
# Original Code from: https://github.com/dersphere/plugin.video.myvideo_de.git # 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): def __rc4crypt(self,data, key):
x = 0 x = 0
box = list(range(256)) box = list(range(256))
for i in 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] box[i], box[x] = box[x], box[i]
x = 0 x = 0
y = 0 y = 0
out = [] out = ''
for char in data: for char in data:
x = (x + 1) % 256 x = (x + 1) % 256
y = (y + box[x]) % 256 y = (y + box[x]) % 256
box[x], box[y] = box[y], box[x] box[x], box[y] = box[y], box[x]
# out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256])) out += chr(compat_ord(char) ^ box[(box[x] + box[y]) % 256])
out.append(chr(char ^ box[(box[x] + box[y]) % 256])) return out
return ''.join(out)
def __md5(self,s): def __md5(self,s):
return hashlib.md5(s).hexdigest() return hashlib.md5(s).hexdigest().encode()
def _real_extract(self,url): def _real_extract(self,url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
@ -2046,9 +2046,13 @@ class MyVideoIE(InfoExtractor):
}] }]
# try encxml # try encxml
mobj = re.search('var flashvars={(.+?)}', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract video')
params = {} params = {}
encxml = '' encxml = ''
sec = re.search('var flashvars={(.+?)}', webpage).group(1) sec = mobj.group(1)
for (a, b) in re.findall('(.+?):\'(.+?)\',?', sec): for (a, b) in re.findall('(.+?):\'(.+?)\',?', sec):
if not a == '_encxml': if not a == '_encxml':
params[a] = b params[a] = b
@ -2067,11 +2071,11 @@ class MyVideoIE(InfoExtractor):
# get enc data # get enc data
enc_data = self._download_webpage(xmldata_url, video_id).split('=')[1] enc_data = self._download_webpage(xmldata_url, video_id).split('=')[1]
enc_data_b = binascii.unhexlify(enc_data) enc_data_b = binascii.unhexlify(enc_data)
sk = self.__md5( sk = self.__md5(
base64.b64decode(base64.b64decode(GK)) + base64.b64decode(base64.b64decode(GK)) +
self.__md5( self.__md5(
str(video_id).encode('utf-8') str(video_id).encode('utf-8')
).encode('utf-8') )
) )
dec_data = self.__rc4crypt(enc_data_b, sk) dec_data = self.__rc4crypt(enc_data_b, sk)
@ -2098,11 +2102,6 @@ class MyVideoIE(InfoExtractor):
raise ExtractorError(u'unable to extract swfobj') raise ExtractorError(u'unable to extract swfobj')
video_file = compat_urllib_parse.unquote(mobj.group(1)) 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'): if not video_file.endswith('f4m'):
ppath, prefix = video_file.split('.') ppath, prefix = video_file.split('.')
video_playpath = '%s:%s' % (prefix, ppath) video_playpath = '%s:%s' % (prefix, ppath)
@ -2133,7 +2132,6 @@ class MyVideoIE(InfoExtractor):
'ext': u'flv', 'ext': u'flv',
'play_path': video_playpath, 'play_path': video_playpath,
'video_file': video_file, 'video_file': video_file,
# 'file_path': video_filepath,
'video_hls_playlist': video_hls_playlist, 'video_hls_playlist': video_hls_playlist,
'player_url': video_swfobj, 'player_url': video_swfobj,
}] }]

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

Loading…
Cancel
Save