]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vbox7.py
[vbox7] Add support for embed URLs
[yt-dlp.git] / youtube_dl / extractor / vbox7.py
CommitLineData
50451f2a
JMF
1# encoding: utf-8
2from __future__ import unicode_literals
3
01c10ca2 4from .common import InfoExtractor
cd29eaab 5from ..utils import urlencode_postdata
01c10ca2
PH
6
7
8class Vbox7IE(InfoExtractor):
9c0fa60b 9 _VALID_URL = r'https?://(?:www\.)?vbox7\.com/(?:play:|emb/external\.php\?.*?\bvid=)(?P<id>[\da-fA-F]+)'
cb55908e
S
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 }, {
50451f2a
JMF
19 'url': 'http://vbox7.com/play:249bb972c2',
20 'md5': '99f65c0c9ef9b682b97313e052734c3f',
21 'info_dict': {
22 'id': '249bb972c2',
8e6f8051 23 'ext': 'mp4',
50451f2a
JMF
24 'title': 'Смях! Чудо - чист за секунди - Скрита камера',
25 },
cb55908e 26 'skip': 'georestricted',
9c0fa60b
S
27 }, {
28 'url': 'http://vbox7.com/emb/external.php?vid=a240d20f9c&autoplay=1',
29 'only_matching': True,
cb55908e 30 }]
01c10ca2 31
50451f2a 32 def _real_extract(self, url):
1cc79574 33 video_id = self._match_id(url)
01c10ca2 34
9c0fa60b
S
35 webpage = self._download_webpage(
36 'http://vbox7.com/play:%s' % video_id, video_id)
cb55908e
S
37
38 title = self._html_search_regex(
9c0fa60b 39 r'<title>(.+?)</title>', webpage, 'title').split('/')[0].strip()
cb55908e
S
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()
01c10ca2 58
50451f2a
JMF
59 return {
60 'id': video_id,
cb55908e 61 'url': self._proto_relative_url(video_url, 'http:'),
50451f2a 62 'title': title,
01c10ca2 63 'thumbnail': thumbnail_url,
50451f2a 64 }