]>
Commit | Line | Data |
---|---|---|
50451f2a JMF |
1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
01c10ca2 | 4 | from .common import InfoExtractor |
1cc79574 | 5 | from ..compat import ( |
01c10ca2 | 6 | compat_urllib_parse, |
4af98ecd | 7 | compat_urlparse, |
1cc79574 PH |
8 | ) |
9 | from ..utils import ( | |
01c10ca2 | 10 | ExtractorError, |
5c2266df | 11 | sanitized_Request, |
01c10ca2 PH |
12 | ) |
13 | ||
14 | ||
15 | class Vbox7IE(InfoExtractor): | |
1cc79574 | 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): |
1cc79574 | 28 | video_id = self._match_id(url) |
01c10ca2 | 29 | |
4af98ecd YCH |
30 | # need to get the page 3 times for the correct jsSecretToken cookie |
31 | # which is necessary for the correct title | |
32 | def get_session_id(): | |
33 | redirect_page = self._download_webpage(url, video_id) | |
34 | session_id_url = self._search_regex( | |
35 | r'var\s*url\s*=\s*\'([^\']+)\';', redirect_page, | |
36 | 'session id url') | |
37 | self._download_webpage( | |
38 | compat_urlparse.urljoin(url, session_id_url), video_id, | |
39 | 'Getting session id') | |
40 | ||
41 | get_session_id() | |
42 | get_session_id() | |
43 | ||
44 | webpage = self._download_webpage(url, video_id, | |
9e1a5b84 | 45 | 'Downloading redirect page') |
01c10ca2 PH |
46 | |
47 | title = self._html_search_regex(r'<title>(.*)</title>', | |
9e1a5b84 | 48 | webpage, 'title').split('/')[0].strip() |
01c10ca2 | 49 | |
01c10ca2 | 50 | info_url = "http://vbox7.com/play/magare.do" |
50451f2a | 51 | data = compat_urllib_parse.urlencode({'as3': '1', 'vid': video_id}) |
5c2266df | 52 | info_request = sanitized_Request(info_url, data) |
01c10ca2 | 53 | info_request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
50451f2a | 54 | info_response = self._download_webpage(info_request, video_id, 'Downloading info webpage') |
01c10ca2 | 55 | if info_response is None: |
50451f2a | 56 | raise ExtractorError('Unable to extract the media url') |
01c10ca2 PH |
57 | (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&')) |
58 | ||
50451f2a JMF |
59 | return { |
60 | 'id': video_id, | |
61 | 'url': final_url, | |
50451f2a | 62 | 'title': title, |
01c10ca2 | 63 | 'thumbnail': thumbnail_url, |
50451f2a | 64 | } |