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