]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/vbox7.py
fa7899e6dbd779fa824e1c4cdfdf16b76a8716eb
[youtube-dl] / youtube_dl / extractor / vbox7.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import urlencode_postdata
6
7
8 class Vbox7IE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?vbox7\.com/play:(?P<id>[^/]+)'
10     _TESTS = [{
11         'url': 'http://vbox7.com/play:0946fff23c',
12         'md5': 'a60f9ab3a3a2f013ef9a967d5f7be5bf',
13         'info_dict': {
14             'id': '0946fff23c',
15             'ext': 'mp4',
16             'title': 'Борисов: Притеснен съм за бъдещето на България',
17         },
18     }, {
19         'url': 'http://vbox7.com/play:249bb972c2',
20         'md5': '99f65c0c9ef9b682b97313e052734c3f',
21         'info_dict': {
22             'id': '249bb972c2',
23             'ext': 'mp4',
24             'title': 'Смях! Чудо - чист за секунди - Скрита камера',
25         },
26         'skip': 'georestricted',
27     }]
28
29     def _real_extract(self, url):
30         video_id = self._match_id(url)
31
32         webpage = self._download_webpage(url, video_id)
33
34         title = self._html_search_regex(
35             r'<title>(.*)</title>', webpage, 'title').split('/')[0].strip()
36
37         video_url = self._search_regex(
38             r'src\s*:\s*(["\'])(?P<url>.+?.mp4.*?)\1',
39             webpage, 'video url', default=None, group='url')
40
41         thumbnail_url = self._og_search_thumbnail(webpage)
42
43         if not video_url:
44             info_response = self._download_webpage(
45                 'http://vbox7.com/play/magare.do', video_id,
46                 'Downloading info webpage',
47                 data=urlencode_postdata({'as3': '1', 'vid': video_id}),
48                 headers={'Content-Type': 'application/x-www-form-urlencoded'})
49             final_url, thumbnail_url = map(
50                 lambda x: x.split('=')[1], info_response.split('&'))
51
52         if '/na.mp4' in video_url:
53             self.raise_geo_restricted()
54
55         return {
56             'id': video_id,
57             'url': self._proto_relative_url(video_url, 'http:'),
58             'title': title,
59             'thumbnail': thumbnail_url,
60         }