]>
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, | |
11 | ) | |
fc6861b1 S |
12 | |
13 | ||
3a738295 S |
14 | class SportBoxEmbedIE(InfoExtractor): |
15 | _VALID_URL = r'https?://news\.sportbox\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)' | |
16 | _TESTS = [{ | |
17 | 'url': 'http://news.sportbox.ru/vdl/player/ci/211355', | |
18 | 'info_dict': { | |
19 | 'id': '211355', | |
20 | 'ext': 'mp4', | |
327c8364 | 21 | 'title': '211355', |
ec85ded8 | 22 | 'thumbnail': r're:^https?://.*\.jpg$', |
327c8364 S |
23 | 'duration': 292, |
24 | 'view_count': int, | |
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, | |
3a738295 S |
36 | }] |
37 | ||
1436a683 S |
38 | @staticmethod |
39 | def _extract_urls(webpage): | |
40 | return re.findall( | |
41 | r'<iframe[^>]+src="(https?://news\.sportbox\.ru/vdl/player[^"]+)"', | |
42 | webpage) | |
43 | ||
3a738295 S |
44 | def _real_extract(self, url): |
45 | video_id = self._match_id(url) | |
46 | ||
47 | webpage = self._download_webpage(url, video_id) | |
48 | ||
327c8364 S |
49 | wjplayer_data = self._parse_json( |
50 | self._search_regex( | |
51 | r'(?s)wjplayer\(({.+?})\);', webpage, 'wjplayer settings'), | |
52 | video_id, transform_source=js_to_json) | |
260c7036 | 53 | |
327c8364 S |
54 | formats = [] |
55 | for source in wjplayer_data['sources']: | |
56 | src = source.get('src') | |
57 | if not src: | |
58 | continue | |
59 | if determine_ext(src) == 'm3u8': | |
60 | formats.extend(self._extract_m3u8_formats( | |
61 | src, video_id, 'mp4', entry_protocol='m3u8_native', | |
62 | m3u8_id='hls', fatal=False)) | |
63 | else: | |
64 | formats.append({ | |
65 | 'url': src, | |
66 | }) | |
260c7036 | 67 | self._sort_formats(formats) |
3a738295 | 68 | |
327c8364 S |
69 | view_count = int_or_none(self._search_regex( |
70 | r'Просмотров\s*:\s*(\d+)', webpage, 'view count', default=None)) | |
3a738295 S |
71 | |
72 | return { | |
73 | 'id': video_id, | |
327c8364 S |
74 | 'title': video_id, |
75 | 'thumbnail': wjplayer_data.get('poster'), | |
76 | 'duration': int_or_none(wjplayer_data.get('duration')), | |
77 | 'view_count': view_count, | |
fc6861b1 S |
78 | 'formats': formats, |
79 | } |