]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/sportbox.py
Merge pull request #8061 from dstftw/introduce-chapter-and-series-fields
[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
3a738295 7from ..compat import compat_urlparse
fc6861b1 8from ..utils import (
77d9cb2f 9 unified_strdate,
fc6861b1
S
10)
11
12
13class SportBoxIE(InfoExtractor):
a7b8467a 14 _VALID_URL = r'https?://news\.sportbox\.ru/(?:[^/]+/)+spbvideo_NI\d+_(?P<display_id>.+)'
3a738295
S
15 _TESTS = [{
16 'url': 'http://news.sportbox.ru/Vidy_sporta/Avtosport/Rossijskij/spbvideo_NI483529_Gonka-2-zaezd-Obyedinenniy-2000-klassi-Turing-i-S',
17 'md5': 'ff56a598c2cf411a9a38a69709e97079',
18 'info_dict': {
19 'id': '80822',
20 'ext': 'mp4',
21 'title': 'Гонка 2 заезд ««Объединенный 2000»: классы Туринг и Супер-продакшн',
77d9cb2f 22 'description': 'md5:3d72dc4a006ab6805d82f037fdc637ad',
3a738295 23 'thumbnail': 're:^https?://.*\.jpg$',
3a738295 24 'upload_date': '20140928',
e9ca615a 25 },
3a738295
S
26 'params': {
27 # m3u8 download
28 'skip_download': True,
29 },
30 }, {
31 'url': 'http://news.sportbox.ru/Vidy_sporta/billiard/spbvideo_NI486287_CHempionat-mira-po-dinamichnoy-piramide-4',
32 'only_matching': True,
33 }, {
34 'url': 'http://news.sportbox.ru/video/no_ads/spbvideo_NI536574_V_Novorossijske_proshel_detskij_turnir_Pole_slavy_bojevoj?ci=211355',
35 'only_matching': True,
36 }]
fc6861b1
S
37
38 def _real_extract(self, url):
39 mobj = re.match(self._VALID_URL, url)
40 display_id = mobj.group('display_id')
41
42 webpage = self._download_webpage(url, display_id)
43
3a738295
S
44 player = self._search_regex(
45 r'src="/?(vdl/player/[^"]+)"', webpage, 'player')
fc6861b1
S
46
47 title = self._html_search_regex(
77d9cb2f
S
48 [r'"nodetitle"\s*:\s*"([^"]+)"', r'class="node-header_{1,2}title">([^<]+)'],
49 webpage, 'title')
50 description = self._og_search_description(webpage) or self._html_search_meta(
51 'description', webpage, 'description')
fc6861b1 52 thumbnail = self._og_search_thumbnail(webpage)
77d9cb2f
S
53 upload_date = unified_strdate(self._html_search_meta(
54 'dateCreated', webpage, 'upload date'))
fc6861b1
S
55
56 return {
3a738295
S
57 '_type': 'url_transparent',
58 'url': compat_urlparse.urljoin(url, '/%s' % player),
fc6861b1
S
59 'display_id': display_id,
60 'title': title,
61 'description': description,
62 'thumbnail': thumbnail,
77d9cb2f 63 'upload_date': upload_date,
3a738295
S
64 }
65
66
67class SportBoxEmbedIE(InfoExtractor):
68 _VALID_URL = r'https?://news\.sportbox\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)'
69 _TESTS = [{
70 'url': 'http://news.sportbox.ru/vdl/player/ci/211355',
71 'info_dict': {
72 'id': '211355',
73 'ext': 'mp4',
74 'title': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
75 'thumbnail': 're:^https?://.*\.jpg$',
76 },
77 'params': {
78 # m3u8 download
79 'skip_download': True,
80 },
81 }, {
82 'url': 'http://news.sportbox.ru/vdl/player?nid=370908&only_player=1&autostart=false&playeri=2&height=340&width=580',
83 'only_matching': True,
84 }]
85
1436a683
S
86 @staticmethod
87 def _extract_urls(webpage):
88 return re.findall(
89 r'<iframe[^>]+src="(https?://news\.sportbox\.ru/vdl/player[^"]+)"',
90 webpage)
91
3a738295
S
92 def _real_extract(self, url):
93 video_id = self._match_id(url)
94
95 webpage = self._download_webpage(url, video_id)
96
97 hls = self._search_regex(
98 r"sportboxPlayer\.jwplayer_common_params\.file\s*=\s*['\"]([^'\"]+)['\"]",
99 webpage, 'hls file')
100
101 formats = self._extract_m3u8_formats(hls, video_id, 'mp4')
102
103 title = self._search_regex(
104 r'sportboxPlayer\.node_title\s*=\s*"([^"]+)"', webpage, 'title')
105
106 thumbnail = self._search_regex(
107 r'sportboxPlayer\.jwplayer_common_params\.image\s*=\s*"([^"]+)"',
ef28a6cb 108 webpage, 'thumbnail', default=None)
3a738295
S
109
110 return {
111 'id': video_id,
112 'title': title,
113 'thumbnail': thumbnail,
fc6861b1
S
114 'formats': formats,
115 }