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