]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vbox7.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / vbox7.py
CommitLineData
01c10ca2 1from .common import InfoExtractor
67bb70cd 2from ..utils import ExtractorError, base_url, int_or_none, url_basename
3from ..utils.traversal import traverse_obj
01c10ca2
PH
4
5
6class Vbox7IE(InfoExtractor):
3d6761ba
S
7 _VALID_URL = r'''(?x)
8 https?://
9 (?:[^/]+\.)?vbox7\.com/
10 (?:
11 play:|
12 (?:
13 emb/external\.php|
14 player/ext\.swf
15 )\?.*?\bvid=
16 )
17 (?P<id>[\da-fA-F]+)
18 '''
bfd973ec 19 _EMBED_REGEX = [r'<iframe[^>]+src=(?P<q>["\'])(?P<url>(?:https?:)?//vbox7\.com/emb/external\.php.+?)(?P=q)']
4248dad9 20 _GEO_COUNTRIES = ['BG']
cb55908e
S
21 _TESTS = [{
22 'url': 'http://vbox7.com/play:0946fff23c',
67bb70cd 23 'md5': '50ca1f78345a9c15391af47d8062d074',
cb55908e
S
24 'info_dict': {
25 'id': '0946fff23c',
26 'ext': 'mp4',
27 'title': 'Борисов: Притеснен съм за бъдещето на България',
3d6761ba 28 'description': 'По думите му е опасно страната ни да бъде обявена за "сигурна"',
ec85ded8 29 'thumbnail': r're:^https?://.*\.jpg$',
3d6761ba
S
30 'timestamp': 1470982814,
31 'upload_date': '20160812',
32 'uploader': 'zdraveibulgaria',
67bb70cd 33 'view_count': int,
34 'duration': 2640,
cb55908e
S
35 },
36 }, {
50451f2a 37 'url': 'http://vbox7.com/play:249bb972c2',
67bb70cd 38 'md5': 'da1dd2eb245200cb86e6d09d43232116',
50451f2a
JMF
39 'info_dict': {
40 'id': '249bb972c2',
8e6f8051 41 'ext': 'mp4',
50451f2a 42 'title': 'Смях! Чудо - чист за секунди - Скрита камера',
67bb70cd 43 'uploader': 'svideteliat_ot_varshava',
44 'view_count': int,
45 'timestamp': 1360215023,
615a8444 46 'thumbnail': 'https://i49.vbox7.com/o/249/249bb972c20.jpg',
67bb70cd 47 'description': 'Смях! Чудо - чист за секунди - Скрита камера',
48 'upload_date': '20130207',
49 'duration': 83,
50451f2a 50 },
67bb70cd 51 'expected_warnings': ['Failed to download m3u8 information'],
9c0fa60b
S
52 }, {
53 'url': 'http://vbox7.com/emb/external.php?vid=a240d20f9c&autoplay=1',
54 'only_matching': True,
3d6761ba
S
55 }, {
56 'url': 'http://i49.vbox7.com/player/ext.swf?vid=0946fff23c&autoplay=1',
57 'only_matching': True,
cb55908e 58 }]
01c10ca2 59
50451f2a 60 def _real_extract(self, url):
1cc79574 61 video_id = self._match_id(url)
01c10ca2 62
67bb70cd 63 data = self._download_json(
64 'https://www.vbox7.com/aj/player/item/options', video_id,
65 query={'vid': video_id})['options']
01c10ca2 66
67bb70cd 67 src_url = data.get('src')
68 if src_url in (None, '', 'blank'):
69 raise ExtractorError('Video is unavailable', expected=True)
3d6761ba 70
67bb70cd 71 fmt_base = url_basename(src_url).rsplit('.', 1)[0].rsplit('_', 1)[0]
72 if fmt_base == 'vn':
73 self.raise_geo_restricted()
3d6761ba 74
67bb70cd 75 fmt_base = base_url(src_url) + fmt_base
3d6761ba 76
67bb70cd 77 formats = self._extract_m3u8_formats(
78 f'{fmt_base}.m3u8', video_id, m3u8_id='hls', fatal=False)
79 # TODO: Add MPD formats, when dash range support is added
80 for res in traverse_obj(data, ('resolutions', lambda _, v: v != 0, {int})):
81 formats.append({
82 'url': f'{fmt_base}_{res}.mp4',
83 'format_id': f'http-{res}',
84 'height': res,
85 })
3d6761ba 86
67bb70cd 87 return {
50451f2a 88 'id': video_id,
67bb70cd 89 'formats': formats,
90 **self._search_json_ld(self._download_webpage(
91 f'https://www.vbox7.com/play:{video_id}', video_id, fatal=False) or '', video_id, fatal=False),
92 **traverse_obj(data, {
93 'title': ('title', {str}),
94 'uploader': ('uploader', {str}),
95 'duration': ('duration', {int_or_none}),
96 }),
97 }