[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / sportbox.py
blobccbb0e8ccf4a480dc15750e6fdc292459ca1d28f
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 js_to_json,
6 merge_dicts,
10 class SportBoxIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:news\.sportbox|matchtv)\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)'
12 _EMBED_REGEX = [r'<iframe[^>]+src="(?P<url>https?://(?:news\.sportbox|matchtv)\.ru/vdl/player[^"]+)"']
13 _TESTS = [{
14 'url': 'http://news.sportbox.ru/vdl/player/ci/211355',
15 'info_dict': {
16 'id': '109158',
17 'ext': 'mp4',
18 'title': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
19 'description': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
20 'thumbnail': r're:^https?://.*\.jpg$',
21 'duration': 292,
22 'view_count': int,
23 'timestamp': 1426237001,
24 'upload_date': '20150313',
26 'params': {
27 # m3u8 download
28 'skip_download': True,
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,
33 }, {
34 'url': 'https://news.sportbox.ru/vdl/player/media/193095',
35 'only_matching': True,
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,
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
47 webpage = self._download_webpage(url, video_id)
49 sources = self._parse_json(
50 self._search_regex(
51 r'(?s)playerOptions\.sources(?:WithRes)?\s*=\s*(\[.+?\])\s*;\s*\n',
52 webpage, 'sources'),
53 video_id, transform_source=js_to_json)
55 formats = []
56 for source in sources:
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,
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']
76 info = self._search_json_ld(webpage, media_id, default={})
78 view_count = int_or_none(self._search_regex(
79 r'Просмотров\s*:\s*(\d+)', webpage, 'view count', default=None))
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')),
86 'view_count': view_count,
87 'formats': formats,