]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/sportbox.py
[sportbox] Add extractor (Closes #3906)
[yt-dlp.git] / youtube_dl / extractor / sportbox.py
CommitLineData
fc6861b1
S
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..utils import (
8 parse_duration,
9 parse_iso8601,
10 int_or_none,
11)
12
13
14class SportBoxIE(InfoExtractor):
15 _VALID_URL = r'https?://news\.sportbox\.ru/Vidy_sporta/(?:[^/]+/)+spbvideo_NI\d+_(?P<display_id>.+)'
16 _TESTS = [
17 {
18 'url': 'http://news.sportbox.ru/Vidy_sporta/Avtosport/Rossijskij/spbvideo_NI483529_Gonka-2-zaezd-Obyedinenniy-2000-klassi-Turing-i-S',
19 'md5': 'ff56a598c2cf411a9a38a69709e97079',
20 'info_dict': {
21 'id': '80822',
22 'ext': 'mp4',
23 'title': 'Гонка 2 заезд ««Объединенный 2000»: классы Туринг и Супер-продакшн',
24 'description': 'md5:81715fa9c4ea3d9e7915dc8180c778ed',
25 'thumbnail': 're:^https?://.*\.jpg$',
26 'timestamp': 1411896237,
27 'upload_date': '20140928',
28 'duration': 4846,
29 'view_count': int,
30 },
31 'params': {
32 # m3u8 download
33 'skip_download': True,
34 },
35 }, {
36 'url': 'http://news.sportbox.ru/Vidy_sporta/billiard/spbvideo_NI486287_CHempionat-mira-po-dinamichnoy-piramide-4',
37 'only_matching': True,
38 }
39 ]
40
41 def _real_extract(self, url):
42 mobj = re.match(self._VALID_URL, url)
43 display_id = mobj.group('display_id')
44
45 webpage = self._download_webpage(url, display_id)
46
47 video_id = self._search_regex(
48 r'src="/vdl/player/media/(\d+)"', webpage, 'video id')
49
50 player = self._download_webpage(
51 'http://news.sportbox.ru/vdl/player/media/%s' % video_id,
52 display_id, 'Downloading player webpage')
53
54 hls = self._search_regex(
55 r"var\s+original_hls_file\s*=\s*'([^']+)'", player, 'hls file')
56
57 formats = self._extract_m3u8_formats(hls, display_id, 'mp4')
58
59 title = self._html_search_regex(
60 r'<h1 itemprop="name">([^<]+)</h1>', webpage, 'title')
61 description = self._html_search_regex(
62 r'(?s)<div itemprop="description">(.+?)</div>', webpage, 'description', fatal=False)
63 thumbnail = self._og_search_thumbnail(webpage)
64 timestamp = parse_iso8601(self._search_regex(
65 r'<span itemprop="uploadDate">([^<]+)</span>', webpage, 'timestamp', fatal=False))
66 duration = parse_duration(self._html_search_regex(
67 r'<meta itemprop="duration" content="PT([^"]+)">', webpage, 'duration', fatal=False))
68 view_count = int_or_none(self._html_search_regex(
69 r'<span>Просмотров: (\d+)</span>', player, 'view count', fatal=False))
70
71 return {
72 'id': video_id,
73 'display_id': display_id,
74 'title': title,
75 'description': description,
76 'thumbnail': thumbnail,
77 'timestamp': timestamp,
78 'duration': duration,
79 'view_count': view_count,
80 'formats': formats,
81 }