4 from .common
import InfoExtractor
14 class IPrimaIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?!cnn)(?:[^/]+)\.iprima\.cz/(?:[^/]+/)*(?P<id>[^/?#&]+)'
17 _NETRC_MACHINE
= 'iprima'
18 _LOGIN_URL
= 'https://auth.iprima.cz/oauth2/login'
19 _TOKEN_URL
= 'https://auth.iprima.cz/oauth2/token'
23 'url': 'https://prima.iprima.cz/particka/92-epizoda',
27 'title': 'Partička (92)',
28 'description': 'md5:859d53beae4609e6dd7796413f1b6cac',
29 'upload_date': '20201103',
30 'timestamp': 1604437480,
33 'skip_download': True, # m3u8 download
36 'url': 'http://play.iprima.cz/particka/particka-92',
37 'only_matching': True,
40 'url': 'http://play.iprima.cz/closer-nove-pripady/closer-nove-pripady-iv-1',
41 'only_matching': True,
43 'url': 'https://prima.iprima.cz/my-little-pony/mapa-znameni-2-2',
44 'only_matching': True,
46 'url': 'https://prima.iprima.cz/porady/jak-se-stavi-sen/rodina-rathousova-praha',
47 'only_matching': True,
49 'url': 'http://www.iprima.cz/filmy/desne-rande',
50 'only_matching': True,
52 'url': 'https://zoom.iprima.cz/10-nejvetsich-tajemstvi-zahad/posvatna-mista-a-stavby',
53 'only_matching': True,
55 'url': 'https://krimi.iprima.cz/mraz-0/sebevrazdy',
56 'only_matching': True,
58 'url': 'https://cool.iprima.cz/derava-silnice-nevadi',
59 'only_matching': True,
61 'url': 'https://love.iprima.cz/laska-az-za-hrob/slib-dany-bratrovi',
62 'only_matching': True,
65 def _perform_login(self
, username
, password
):
69 login_page
= self
._download
_webpage
(
70 self
._LOGIN
_URL
, None, note
='Downloading login page',
71 errnote
='Downloading login page failed')
73 login_form
= self
._hidden
_inputs
(login_page
)
77 '_password': password
})
79 _
, login_handle
= self
._download
_webpage
_handle
(
80 self
._LOGIN
_URL
, None, data
=urlencode_postdata(login_form
),
83 code
= parse_qs(login_handle
.geturl()).get('code')[0]
85 raise ExtractorError('Login failed', expected
=True)
87 token_request_data
= {
88 'scope': 'openid+email+profile+phone+address+offline_access',
89 'client_id': 'prima_sso',
90 'grant_type': 'authorization_code',
92 'redirect_uri': 'https://auth.iprima.cz/sso/auth-check'}
94 token_data
= self
._download
_json
(
95 self
._TOKEN
_URL
, None,
96 note
='Downloading token', errnote
='Downloading token failed',
97 data
=urlencode_postdata(token_request_data
))
99 self
.access_token
= token_data
.get('access_token')
100 if self
.access_token
is None:
101 raise ExtractorError('Getting token failed', expected
=True)
103 def _real_initialize(self
):
104 if not self
.access_token
:
105 self
.raise_login_required('Login is required to access any iPrima content', method
='password')
107 def _raise_access_error(self
, error_code
):
108 if error_code
== 'PLAY_GEOIP_DENIED':
109 self
.raise_geo_restricted(countries
=['CZ'], metadata_available
=True)
110 elif error_code
is not None:
111 self
.raise_no_formats('Access to stream infos forbidden', expected
=True)
113 def _real_extract(self
, url
):
114 video_id
= self
._match
_id
(url
)
116 webpage
= self
._download
_webpage
(url
, video_id
)
118 title
= self
._html
_search
_meta
(
119 ['og:title', 'twitter:title'],
120 webpage
, 'title', default
=None)
122 video_id
= self
._search
_regex
((
123 r
'productId\s*=\s*([\'"])(?P<id>p\d+)\1',
124 r'pproduct_id\s*=\s*([\'"])(?P
<id>p\d
+)\
1'),
125 webpage, 'real
id', group='id')
127 metadata = self._download_json(
128 f'https
://api
.play
-backend
.iprima
.cz
/api
/v1
//products
/id-{video_id}
/play
',
129 video_id, note='Getting manifest URLs
', errnote='Failed to get manifest URLs
',
130 headers={'X-OTT-Access-Token': self.access_token},
133 self._raise_access_error(metadata.get('errorCode
'))
135 stream_infos = metadata.get('streamInfos
')
137 if stream_infos is None:
138 self.raise_no_formats('Reading stream infos failed
', expected=True)
140 for manifest in stream_infos:
141 manifest_type = manifest.get('type')
142 manifest_url = manifest.get('url
')
143 ext = determine_ext(manifest_url)
144 if manifest_type == 'HLS
' or ext == 'm3u8
':
145 formats += self._extract_m3u8_formats(
146 manifest_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
147 m3u8_id='hls
', fatal=False)
148 elif manifest_type == 'DASH
' or ext == 'mpd
':
149 formats += self._extract_mpd_formats(
150 manifest_url, video_id, mpd_id='dash
', fatal=False)
151 self._sort_formats(formats)
153 final_result = self._search_json_ld(webpage, video_id) or {}
154 final_result.update({
157 'thumbnail
': self._html_search_meta(
158 ['thumbnail
', 'og
:image
', 'twitter
:image
'],
159 webpage, 'thumbnail
', default=None),
161 'description
': self._html_search_meta(
162 ['description
', 'og
:description
', 'twitter
:description
'],
163 webpage, 'description
', default=None)})
168 class IPrimaCNNIE(InfoExtractor):
169 _VALID_URL = r'https?
://cnn\
.iprima\
.cz
/(?
:[^
/]+/)*(?P
<id>[^
/?
#&]+)'
173 'url': 'https://cnn.iprima.cz/porady/strunc/24072020-koronaviru-mam-plne-zuby-strasit-druhou-vlnou-je-absurdni-rika-senatorka-dernerova',
177 'title': 'md5:277c6b1ed0577e51b40ddd35602ff43e',
180 'skip_download': 'm3u8'
184 def _real_extract(self
, url
):
185 video_id
= self
._match
_id
(url
)
187 self
._set
_cookie
('play.iprima.cz', 'ott_adult_confirmed', '1')
189 webpage
= self
._download
_webpage
(url
, video_id
)
191 title
= self
._og
_search
_title
(
192 webpage
, default
=None) or self
._search
_regex
(
193 r
'<h1>([^<]+)', webpage
, 'title')
195 video_id
= self
._search
_regex
(
196 (r
'<iframe[^>]+\bsrc=["\'](?
:https?
:)?
//(?
:api\
.play
-backend\
.iprima\
.cz
/prehravac
/embedded|prima\
.iprima\
.cz
/[^
/]+/[^
/]+)\?.*?
\bid
=(p\d
+)',
197 r'data
-product
="([^"]+)">',
198 r'id=["\']player
-(p\d
+)"',
199 r'playerId\s*:\s*["\']player
-(p\d
+)',
200 r'\bvideos\s
*=\s
*["\'](p\d+)'),
203 playerpage = self._download_webpage(
204 'http://play.iprima.cz/prehravac/init',
205 video_id, note='Downloading player', query={
207 '_ts': round(time.time()),
208 'productId': video_id,
209 }, headers={'Referer': url})
213 def extract_formats(format_url, format_key=None, lang=None):
214 ext = determine_ext(format_url)
216 if format_key == 'hls' or ext == 'm3u8':
217 new_formats = self._extract_m3u8_formats(
218 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
219 m3u8_id='hls', fatal=False)
220 elif format_key == 'dash' or ext == 'mpd':
222 new_formats = self._extract_mpd_formats(
223 format_url, video_id, mpd_id='dash', fatal=False)
225 for f in new_formats:
226 if not f.get('language'):
228 formats.extend(new_formats)
230 options = self._parse_json(
232 r'(?s)(?:TDIPlayerOptions|playerOptions)\s*=\s*({.+?});\s*\]\]',
233 playerpage, 'player options', default='{}'),
234 video_id, transform_source=js_to_json, fatal=False)
236 for key, tracks in options.get('tracks', {}).items():
237 if not isinstance(tracks, list):
240 src = track.get('src')
242 extract_formats(src, key.lower(), track.get('lang'))
245 for _, src in re.findall(r'src["\']\s
*:\s
*(["\'])(.+?)\1', playerpage):
248 if not formats and '>GEO_IP_NOT_ALLOWED<' in playerpage:
249 self.raise_geo_restricted(countries=['CZ'], metadata_available=True)
251 self._sort_formats(formats)
256 'thumbnail': self._og_search_thumbnail(webpage, default=None),
258 'description': self._og_search_description(webpage, default=None),