[vbox7] Add support for embed URLs
[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:|emb/external\.php\?.*?\bvid=)(?P<id>[\da-fA-F]+)'
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         'url': 'http://vbox7.com/emb/external.php?vid=a240d20f9c&autoplay=1',
29         'only_matching': True,
30     }]
31
32     def _real_extract(self, url):
33         video_id = self._match_id(url)
34
35         webpage = self._download_webpage(
36             'http://vbox7.com/play:%s' % video_id, video_id)
37
38         title = self._html_search_regex(
39             r'<title>(.+?)</title>', webpage, 'title').split('/')[0].strip()
40
41         video_url = self._search_regex(
42             r'src\s*:\s*(["\'])(?P<url>.+?.mp4.*?)\1',
43             webpage, 'video url', default=None, group='url')
44
45         thumbnail_url = self._og_search_thumbnail(webpage)
46
47         if not video_url:
48             info_response = self._download_webpage(
49                 'http://vbox7.com/play/magare.do', video_id,
50                 'Downloading info webpage',
51                 data=urlencode_postdata({'as3': '1', 'vid': video_id}),
52                 headers={'Content-Type': 'application/x-www-form-urlencoded'})
53             final_url, thumbnail_url = map(
54                 lambda x: x.split('=')[1], info_response.split('&'))
55
56         if '/na.mp4' in video_url:
57             self.raise_geo_restricted()
58
59         return {
60             'id': video_id,
61             'url': self._proto_relative_url(video_url, 'http:'),
62             'title': title,
63             'thumbnail': thumbnail_url,
64         }