]>
Commit | Line | Data |
---|---|---|
fc6861b1 | 1 | from .common import InfoExtractor |
327c8364 S |
2 | from ..utils import ( |
3 | determine_ext, | |
4 | int_or_none, | |
5 | js_to_json, | |
476cf548 | 6 | merge_dicts, |
327c8364 | 7 | ) |
fc6861b1 S |
8 | |
9 | ||
476cf548 S |
10 | class SportBoxIE(InfoExtractor): |
11 | _VALID_URL = r'https?://(?:news\.sportbox|matchtv)\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)' | |
bfd973ec | 12 | _EMBED_REGEX = [r'<iframe[^>]+src="(?P<url>https?://(?:news\.sportbox|matchtv)\.ru/vdl/player[^"]+)"'] |
3a738295 S |
13 | _TESTS = [{ |
14 | 'url': 'http://news.sportbox.ru/vdl/player/ci/211355', | |
15 | 'info_dict': { | |
476cf548 | 16 | 'id': '109158', |
3a738295 | 17 | 'ext': 'mp4', |
4c237ab7 | 18 | 'title': 'В Новороссийске прошел детский турнир «Поле славы боевой»', |
476cf548 | 19 | 'description': 'В Новороссийске прошел детский турнир «Поле славы боевой»', |
ec85ded8 | 20 | 'thumbnail': r're:^https?://.*\.jpg$', |
327c8364 S |
21 | 'duration': 292, |
22 | 'view_count': int, | |
476cf548 S |
23 | 'timestamp': 1426237001, |
24 | 'upload_date': '20150313', | |
3a738295 S |
25 | }, |
26 | 'params': { | |
27 | # m3u8 download | |
28 | 'skip_download': True, | |
29 | }, | |
30 | }, { | |
31 | 'url': 'http://news.sportbox.ru/vdl/player?nid=370908&only_player=1&autostart=false&playeri=2&height=340&width=580', | |
32 | 'only_matching': True, | |
327c8364 S |
33 | }, { |
34 | 'url': 'https://news.sportbox.ru/vdl/player/media/193095', | |
35 | 'only_matching': True, | |
476cf548 S |
36 | }, { |
37 | 'url': 'https://news.sportbox.ru/vdl/player/media/109158', | |
38 | 'only_matching': True, | |
39 | }, { | |
40 | 'url': 'https://matchtv.ru/vdl/player/media/109158', | |
41 | 'only_matching': True, | |
3a738295 S |
42 | }] |
43 | ||
44 | def _real_extract(self, url): | |
45 | video_id = self._match_id(url) | |
46 | ||
47 | webpage = self._download_webpage(url, video_id) | |
48 | ||
476cf548 | 49 | sources = self._parse_json( |
4c237ab7 | 50 | self._search_regex( |
476cf548 S |
51 | r'(?s)playerOptions\.sources(?:WithRes)?\s*=\s*(\[.+?\])\s*;\s*\n', |
52 | webpage, 'sources'), | |
4c237ab7 AT |
53 | video_id, transform_source=js_to_json) |
54 | ||
327c8364 | 55 | formats = [] |
476cf548 | 56 | for source in sources: |
327c8364 S |
57 | src = source.get('src') |
58 | if not src: | |
59 | continue | |
60 | if determine_ext(src) == 'm3u8': | |
61 | formats.extend(self._extract_m3u8_formats( | |
62 | src, video_id, 'mp4', entry_protocol='m3u8_native', | |
63 | m3u8_id='hls', fatal=False)) | |
64 | else: | |
65 | formats.append({ | |
66 | 'url': src, | |
67 | }) | |
3a738295 | 68 | |
476cf548 S |
69 | player = self._parse_json( |
70 | self._search_regex( | |
71 | r'(?s)playerOptions\s*=\s*({.+?})\s*;\s*\n', webpage, | |
72 | 'player options', default='{}'), | |
73 | video_id, transform_source=js_to_json) | |
74 | media_id = player['mediaId'] | |
75 | ||
76 | info = self._search_json_ld(webpage, media_id, default={}) | |
77 | ||
327c8364 S |
78 | view_count = int_or_none(self._search_regex( |
79 | r'Просмотров\s*:\s*(\d+)', webpage, 'view count', default=None)) | |
3a738295 | 80 | |
476cf548 S |
81 | return merge_dicts(info, { |
82 | 'id': media_id, | |
83 | 'title': self._og_search_title(webpage, default=None) or media_id, | |
84 | 'thumbnail': player.get('poster'), | |
85 | 'duration': int_or_none(player.get('duration')), | |
327c8364 | 86 | 'view_count': view_count, |
fc6861b1 | 87 | 'formats': formats, |
476cf548 | 88 | }) |