1 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import (
13 compat_urllib_parse_unquote
,
21 class MyVideoIE(InfoExtractor
):
23 _VALID_URL
= r
'http://(?:www\.)?myvideo\.de/(?:[^/]+/)?watch/(?P<id>[0-9]+)/[^?/]+.*'
26 'url': 'http://www.myvideo.de/watch/8229274/bowling_fail_or_win',
27 'md5': '2d2753e8130479ba2cb7e0a37002053e',
31 'title': 'bowling-fail-or-win',
35 # Original Code from: https://github.com/dersphere/plugin.video.myvideo_de.git
36 # Released into the Public Domain by Tristan Fischer on 2013-05-19
37 # https://github.com/rg3/youtube-dl/pull/842
38 def __rc4crypt(self
, data
, key
):
40 box
= list(range(256))
41 for i
in list(range(256)):
42 x
= (x
+ box
[i
] + compat_ord(key
[i
% len(key
)])) % 256
43 box
[i
], box
[x
] = box
[x
], box
[i
]
49 y
= (y
+ box
[x
]) % 256
50 box
[x
], box
[y
] = box
[y
], box
[x
]
51 out
+= chr(compat_ord(char
) ^ box
[(box
[x
] + box
[y
]) % 256])
55 return hashlib
.md5(s
).hexdigest().encode()
57 def _real_extract(self
, url
):
58 mobj
= re
.match(self
._VALID
_URL
, url
)
59 video_id
= mobj
.group('id')
62 b
'WXpnME1EZGhNRGhpTTJNM01XVmhOREU0WldNNVpHTTJOakpt'
63 b
'TW1FMU5tVTBNR05pWkRaa05XRXhNVFJoWVRVd1ptSXhaVEV3'
64 b
'TnpsbA0KTVRkbU1tSTRNdz09'
68 webpage_url
= 'http://www.myvideo.de/watch/%s' % video_id
69 webpage
= self
._download
_webpage
(webpage_url
, video_id
)
71 mobj
= re
.search('source src=\'(.+?)[.]([^.]+)\'', webpage
)
73 self
.report_extraction(video_id
)
74 video_url
= mobj
.group(1) + '.flv'
76 video_title
= self
._html
_search
_regex
('<title>([^<]+)</title>',
85 mobj
= re
.search(r
'data-video-service="/service/data/video/%s/config' % video_id
, webpage
)
87 request
= sanitized_Request('http://www.myvideo.de/service/data/video/%s/config' % video_id
, '')
88 response
= self
._download
_webpage
(request
, video_id
,
89 'Downloading video info')
90 info
= json
.loads(base64
.b64decode(response
).decode('utf-8'))
93 'title': info
['title'],
94 'url': info
['streaming_url'].replace('rtmpe', 'rtmpt'),
95 'play_path': info
['filename'],
97 'thumbnail': info
['thumbnail'][0]['url'],
101 mobj
= re
.search('var flashvars={(.+?)}', webpage
)
103 raise ExtractorError('Unable to extract video')
108 for (a
, b
) in re
.findall('(.+?):\'(.+?)\',?', sec
):
109 if not a
== '_encxml':
112 encxml
= compat_urllib_parse_unquote(b
)
113 if not params
.get('domain'):
114 params
['domain'] = 'www.myvideo.de'
115 xmldata_url
= '%s?%s' % (encxml
, compat_urllib_parse
.urlencode(params
))
116 if 'flash_playertype=MTV' in xmldata_url
:
117 self
._downloader
.report_warning('avoiding MTV player')
119 'http://www.myvideo.de/dynamic/get_player_video_xml.php'
120 '?flash_playertype=D&ID=%s&_countlimit=4&autorun=yes'
124 enc_data
= self
._download
_webpage
(xmldata_url
, video_id
).split('=')[1]
125 enc_data_b
= binascii
.unhexlify(enc_data
)
127 base64
.b64decode(base64
.b64decode(GK
)) +
129 str(video_id
).encode('utf-8')
132 dec_data
= self
.__rc
4crypt
(enc_data_b
, sk
)
135 self
.report_extraction(video_id
)
138 mobj
= re
.search('connectionurl=\'(.*?)\'', dec_data
)
140 video_url
= compat_urllib_parse_unquote(mobj
.group(1))
141 if 'myvideo2flash' in video_url
:
143 'Rewriting URL to use unencrypted rtmp:// ...',
145 video_url
= video_url
.replace('rtmpe://', 'rtmp://')
148 # extract non rtmp videos
149 mobj
= re
.search('path=\'(http.*?)\' source=\'(.*?)\'', dec_data
)
151 raise ExtractorError('unable to extract url')
152 video_url
= compat_urllib_parse_unquote(mobj
.group(1)) + compat_urllib_parse_unquote(mobj
.group(2))
154 video_file
= self
._search
_regex
('source=\'(.*?)\'', dec_data
, 'video file')
155 video_file
= compat_urllib_parse_unquote(video_file
)
157 if not video_file
.endswith('f4m'):
158 ppath
, prefix
= video_file
.split('.')
159 video_playpath
= '%s:%s' % (prefix
, ppath
)
163 video_swfobj
= self
._search
_regex
('swfobject.embedSWF\(\'(.+?)\'', webpage
, 'swfobj')
164 video_swfobj
= compat_urllib_parse_unquote(video_swfobj
)
166 video_title
= self
._html
_search
_regex
("<h1(?: class='globalHd')?>(.*?)</h1>",
173 'title': video_title
,
175 'play_path': video_playpath
,
176 'player_url': video_swfobj
,