]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/vbox7.py
[ChangeLog] Actualize
[youtube-dl.git] / youtube_dl / extractor / vbox7.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import ExtractorError
8
9
10 class Vbox7IE(InfoExtractor):
11     _VALID_URL = r'''(?x)
12                     https?://
13                         (?:[^/]+\.)?vbox7\.com/
14                         (?:
15                             play:|
16                             (?:
17                                 emb/external\.php|
18                                 player/ext\.swf
19                             )\?.*?\bvid=
20                         )
21                         (?P<id>[\da-fA-F]+)
22                     '''
23     _GEO_COUNTRIES = ['BG']
24     _TESTS = [{
25         'url': 'http://vbox7.com/play:0946fff23c',
26         'md5': 'a60f9ab3a3a2f013ef9a967d5f7be5bf',
27         'info_dict': {
28             'id': '0946fff23c',
29             'ext': 'mp4',
30             'title': 'Борисов: Притеснен съм за бъдещето на България',
31             'description': 'По думите му е опасно страната ни да бъде обявена за "сигурна"',
32             'thumbnail': r're:^https?://.*\.jpg$',
33             'timestamp': 1470982814,
34             'upload_date': '20160812',
35             'uploader': 'zdraveibulgaria',
36         },
37         'params': {
38             'proxy': '127.0.0.1:8118',
39         },
40     }, {
41         'url': 'http://vbox7.com/play:249bb972c2',
42         'md5': '99f65c0c9ef9b682b97313e052734c3f',
43         'info_dict': {
44             'id': '249bb972c2',
45             'ext': 'mp4',
46             'title': 'Смях! Чудо - чист за секунди - Скрита камера',
47         },
48         'skip': 'georestricted',
49     }, {
50         'url': 'http://vbox7.com/emb/external.php?vid=a240d20f9c&autoplay=1',
51         'only_matching': True,
52     }, {
53         'url': 'http://i49.vbox7.com/player/ext.swf?vid=0946fff23c&autoplay=1',
54         'only_matching': True,
55     }]
56
57     @staticmethod
58     def _extract_url(webpage):
59         mobj = re.search(
60             r'<iframe[^>]+src=(?P<q>["\'])(?P<url>(?:https?:)?//vbox7\.com/emb/external\.php.+?)(?P=q)',
61             webpage)
62         if mobj:
63             return mobj.group('url')
64
65     def _real_extract(self, url):
66         video_id = self._match_id(url)
67
68         response = self._download_json(
69             'https://www.vbox7.com/ajax/video/nextvideo.php?vid=%s' % video_id,
70             video_id)
71
72         if 'error' in response:
73             raise ExtractorError(
74                 '%s said: %s' % (self.IE_NAME, response['error']), expected=True)
75
76         video = response['options']
77
78         title = video['title']
79         video_url = video['src']
80
81         if '/na.mp4' in video_url:
82             self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
83
84         uploader = video.get('uploader')
85
86         webpage = self._download_webpage(
87             'http://vbox7.com/play:%s' % video_id, video_id, fatal=None)
88
89         info = {}
90
91         if webpage:
92             info = self._search_json_ld(
93                 webpage.replace('"/*@context"', '"@context"'), video_id,
94                 fatal=False)
95
96         info.update({
97             'id': video_id,
98             'title': title,
99             'url': video_url,
100             'uploader': uploader,
101             'thumbnail': self._proto_relative_url(
102                 info.get('thumbnail') or self._og_search_thumbnail(webpage),
103                 'http:'),
104         })
105         return info