]>
Commit | Line | Data |
---|---|---|
50451f2a JMF |
1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
01c10ca2 PH |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | compat_urllib_parse, | |
9 | compat_urllib_request, | |
10 | ||
11 | ExtractorError, | |
12 | ) | |
13 | ||
14 | ||
15 | class Vbox7IE(InfoExtractor): | |
50451f2a | 16 | _VALID_URL = r'http://(www\.)?vbox7\.com/play:(?P<id>[^/]+)' |
6f5ac90c | 17 | _TEST = { |
50451f2a JMF |
18 | 'url': 'http://vbox7.com/play:249bb972c2', |
19 | 'md5': '99f65c0c9ef9b682b97313e052734c3f', | |
20 | 'info_dict': { | |
21 | 'id': '249bb972c2', | |
8e6f8051 | 22 | 'ext': 'mp4', |
50451f2a JMF |
23 | 'title': 'Смях! Чудо - чист за секунди - Скрита камера', |
24 | }, | |
6f5ac90c | 25 | } |
01c10ca2 | 26 | |
50451f2a | 27 | def _real_extract(self, url): |
01c10ca2 | 28 | mobj = re.match(self._VALID_URL, url) |
50451f2a | 29 | video_id = mobj.group('id') |
01c10ca2 PH |
30 | |
31 | redirect_page, urlh = self._download_webpage_handle(url, video_id) | |
50451f2a | 32 | new_location = self._search_regex(r'window\.location = \'(.*)\';', |
9e1a5b84 | 33 | redirect_page, 'redirect location') |
01c10ca2 | 34 | redirect_url = urlh.geturl() + new_location |
50451f2a | 35 | webpage = self._download_webpage(redirect_url, video_id, |
9e1a5b84 | 36 | 'Downloading redirect page') |
01c10ca2 PH |
37 | |
38 | title = self._html_search_regex(r'<title>(.*)</title>', | |
9e1a5b84 | 39 | webpage, 'title').split('/')[0].strip() |
01c10ca2 | 40 | |
01c10ca2 | 41 | info_url = "http://vbox7.com/play/magare.do" |
50451f2a | 42 | data = compat_urllib_parse.urlencode({'as3': '1', 'vid': video_id}) |
01c10ca2 PH |
43 | info_request = compat_urllib_request.Request(info_url, data) |
44 | info_request.add_header('Content-Type', 'application/x-www-form-urlencoded') | |
50451f2a | 45 | info_response = self._download_webpage(info_request, video_id, 'Downloading info webpage') |
01c10ca2 | 46 | if info_response is None: |
50451f2a | 47 | raise ExtractorError('Unable to extract the media url') |
01c10ca2 PH |
48 | (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&')) |
49 | ||
50451f2a JMF |
50 | return { |
51 | 'id': video_id, | |
52 | 'url': final_url, | |
50451f2a | 53 | 'title': title, |
01c10ca2 | 54 | 'thumbnail': thumbnail_url, |
50451f2a | 55 | } |