]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nova.py
New upstream version 2020.03.24
[youtubedl] / youtube_dl / extractor / nova.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 clean_html,
9 int_or_none,
10 js_to_json,
11 qualities,
12 unified_strdate,
13 url_or_none,
14 )
15
16
17 class NovaEmbedIE(InfoExtractor):
18 _VALID_URL = r'https?://media\.cms\.nova\.cz/embed/(?P<id>[^/?#&]+)'
19 _TEST = {
20 'url': 'https://media.cms.nova.cz/embed/8o0n0r?autoplay=1',
21 'md5': 'ee009bafcc794541570edd44b71cbea3',
22 'info_dict': {
23 'id': '8o0n0r',
24 'ext': 'mp4',
25 'title': '2180. díl',
26 'thumbnail': r're:^https?://.*\.jpg',
27 'duration': 2578,
28 },
29 }
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33
34 webpage = self._download_webpage(url, video_id)
35
36 bitrates = self._parse_json(
37 self._search_regex(
38 r'(?s)(?:src|bitrates)\s*=\s*({.+?})\s*;', webpage, 'formats'),
39 video_id, transform_source=js_to_json)
40
41 QUALITIES = ('lq', 'mq', 'hq', 'hd')
42 quality_key = qualities(QUALITIES)
43
44 formats = []
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)
50 if not format_url:
51 continue
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',
56 fatal=False))
57 continue
58 f = {
59 'url': format_url,
60 }
61 f_id = format_id
62 for quality in QUALITIES:
63 if '%s.mp4' % quality in format_url:
64 f_id += '-%s' % quality
65 f.update({
66 'quality': quality_key(quality),
67 'format_note': quality.upper(),
68 })
69 break
70 f['format_id'] = f_id
71 formats.append(f)
72 self._sort_formats(formats)
73
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))
85
86 return {
87 'id': video_id,
88 'title': title,
89 'thumbnail': thumbnail,
90 'duration': duration,
91 'formats': formats,
92 }
93
94
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|/|$)'
98 _TESTS = [{
99 'url': 'http://tn.nova.cz/clanek/tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci.html#player_13260',
100 'md5': '249baab7d0104e186e78b0899c7d5f28',
101 'info_dict': {
102 'id': '1757139',
103 'display_id': 'tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci',
104 'ext': 'mp4',
105 'title': 'Podzemní nemocnice v pražské Krči',
106 'description': 'md5:f0a42dd239c26f61c28f19e62d20ef53',
107 'thumbnail': r're:^https?://.*\.(?:jpg)',
108 }
109 }, {
110 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
111 'info_dict': {
112 'id': '1753621',
113 'ext': 'mp4',
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',
118 },
119 'params': {
120 # rtmp download
121 'skip_download': True,
122 },
123 'skip': 'gone',
124 }, {
125 # media.cms.nova.cz embed
126 'url': 'https://novaplus.nova.cz/porad/ulice/epizoda/18760-2180-dil',
127 'info_dict': {
128 'id': '8o0n0r',
129 'ext': 'mp4',
130 'title': '2180. díl',
131 'thumbnail': r're:^https?://.*\.jpg',
132 'duration': 2578,
133 },
134 'params': {
135 'skip_download': True,
136 },
137 'add_ie': [NovaEmbedIE.ie_key()],
138 'skip': 'CHYBA 404: STRÁNKA NENALEZENA',
139 }, {
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,
142 }, {
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,
145 }, {
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,
148 }, {
149 'url': 'http://prask.nova.cz/clanek/novinky/co-si-na-sobe-nase-hvezdy-nechaly-pojistit.html',
150 'only_matching': True,
151 }, {
152 'url': 'http://tv.nova.cz/clanek/novinky/zivot-je-zivot-bondovsky-trailer.html',
153 'only_matching': True,
154 }]
155
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')
160
161 webpage = self._download_webpage(url, display_id)
162
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))
170 else:
171 upload_date = None
172
173 # novaplus
174 embed_id = self._search_regex(
175 r'<iframe[^>]+\bsrc=["\'](?:https?:)?//media\.cms\.nova\.cz/embed/([^/?#&]+)',
176 webpage, 'embed url', default=None)
177 if embed_id:
178 return {
179 '_type': 'url_transparent',
180 'url': 'https://media.cms.nova.cz/embed/%s' % embed_id,
181 'ie_key': NovaEmbedIE.ie_key(),
182 'id': embed_id,
183 'description': description,
184 'upload_date': upload_date
185 }
186
187 video_id = self._search_regex(
188 [r"(?:media|video_id)\s*:\s*'(\d+)'",
189 r'media=(\d+)',
190 r'id="article_video_(\d+)"',
191 r'id="player_(\d+)"'],
192 webpage, 'video id')
193
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)
197 config_params = {}
198
199 if not config_url:
200 player = self._parse_json(
201 self._search_regex(
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)
205 if player:
206 config_url = url_or_none(player.get('configUrl'))
207 params = player.get('configParams')
208 if isinstance(params, dict):
209 config_params = params
210
211 if not config_url:
212 DEFAULT_SITE_ID = '23000'
213 SITES = {
214 'tvnoviny': DEFAULT_SITE_ID,
215 'novaplus': DEFAULT_SITE_ID,
216 'vymena': DEFAULT_SITE_ID,
217 'krasna': DEFAULT_SITE_ID,
218 'fanda': '30',
219 'tn': '30',
220 'doma': '30',
221 }
222
223 site_id = self._search_regex(
224 r'site=(\d+)', webpage, 'site id', default=None) or SITES.get(
225 site, DEFAULT_SITE_ID)
226
227 config_url = 'https://api.nova.cz/bin/player/videojs/config.php'
228 config_params = {
229 'site': site_id,
230 'media': video_id,
231 'quality': 3,
232 'version': 1,
233 }
234
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])
239
240 mediafile = config['mediafile']
241 video_url = mediafile['src']
242
243 m = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>[^/]+?))/&*(?P<playpath>.+)$', video_url)
244 if m:
245 formats = [{
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',
250 'ext': 'flv',
251 }]
252 else:
253 formats = [{
254 'url': video_url,
255 }]
256 self._sort_formats(formats)
257
258 title = mediafile.get('meta', {}).get('title') or self._og_search_title(webpage)
259 thumbnail = config.get('poster')
260
261 return {
262 'id': video_id,
263 'display_id': display_id,
264 'title': title,
265 'description': description,
266 'upload_date': upload_date,
267 'thumbnail': thumbnail,
268 'formats': formats,
269 }