]>
Commit | Line | Data |
---|---|---|
439a1fff JMF |
1 | from __future__ import unicode_literals |
2 | ||
a08dfd27 PH |
3 | import binascii |
4 | import base64 | |
5 | import hashlib | |
6 | import re | |
fbf189a6 | 7 | import json |
a08dfd27 PH |
8 | |
9 | from .common import InfoExtractor | |
8c25f81b | 10 | from ..compat import ( |
a08dfd27 PH |
11 | compat_ord, |
12 | compat_urllib_parse, | |
9fd3bf04 | 13 | compat_urllib_parse_unquote, |
fbf189a6 | 14 | compat_urllib_request, |
8c25f81b PH |
15 | ) |
16 | from ..utils import ( | |
a08dfd27 PH |
17 | ExtractorError, |
18 | ) | |
19 | ||
20 | ||
a08dfd27 | 21 | class MyVideoIE(InfoExtractor): |
439a1fff JMF |
22 | _VALID_URL = r'http://(?:www\.)?myvideo\.de/(?:[^/]+/)?watch/(?P<id>[0-9]+)/[^?/]+.*' |
23 | IE_NAME = 'myvideo' | |
6f5ac90c | 24 | _TEST = { |
439a1fff JMF |
25 | 'url': 'http://www.myvideo.de/watch/8229274/bowling_fail_or_win', |
26 | 'md5': '2d2753e8130479ba2cb7e0a37002053e', | |
27 | 'info_dict': { | |
28 | 'id': '8229274', | |
29 | 'ext': 'flv', | |
30 | 'title': 'bowling-fail-or-win', | |
6f5ac90c PH |
31 | } |
32 | } | |
a08dfd27 PH |
33 | |
34 | # Original Code from: https://github.com/dersphere/plugin.video.myvideo_de.git | |
35 | # Released into the Public Domain by Tristan Fischer on 2013-05-19 | |
36 | # https://github.com/rg3/youtube-dl/pull/842 | |
5f6a1245 | 37 | def __rc4crypt(self, data, key): |
a08dfd27 PH |
38 | x = 0 |
39 | box = list(range(256)) | |
40 | for i in list(range(256)): | |
41 | x = (x + box[i] + compat_ord(key[i % len(key)])) % 256 | |
42 | box[i], box[x] = box[x], box[i] | |
43 | x = 0 | |
44 | y = 0 | |
45 | out = '' | |
46 | for char in data: | |
47 | x = (x + 1) % 256 | |
48 | y = (y + box[x]) % 256 | |
49 | box[x], box[y] = box[y], box[x] | |
50 | out += chr(compat_ord(char) ^ box[(box[x] + box[y]) % 256]) | |
51 | return out | |
52 | ||
5f6a1245 | 53 | def __md5(self, s): |
a08dfd27 PH |
54 | return hashlib.md5(s).hexdigest().encode() |
55 | ||
5f6a1245 | 56 | def _real_extract(self, url): |
a08dfd27 | 57 | mobj = re.match(self._VALID_URL, url) |
439a1fff | 58 | video_id = mobj.group('id') |
a08dfd27 PH |
59 | |
60 | GK = ( | |
b74e86f4 PH |
61 | b'WXpnME1EZGhNRGhpTTJNM01XVmhOREU0WldNNVpHTTJOakpt' |
62 | b'TW1FMU5tVTBNR05pWkRaa05XRXhNVFJoWVRVd1ptSXhaVEV3' | |
63 | b'TnpsbA0KTVRkbU1tSTRNdz09' | |
a08dfd27 PH |
64 | ) |
65 | ||
66 | # Get video webpage | |
67 | webpage_url = 'http://www.myvideo.de/watch/%s' % video_id | |
68 | webpage = self._download_webpage(webpage_url, video_id) | |
69 | ||
70 | mobj = re.search('source src=\'(.+?)[.]([^.]+)\'', webpage) | |
71 | if mobj is not None: | |
72 | self.report_extraction(video_id) | |
73 | video_url = mobj.group(1) + '.flv' | |
74 | ||
75 | video_title = self._html_search_regex('<title>([^<]+)</title>', | |
9e1a5b84 | 76 | webpage, 'title') |
a08dfd27 | 77 | |
439a1fff JMF |
78 | return { |
79 | 'id': video_id, | |
80 | 'url': video_url, | |
81 | 'title': video_title, | |
82 | } | |
a08dfd27 | 83 | |
fbf189a6 JMF |
84 | mobj = re.search(r'data-video-service="/service/data/video/%s/config' % video_id, webpage) |
85 | if mobj is not None: | |
86 | request = compat_urllib_request.Request('http://www.myvideo.de/service/data/video/%s/config' % video_id, '') | |
87 | response = self._download_webpage(request, video_id, | |
439a1fff | 88 | 'Downloading video info') |
fbf189a6 | 89 | info = json.loads(base64.b64decode(response).decode('utf-8')) |
439a1fff JMF |
90 | return { |
91 | 'id': video_id, | |
92 | 'title': info['title'], | |
93 | 'url': info['streaming_url'].replace('rtmpe', 'rtmpt'), | |
94 | 'play_path': info['filename'], | |
95 | 'ext': 'flv', | |
96 | 'thumbnail': info['thumbnail'][0]['url'], | |
97 | } | |
fbf189a6 | 98 | |
a08dfd27 PH |
99 | # try encxml |
100 | mobj = re.search('var flashvars={(.+?)}', webpage) | |
101 | if mobj is None: | |
439a1fff | 102 | raise ExtractorError('Unable to extract video') |
a08dfd27 PH |
103 | |
104 | params = {} | |
105 | encxml = '' | |
106 | sec = mobj.group(1) | |
107 | for (a, b) in re.findall('(.+?):\'(.+?)\',?', sec): | |
108 | if not a == '_encxml': | |
109 | params[a] = b | |
110 | else: | |
9fd3bf04 | 111 | encxml = compat_urllib_parse_unquote(b) |
a08dfd27 PH |
112 | if not params.get('domain'): |
113 | params['domain'] = 'www.myvideo.de' | |
114 | xmldata_url = '%s?%s' % (encxml, compat_urllib_parse.urlencode(params)) | |
115 | if 'flash_playertype=MTV' in xmldata_url: | |
439a1fff | 116 | self._downloader.report_warning('avoiding MTV player') |
a08dfd27 PH |
117 | xmldata_url = ( |
118 | 'http://www.myvideo.de/dynamic/get_player_video_xml.php' | |
119 | '?flash_playertype=D&ID=%s&_countlimit=4&autorun=yes' | |
120 | ) % video_id | |
121 | ||
122 | # get enc data | |
123 | enc_data = self._download_webpage(xmldata_url, video_id).split('=')[1] | |
124 | enc_data_b = binascii.unhexlify(enc_data) | |
125 | sk = self.__md5( | |
126 | base64.b64decode(base64.b64decode(GK)) + | |
127 | self.__md5( | |
128 | str(video_id).encode('utf-8') | |
129 | ) | |
130 | ) | |
131 | dec_data = self.__rc4crypt(enc_data_b, sk) | |
132 | ||
133 | # extracting infos | |
134 | self.report_extraction(video_id) | |
135 | ||
136 | video_url = None | |
137 | mobj = re.search('connectionurl=\'(.*?)\'', dec_data) | |
138 | if mobj: | |
9fd3bf04 | 139 | video_url = compat_urllib_parse_unquote(mobj.group(1)) |
a08dfd27 | 140 | if 'myvideo2flash' in video_url: |
f45f96f8 | 141 | self.report_warning( |
439a1fff | 142 | 'Rewriting URL to use unencrypted rtmp:// ...', |
f45f96f8 PH |
143 | video_id) |
144 | video_url = video_url.replace('rtmpe://', 'rtmp://') | |
a08dfd27 PH |
145 | |
146 | if not video_url: | |
147 | # extract non rtmp videos | |
148 | mobj = re.search('path=\'(http.*?)\' source=\'(.*?)\'', dec_data) | |
149 | if mobj is None: | |
439a1fff | 150 | raise ExtractorError('unable to extract url') |
9fd3bf04 | 151 | video_url = compat_urllib_parse_unquote(mobj.group(1)) + compat_urllib_parse_unquote(mobj.group(2)) |
a08dfd27 | 152 | |
439a1fff | 153 | video_file = self._search_regex('source=\'(.*?)\'', dec_data, 'video file') |
9fd3bf04 | 154 | video_file = compat_urllib_parse_unquote(video_file) |
a08dfd27 PH |
155 | |
156 | if not video_file.endswith('f4m'): | |
157 | ppath, prefix = video_file.split('.') | |
158 | video_playpath = '%s:%s' % (prefix, ppath) | |
a08dfd27 PH |
159 | else: |
160 | video_playpath = '' | |
a08dfd27 | 161 | |
439a1fff | 162 | video_swfobj = self._search_regex('swfobject.embedSWF\(\'(.+?)\'', webpage, 'swfobj') |
9fd3bf04 | 163 | video_swfobj = compat_urllib_parse_unquote(video_swfobj) |
a08dfd27 PH |
164 | |
165 | video_title = self._html_search_regex("<h1(?: class='globalHd')?>(.*?)</h1>", | |
9e1a5b84 | 166 | webpage, 'title') |
439a1fff JMF |
167 | |
168 | return { | |
169 | 'id': video_id, | |
170 | 'url': video_url, | |
171 | 'tc_url': video_url, | |
172 | 'title': video_title, | |
173 | 'ext': 'flv', | |
174 | 'play_path': video_playpath, | |
175 | 'player_url': video_swfobj, | |
176 | } |