3 from .common
import InfoExtractor
16 class NovaEmbedIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://media\.cms\.nova\.cz/embed/(?P<id>[^/?#&]+)'
19 'url': 'https://media.cms.nova.cz/embed/8o0n0r?autoplay=1',
23 'thumbnail': r
're:^https?://.*\.jpg',
27 'skip_download': True,
28 'ignore_no_formats_error': True,
30 'expected_warnings': ['DRM protected', 'Requested format is not available'],
32 'url': 'https://media.cms.nova.cz/embed/KybpWYvcgOa',
36 'title': 'Borhyová oslavila 60? Soutěžící z pořadu odboural moderátora Ondřeje Sokola',
37 'thumbnail': r
're:^https?://.*\.jpg',
40 'params': {'skip_download': 'm3u8'}
,
43 def _real_extract(self
, url
):
44 video_id
= self
._match
_id
(url
)
46 webpage
= self
._download
_webpage
(url
, video_id
)
52 player
= self
._parse
_json
(
54 (r
'(?:(?:replacePlaceholders|processAdTagModifier).*?:\s*)?(?:replacePlaceholders|processAdTagModifier)\s*\(\s*(?P<json>{.*?})\s*\)(?:\s*\))?\s*,',
55 r
'Player\.init\s*\([^,]+,(?P<cndn>\s*\w+\s*\?)?\s*(?P<json>{(?(cndn).+?|.+)})\s*(?(cndn):|,\s*{.+?}\s*\)\s*;)'),
56 webpage
, 'player', default
='{}', group
='json'), video_id
, fatal
=False)
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):
64 if (not self
.get_param('allow_unplayable_formats')
65 and traverse_obj(format_dict
, ('drm', 'keySystem'))):
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
_m
3u8_formats
(
74 format_url
, video_id
, 'mp4',
75 entry_protocol
='m3u8_native', m3u8_id
='hls',
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))
85 duration
= int_or_none(player
.get('duration'))
87 # Old path, not actual as of 08.04.2020
88 bitrates
= self
._parse
_json
(
90 r
'(?s)(?:src|bitrates)\s*=\s*({.+?})\s*;', webpage
, 'formats'),
91 video_id
, transform_source
=js_to_json
)
93 QUALITIES
= ('lq', 'mq', 'hq', 'hd')
94 quality_key
= qualities(QUALITIES
)
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
)
103 if format_id
== 'hls':
104 formats
.extend(self
._extract
_m
3u8_formats
(
105 format_url
, video_id
, ext
='mp4',
106 entry_protocol
='m3u8_native', m3u8_id
='hls',
113 for quality
in QUALITIES
:
114 if '%s.mp4' % quality
in format_url
:
115 f_id
+= '-%s' % quality
117 'quality': quality_key(quality
),
118 'format_note': quality
.upper(),
121 f
['format_id'] = f_id
124 if not formats
and has_drm
:
125 self
.report_drm(video_id
)
126 self
._sort
_formats
(formats
)
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(
138 r'videoDuration\s*:\s*(\d+)', webpage, 'duration',
144 'thumbnail': thumbnail,
145 'duration': duration,
150 class NovaIE(InfoExtractor):
151 IE_DESC = 'TN.cz, Prásk.tv, Nova.cz, Novaplus.cz, FANDA.tv, Krásná.cz and Doma.cz'
152 _VALID_URL = r'https?://(?:[^.]+\.)?(?P<site>tv(?:noviny)?|tn|novaplus|vymena|fanda|krasna|doma|prask)\.nova\.cz/(?:[^/]+/)+(?P<id>[^/]+?)(?:\.html|/|$)'
154 'url': 'http://tn.nova.cz/clanek/tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci.html#player_13260',
155 'md5': '249baab7d0104e186e78b0899c7d5f28',
158 'display_id': 'tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci',
160 'title': 'Podzemní nemocnice v pražské Krči',
161 'description': 'md5:f0a42dd239c26f61c28f19e62d20ef53',
162 'thumbnail': r're:^https?://.*\.(?:jpg)',
165 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
169 'title': 'Zaklínač 3: Divoký hon',
170 'description': 're:.*Pokud se stejně jako my nemůžete.*',
171 'thumbnail': r're:https?://.*\.jpg(\?.*)?',
172 'upload_date': '20150521',
176 'skip_download': True,
180 # media.cms.nova.cz embed
181 'url': 'https://novaplus.nova.cz/porad/ulice/epizoda/18760-2180-dil',
185 'title': '2180. díl',
186 'thumbnail': r're:^https?://.*\.jpg',
190 'skip_download': True,
192 'add_ie': [NovaEmbedIE.ie_key()],
193 'skip': 'CHYBA 404: STRÁNKA NENALEZENA',
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,
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,
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,
204 'url': 'http://prask.nova.cz/clanek/novinky/co-si-na-sobe-nase-hvezdy-nechaly-pojistit.html',
205 'only_matching': True,
207 'url': 'http://tv.nova.cz/clanek/novinky/zivot-je-zivot-bondovsky-trailer.html',
208 'only_matching': True,
211 def _real_extract(self, url):
212 mobj = self._match_valid_url(url)
213 display_id = mobj.group('id')
214 site = mobj.group('site')
216 webpage = self._download_webpage(url, display_id)
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))
229 embed_id = self._search_regex(
230 r'<iframe[^>]+\bsrc=["\'](?
:https?
:)?
//media\
.cms\
.nova\
.cz
/embed
/([^
/?
#&]+)',
231 webpage
, 'embed url', default
=None)
234 '_type': 'url_transparent',
235 'url': 'https://media.cms.nova.cz/embed/%s' % embed_id
,
236 'ie_key': NovaEmbedIE
.ie_key(),
238 'description': description
,
239 'upload_date': upload_date
242 video_id
= self
._search
_regex
(
243 [r
"(?:media|video_id)\s*:\s*'(\d+)'",
245 r
'id="article_video_(\d+)"',
246 r
'id="player_(\d+)"'],
249 config_url
= self
._search
_regex
(
250 r
'src="(https?://(?:tn|api)\.nova\.cz/bin/player/videojs/config\.php\?[^"]+)"',
251 webpage
, 'config url', default
=None)
255 player
= self
._parse
_json
(
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)
261 config_url
= url_or_none(player
.get('configUrl'))
262 params
= player
.get('configParams')
263 if isinstance(params
, dict):
264 config_params
= params
267 DEFAULT_SITE_ID
= '23000'
269 'tvnoviny': DEFAULT_SITE_ID
,
270 'novaplus': DEFAULT_SITE_ID
,
271 'vymena': DEFAULT_SITE_ID
,
272 'krasna': DEFAULT_SITE_ID
,
278 site_id
= self
._search
_regex
(
279 r
'site=(\d+)', webpage
, 'site id', default
=None) or SITES
.get(
280 site
, DEFAULT_SITE_ID
)
282 config_url
= 'https://api.nova.cz/bin/player/videojs/config.php'
290 config
= self
._download
_json
(
291 config_url
, display_id
,
292 'Downloading config JSON', query
=config_params
,
293 transform_source
=lambda s
: s
[s
.index('{'):s.rindex('}') + 1])
295 mediafile
= config
['mediafile']
296 video_url
= mediafile
['src']
298 m
= re
.search(r
'^(?P<url>rtmpe?://[^/]+/(?P<app>[^/]+?))/&*(?P<playpath>.+)$', video_url
)
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',
311 self
._sort
_formats
(formats
)
313 title
= mediafile
.get('meta', {}).get('title') or self
._og
_search
_title
(webpage
)
314 thumbnail
= config
.get('poster')
318 'display_id': display_id
,
320 'description': description
,
321 'upload_date': upload_date
,
322 'thumbnail': thumbnail
,