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