]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/nova.py
[youtube] De-prioritize auto-generated thumbnails
[yt-dlp.git] / yt_dlp / extractor / nova.py
CommitLineData
923e79e2
S
1import re
2
3from .common import InfoExtractor
4b5fe134
SS
4from ..utils import (
5 clean_html,
5caf88cc 6 determine_ext,
c707d206 7 int_or_none,
d6ef8b4d 8 js_to_json,
c707d206 9 qualities,
c1dc0ee5 10 traverse_obj,
4b5fe134 11 unified_strdate,
d6ef8b4d 12 url_or_none,
4b5fe134 13)
923e79e2
S
14
15
c707d206
S
16class NovaEmbedIE(InfoExtractor):
17 _VALID_URL = r'https?://media\.cms\.nova\.cz/embed/(?P<id>[^/?#&]+)'
c1dc0ee5 18 _TESTS = [{
c707d206 19 'url': 'https://media.cms.nova.cz/embed/8o0n0r?autoplay=1',
c707d206
S
20 'info_dict': {
21 'id': '8o0n0r',
c707d206
S
22 'title': '2180. díl',
23 'thumbnail': r're:^https?://.*\.jpg',
24 'duration': 2578,
25 },
c1dc0ee5 26 'params': {
27 'skip_download': True,
28 'ignore_no_formats_error': True,
29 },
30 'expected_warnings': ['DRM protected', 'Requested format is not available'],
31 }, {
32 'url': 'https://media.cms.nova.cz/embed/KybpWYvcgOa',
33 'info_dict': {
34 'id': 'KybpWYvcgOa',
35 'ext': 'mp4',
36 'title': 'Borhyová oslavila 60? Soutěžící z pořadu odboural moderátora Ondřeje Sokola',
37 'thumbnail': r're:^https?://.*\.jpg',
38 'duration': 114,
39 },
40 'params': {'skip_download': 'm3u8'},
41 }]
c707d206
S
42
43 def _real_extract(self, url):
44 video_id = self._match_id(url)
45
46 webpage = self._download_webpage(url, video_id)
47
c1dc0ee5 48 has_drm = False
5caf88cc
S
49 duration = None
50 formats = []
51
52 player = self._parse_json(
c707d206 53 self._search_regex(
fe69f52e 54 (r'(?:(?:replacePlaceholders|processAdTagModifier).*?:\s*)?(?:replacePlaceholders|processAdTagModifier)\s*\(\s*(?P<json>{.*?})\s*\)(?:\s*\))?\s*,',
3c2208f8 55 r'Player\.init\s*\([^,]+,(?P<cndn>\s*\w+\s*\?)?\s*(?P<json>{(?(cndn).+?|.+)})\s*(?(cndn):|,\s*{.+?}\s*\)\s*;)'),
c1dc0ee5 56 webpage, 'player', default='{}', group='json'), video_id, fatal=False)
5caf88cc
S
57 if player:
58 for format_id, format_list in player['tracks'].items():
59 if not isinstance(format_list, list):
60 format_list = [format_list]
61 for format_dict in format_list:
62 if not isinstance(format_dict, dict):
63 continue
c1dc0ee5 64 if (not self.get_param('allow_unplayable_formats')
65 and traverse_obj(format_dict, ('drm', 'keySystem'))):
66 has_drm = True
67 continue
5caf88cc
S
68 format_url = url_or_none(format_dict.get('src'))
69 format_type = format_dict.get('type')
70 ext = determine_ext(format_url)
71 if (format_type == 'application/x-mpegURL'
72 or format_id == 'HLS' or ext == 'm3u8'):
73 formats.extend(self._extract_m3u8_formats(
74 format_url, video_id, 'mp4',
75 entry_protocol='m3u8_native', m3u8_id='hls',
76 fatal=False))
77 elif (format_type == 'application/dash+xml'
78 or format_id == 'DASH' or ext == 'mpd'):
79 formats.extend(self._extract_mpd_formats(
80 format_url, video_id, mpd_id='dash', fatal=False))
81 else:
82 formats.append({
83 'url': format_url,
84 })
85 duration = int_or_none(player.get('duration'))
86 else:
87 # Old path, not actual as of 08.04.2020
88 bitrates = self._parse_json(
89 self._search_regex(
90 r'(?s)(?:src|bitrates)\s*=\s*({.+?})\s*;', webpage, 'formats'),
91 video_id, transform_source=js_to_json)
c707d206 92
5caf88cc
S
93 QUALITIES = ('lq', 'mq', 'hq', 'hd')
94 quality_key = qualities(QUALITIES)
95
96 for format_id, format_list in bitrates.items():
97 if not isinstance(format_list, list):
98 format_list = [format_list]
99 for format_url in format_list:
100 format_url = url_or_none(format_url)
101 if not format_url:
102 continue
103 if format_id == 'hls':
104 formats.extend(self._extract_m3u8_formats(
105 format_url, video_id, ext='mp4',
106 entry_protocol='m3u8_native', m3u8_id='hls',
107 fatal=False))
108 continue
109 f = {
110 'url': format_url,
111 }
112 f_id = format_id
113 for quality in QUALITIES:
114 if '%s.mp4' % quality in format_url:
115 f_id += '-%s' % quality
116 f.update({
117 'quality': quality_key(quality),
118 'format_note': quality.upper(),
119 })
120 break
121 f['format_id'] = f_id
122 formats.append(f)
c707d206 123
c1dc0ee5 124 if not formats and has_drm:
125 self.report_drm(video_id)
c707d206
S
126 self._sort_formats(formats)
127
128 title = self._og_search_title(
129 webpage, default=None) or self._search_regex(
130 (r'<value>(?P<title>[^<]+)',
131 r'videoTitle\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1'), webpage,
132 'title', group='value')
133 thumbnail = self._og_search_thumbnail(
134 webpage, default=None) or self._search_regex(
135 r'poster\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1', webpage,
136 'thumbnail', fatal=False, group='value')
137 duration = int_or_none(self._search_regex(
5caf88cc
S
138 r'videoDuration\s*:\s*(\d+)', webpage, 'duration',
139 default=duration))
c707d206
S
140
141 return {
142 'id': video_id,
143 'title': title,
144 'thumbnail': thumbnail,
145 'duration': duration,
146 'formats': formats,
147 }
148
149
923e79e2
S
150class NovaIE(InfoExtractor):
151 IE_DESC = 'TN.cz, Prásk.tv, Nova.cz, Novaplus.cz, FANDA.tv, Krásná.cz and Doma.cz'
5886b38d 152 _VALID_URL = r'https?://(?:[^.]+\.)?(?P<site>tv(?:noviny)?|tn|novaplus|vymena|fanda|krasna|doma|prask)\.nova\.cz/(?:[^/]+/)+(?P<id>[^/]+?)(?:\.html|/|$)'
923e79e2 153 _TESTS = [{
08b7968e 154 'url': 'http://tn.nova.cz/clanek/tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci.html#player_13260',
06f1de2d 155 'md5': '249baab7d0104e186e78b0899c7d5f28',
923e79e2
S
156 'info_dict': {
157 'id': '1757139',
158 'display_id': 'tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci',
159 'ext': 'mp4',
160 'title': 'Podzemní nemocnice v pražské Krči',
161 'description': 'md5:f0a42dd239c26f61c28f19e62d20ef53',
ec85ded8 162 'thumbnail': r're:^https?://.*\.(?:jpg)',
923e79e2 163 }
fcb04bca
SS
164 }, {
165 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
166 'info_dict': {
167 'id': '1753621',
168 'ext': 'mp4',
169 'title': 'Zaklínač 3: Divoký hon',
170 'description': 're:.*Pokud se stejně jako my nemůžete.*',
ec85ded8 171 'thumbnail': r're:https?://.*\.jpg(\?.*)?',
fcb04bca
SS
172 'upload_date': '20150521',
173 },
174 'params': {
175 # rtmp download
176 'skip_download': True,
06f1de2d
S
177 },
178 'skip': 'gone',
c707d206
S
179 }, {
180 # media.cms.nova.cz embed
181 'url': 'https://novaplus.nova.cz/porad/ulice/epizoda/18760-2180-dil',
182 'info_dict': {
183 'id': '8o0n0r',
184 'ext': 'mp4',
185 'title': '2180. díl',
186 'thumbnail': r're:^https?://.*\.jpg',
187 'duration': 2578,
188 },
189 'params': {
190 'skip_download': True,
191 },
192 'add_ie': [NovaEmbedIE.ie_key()],
06f1de2d 193 'skip': 'CHYBA 404: STRÁNKA NENALEZENA',
923e79e2
S
194 }, {
195 'url': 'http://sport.tn.nova.cz/clanek/sport/hokej/nhl/zivot-jde-dal-hodnotil-po-vyrazeni-z-playoff-jiri-sekac.html',
196 'only_matching': True,
197 }, {
198 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
199 'only_matching': True,
200 }, {
201 'url': 'http://doma.nova.cz/clanek/zdravi/prijdte-se-zapsat-do-registru-kostni-drene-jiz-ve-stredu-3-cervna.html',
202 'only_matching': True,
203 }, {
204 'url': 'http://prask.nova.cz/clanek/novinky/co-si-na-sobe-nase-hvezdy-nechaly-pojistit.html',
205 'only_matching': True,
60158217
S
206 }, {
207 'url': 'http://tv.nova.cz/clanek/novinky/zivot-je-zivot-bondovsky-trailer.html',
208 'only_matching': True,
923e79e2
S
209 }]
210
211 def _real_extract(self, url):
5ad28e7f 212 mobj = self._match_valid_url(url)
923e79e2
S
213 display_id = mobj.group('id')
214 site = mobj.group('site')
215
216 webpage = self._download_webpage(url, display_id)
217
06f1de2d
S
218 description = clean_html(self._og_search_description(webpage, default=None))
219 if site == 'novaplus':
220 upload_date = unified_strdate(self._search_regex(
221 r'(\d{1,2}-\d{1,2}-\d{4})$', display_id, 'upload date', default=None))
222 elif site == 'fanda':
223 upload_date = unified_strdate(self._search_regex(
224 r'<span class="date_time">(\d{1,2}\.\d{1,2}\.\d{4})', webpage, 'upload date', default=None))
225 else:
226 upload_date = None
227
c707d206
S
228 # novaplus
229 embed_id = self._search_regex(
230 r'<iframe[^>]+\bsrc=["\'](?:https?:)?//media\.cms\.nova\.cz/embed/([^/?#&]+)',
231 webpage, 'embed url', default=None)
232 if embed_id:
06f1de2d
S
233 return {
234 '_type': 'url_transparent',
235 'url': 'https://media.cms.nova.cz/embed/%s' % embed_id,
236 'ie_key': NovaEmbedIE.ie_key(),
237 'id': embed_id,
238 'description': description,
239 'upload_date': upload_date
240 }
c707d206 241
923e79e2
S
242 video_id = self._search_regex(
243 [r"(?:media|video_id)\s*:\s*'(\d+)'",
244 r'media=(\d+)',
245 r'id="article_video_(\d+)"',
246 r'id="player_(\d+)"'],
247 webpage, 'video id')
248
249 config_url = self._search_regex(
d6ef8b4d 250 r'src="(https?://(?:tn|api)\.nova\.cz/bin/player/videojs/config\.php\?[^"]+)"',
923e79e2 251 webpage, 'config url', default=None)
d6ef8b4d
S
252 config_params = {}
253
254 if not config_url:
255 player = self._parse_json(
256 self._search_regex(
257 r'(?s)Player\s*\(.+?\s*,\s*({.+?\bmedia\b["\']?\s*:\s*["\']?\d+.+?})\s*\)', webpage,
258 'player', default='{}'),
259 video_id, transform_source=js_to_json, fatal=False)
260 if player:
261 config_url = url_or_none(player.get('configUrl'))
262 params = player.get('configParams')
263 if isinstance(params, dict):
264 config_params = params
923e79e2
S
265
266 if not config_url:
267 DEFAULT_SITE_ID = '23000'
268 SITES = {
269 'tvnoviny': DEFAULT_SITE_ID,
270 'novaplus': DEFAULT_SITE_ID,
271 'vymena': DEFAULT_SITE_ID,
272 'krasna': DEFAULT_SITE_ID,
273 'fanda': '30',
274 'tn': '30',
275 'doma': '30',
276 }
277
278 site_id = self._search_regex(
d6ef8b4d
S
279 r'site=(\d+)', webpage, 'site id', default=None) or SITES.get(
280 site, DEFAULT_SITE_ID)
923e79e2 281
d6ef8b4d
S
282 config_url = 'https://api.nova.cz/bin/player/videojs/config.php'
283 config_params = {
284 'site': site_id,
285 'media': video_id,
286 'quality': 3,
287 'version': 1,
288 }
923e79e2
S
289
290 config = self._download_json(
291 config_url, display_id,
d6ef8b4d 292 'Downloading config JSON', query=config_params,
a00234f1 293 transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
923e79e2
S
294
295 mediafile = config['mediafile']
296 video_url = mediafile['src']
e4ac7bb1
SS
297
298 m = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>[^/]+?))/&*(?P<playpath>.+)$', video_url)
299 if m:
300 formats = [{
301 'url': m.group('url'),
302 'app': m.group('app'),
303 'play_path': m.group('playpath'),
304 'player_path': 'http://tvnoviny.nova.cz/static/shared/app/videojs/video-js.swf',
305 'ext': 'flv',
306 }]
307 else:
308 formats = [{
309 'url': video_url,
310 }]
311 self._sort_formats(formats)
923e79e2
S
312
313 title = mediafile.get('meta', {}).get('title') or self._og_search_title(webpage)
923e79e2
S
314 thumbnail = config.get('poster')
315
316 return {
317 'id': video_id,
318 'display_id': display_id,
319 'title': title,
320 'description': description,
fcb04bca 321 'upload_date': upload_date,
923e79e2 322 'thumbnail': thumbnail,
e4ac7bb1 323 'formats': formats,
923e79e2 324 }