]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/myvideo.py
1 from __future__
import unicode_literals
9 from .common
import InfoExtractor
13 compat_urllib_request
,
19 class MyVideoIE(InfoExtractor
):
20 _VALID_URL
= r
'http://(?:www\.)?myvideo\.de/(?:[^/]+/)?watch/(?P<id>[0-9]+)/[^?/]+.*'
23 'url': 'http://www.myvideo.de/watch/8229274/bowling_fail_or_win',
24 'md5': '2d2753e8130479ba2cb7e0a37002053e',
28 'title': 'bowling-fail-or-win',
32 # Original Code from: https://github.com/dersphere/plugin.video.myvideo_de.git
33 # Released into the Public Domain by Tristan Fischer on 2013-05-19
34 # https://github.com/rg3/youtube-dl/pull/842
35 def __rc4crypt(self
,data
, key
):
37 box
= list(range(256))
38 for i
in list(range(256)):
39 x
= (x
+ box
[i
] + compat_ord(key
[i
% len(key
)])) % 256
40 box
[i
], box
[x
] = box
[x
], box
[i
]
46 y
= (y
+ box
[x
]) % 256
47 box
[x
], box
[y
] = box
[y
], box
[x
]
48 out
+= chr(compat_ord(char
) ^ box
[(box
[x
] + box
[y
]) % 256])
52 return hashlib
.md5(s
).hexdigest().encode()
54 def _real_extract(self
,url
):
55 mobj
= re
.match(self
._VALID
_URL
, url
)
56 video_id
= mobj
.group('id')
59 b
'WXpnME1EZGhNRGhpTTJNM01XVmhOREU0WldNNVpHTTJOakpt'
60 b
'TW1FMU5tVTBNR05pWkRaa05XRXhNVFJoWVRVd1ptSXhaVEV3'
61 b
'TnpsbA0KTVRkbU1tSTRNdz09'
65 webpage_url
= 'http://www.myvideo.de/watch/%s' % video_id
66 webpage
= self
._download
_webpage
(webpage_url
, video_id
)
68 mobj
= re
.search('source src=\'(.+?)[.]([^.]+)\'', webpage
)
70 self
.report_extraction(video_id
)
71 video_url
= mobj
.group(1) + '.flv'
73 video_title
= self
._html
_search
_regex
('<title>([^<]+)</title>',
82 mobj
= re
.search(r
'data-video-service="/service/data/video/%s/config' % video_id
, webpage
)
84 request
= compat_urllib_request
.Request('http://www.myvideo.de/service/data/video/%s/config' % video_id
, '')
85 response
= self
._download
_webpage
(request
, video_id
,
86 'Downloading video info')
87 info
= json
.loads(base64
.b64decode(response
).decode('utf-8'))
90 'title': info
['title'],
91 'url': info
['streaming_url'].replace('rtmpe', 'rtmpt'),
92 'play_path': info
['filename'],
94 'thumbnail': info
['thumbnail'][0]['url'],
98 mobj
= re
.search('var flashvars={(.+?)}', webpage
)
100 raise ExtractorError('Unable to extract video')
105 for (a
, b
) in re
.findall('(.+?):\'(.+?)\',?', sec
):
106 if not a
== '_encxml':
109 encxml
= compat_urllib_parse
.unquote(b
)
110 if not params
.get('domain'):
111 params
['domain'] = 'www.myvideo.de'
112 xmldata_url
= '%s?%s' % (encxml
, compat_urllib_parse
.urlencode(params
))
113 if 'flash_playertype=MTV' in xmldata_url
:
114 self
._downloader
.report_warning('avoiding MTV player')
116 'http://www.myvideo.de/dynamic/get_player_video_xml.php'
117 '?flash_playertype=D&ID=%s&_countlimit=4&autorun=yes'
121 enc_data
= self
._download
_webpage
(xmldata_url
, video_id
).split('=')[1]
122 enc_data_b
= binascii
.unhexlify(enc_data
)
124 base64
.b64decode(base64
.b64decode(GK
)) +
126 str(video_id
).encode('utf-8')
129 dec_data
= self
.__rc
4crypt
(enc_data_b
, sk
)
132 self
.report_extraction(video_id
)
135 mobj
= re
.search('connectionurl=\'(.*?)\'', dec_data
)
137 video_url
= compat_urllib_parse
.unquote(mobj
.group(1))
138 if 'myvideo2flash' in video_url
:
140 'Rewriting URL to use unencrypted rtmp:// ...',
142 video_url
= video_url
.replace('rtmpe://', 'rtmp://')
145 # extract non rtmp videos
146 mobj
= re
.search('path=\'(http.*?)\' source=\'(.*?)\'', dec_data
)
148 raise ExtractorError('unable to extract url')
149 video_url
= compat_urllib_parse
.unquote(mobj
.group(1)) + compat_urllib_parse
.unquote(mobj
.group(2))
151 video_file
= self
._search
_regex
('source=\'(.*?)\'', dec_data
, 'video file')
152 video_file
= compat_urllib_parse
.unquote(video_file
)
154 if not video_file
.endswith('f4m'):
155 ppath
, prefix
= video_file
.split('.')
156 video_playpath
= '%s:%s' % (prefix
, ppath
)
160 video_swfobj
= self
._search
_regex
('swfobject.embedSWF\(\'(.+?)\'', webpage
, 'swfobj')
161 video_swfobj
= compat_urllib_parse
.unquote(video_swfobj
)
163 video_title
= self
._html
_search
_regex
("<h1(?: class='globalHd')?>(.*?)</h1>",
170 'title': video_title
,
172 'play_path': video_playpath
,
173 'player_url': video_swfobj
,