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