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