2 from __future__ import unicode_literals
6 from .common import InfoExtractor
17 class NovaEmbedIE(InfoExtractor):
18 _VALID_URL = r'https?://media\.cms\.nova\.cz/embed/(?P<id>[^/?#&]+)'
20 'url': 'https://media.cms.nova.cz/embed/8o0n0r?autoplay=1',
21 'md5': 'ee009bafcc794541570edd44b71cbea3',
26 'thumbnail': r're:^https?://.*\.jpg',
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
34 webpage = self._download_webpage(url, video_id)
36 bitrates = self._parse_json(
38 r'(?s)(?:src|bitrates)\s*=\s*({.+?})\s*;', webpage, 'formats'),
39 video_id, transform_source=js_to_json)
41 QUALITIES = ('lq', 'mq', 'hq', 'hd')
42 quality_key = qualities(QUALITIES)
45 for format_id, format_list in bitrates.items():
46 if not isinstance(format_list, list):
47 format_list = [format_list]
48 for format_url in format_list:
49 format_url = url_or_none(format_url)
52 if format_id == 'hls':
53 formats.extend(self._extract_m3u8_formats(
54 format_url, video_id, ext='mp4',
55 entry_protocol='m3u8_native', m3u8_id='hls',
62 for quality in QUALITIES:
63 if '%s.mp4' % quality in format_url:
64 f_id += '-%s' % quality
66 'quality': quality_key(quality),
67 'format_note': quality.upper(),
72 self._sort_formats(formats)
74 title = self._og_search_title(
75 webpage, default=None) or self._search_regex(
76 (r'<value>(?P<title>[^<]+)',
77 r'videoTitle\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1'), webpage,
78 'title', group='value')
79 thumbnail = self._og_search_thumbnail(
80 webpage, default=None) or self._search_regex(
81 r'poster\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1', webpage,
82 'thumbnail', fatal=False, group='value')
83 duration = int_or_none(self._search_regex(
84 r'videoDuration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
89 'thumbnail': thumbnail,
95 class NovaIE(InfoExtractor):
96 IE_DESC = 'TN.cz, Prásk.tv, Nova.cz, Novaplus.cz, FANDA.tv, Krásná.cz and Doma.cz'
97 _VALID_URL = r'https?://(?:[^.]+\.)?(?P<site>tv(?:noviny)?|tn|novaplus|vymena|fanda|krasna|doma|prask)\.nova\.cz/(?:[^/]+/)+(?P<id>[^/]+?)(?:\.html|/|$)'
99 'url': 'http://tn.nova.cz/clanek/tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci.html#player_13260',
100 'md5': '249baab7d0104e186e78b0899c7d5f28',
103 'display_id': 'tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci',
105 'title': 'Podzemní nemocnice v pražské Krči',
106 'description': 'md5:f0a42dd239c26f61c28f19e62d20ef53',
107 'thumbnail': r're:^https?://.*\.(?:jpg)',
110 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
114 'title': 'Zaklínač 3: Divoký hon',
115 'description': 're:.*Pokud se stejně jako my nemůžete.*',
116 'thumbnail': r're:https?://.*\.jpg(\?.*)?',
117 'upload_date': '20150521',
121 'skip_download': True,
125 # media.cms.nova.cz embed
126 'url': 'https://novaplus.nova.cz/porad/ulice/epizoda/18760-2180-dil',
130 'title': '2180. díl',
131 'thumbnail': r're:^https?://.*\.jpg',
135 'skip_download': True,
137 'add_ie': [NovaEmbedIE.ie_key()],
138 'skip': 'CHYBA 404: STRÁNKA NENALEZENA',
140 'url': 'http://sport.tn.nova.cz/clanek/sport/hokej/nhl/zivot-jde-dal-hodnotil-po-vyrazeni-z-playoff-jiri-sekac.html',
141 'only_matching': True,
143 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
144 'only_matching': True,
146 'url': 'http://doma.nova.cz/clanek/zdravi/prijdte-se-zapsat-do-registru-kostni-drene-jiz-ve-stredu-3-cervna.html',
147 'only_matching': True,
149 'url': 'http://prask.nova.cz/clanek/novinky/co-si-na-sobe-nase-hvezdy-nechaly-pojistit.html',
150 'only_matching': True,
152 'url': 'http://tv.nova.cz/clanek/novinky/zivot-je-zivot-bondovsky-trailer.html',
153 'only_matching': True,
156 def _real_extract(self, url):
157 mobj = re.match(self._VALID_URL, url)
158 display_id = mobj.group('id')
159 site = mobj.group('site')
161 webpage = self._download_webpage(url, display_id)
163 description = clean_html(self._og_search_description(webpage, default=None))
164 if site == 'novaplus':
165 upload_date = unified_strdate(self._search_regex(
166 r'(\d{1,2}-\d{1,2}-\d{4})$', display_id, 'upload date', default=None))
167 elif site == 'fanda':
168 upload_date = unified_strdate(self._search_regex(
169 r'<span class="date_time">(\d{1,2}\.\d{1,2}\.\d{4})', webpage, 'upload date', default=None))
174 embed_id = self._search_regex(
175 r'<iframe[^>]+\bsrc=["\'](?:https?:)?//media\.cms\.nova\.cz/embed/([^/?#&]+)',
176 webpage, 'embed url', default=None)
179 '_type': 'url_transparent',
180 'url': 'https://media.cms.nova.cz/embed/%s' % embed_id,
181 'ie_key': NovaEmbedIE.ie_key(),
183 'description': description,
184 'upload_date': upload_date
187 video_id = self._search_regex(
188 [r"(?:media|video_id)\s*:\s*'(\d+)'",
190 r'id="article_video_(\d+)"',
191 r'id="player_(\d+)"'],
194 config_url = self._search_regex(
195 r'src="(https?://(?:tn|api)\.nova\.cz/bin/player/videojs/config\.php\?[^"]+)"',
196 webpage, 'config url', default=None)
200 player = self._parse_json(
202 r'(?s)Player\s*\(.+?\s*,\s*({.+?\bmedia\b["\']?\s*:\s*["\']?\d+.+?})\s*\)', webpage,
203 'player', default='{}'),
204 video_id, transform_source=js_to_json, fatal=False)
206 config_url = url_or_none(player.get('configUrl'))
207 params = player.get('configParams')
208 if isinstance(params, dict):
209 config_params = params
212 DEFAULT_SITE_ID = '23000'
214 'tvnoviny': DEFAULT_SITE_ID,
215 'novaplus': DEFAULT_SITE_ID,
216 'vymena': DEFAULT_SITE_ID,
217 'krasna': DEFAULT_SITE_ID,
223 site_id = self._search_regex(
224 r'site=(\d+)', webpage, 'site id', default=None) or SITES.get(
225 site, DEFAULT_SITE_ID)
227 config_url = 'https://api.nova.cz/bin/player/videojs/config.php'
235 config = self._download_json(
236 config_url, display_id,
237 'Downloading config JSON', query=config_params,
238 transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
240 mediafile = config['mediafile']
241 video_url = mediafile['src']
243 m = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>[^/]+?))/&*(?P<playpath>.+)$', video_url)
246 'url': m.group('url'),
247 'app': m.group('app'),
248 'play_path': m.group('playpath'),
249 'player_path': 'http://tvnoviny.nova.cz/static/shared/app/videojs/video-js.swf',
256 self._sort_formats(formats)
258 title = mediafile.get('meta', {}).get('title') or self._og_search_title(webpage)
259 thumbnail = config.get('poster')
263 'display_id': display_id,
265 'description': description,
266 'upload_date': upload_date,
267 'thumbnail': thumbnail,