4 from .common
import InfoExtractor
5 from ..networking
import Request
15 'Safari': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
19 class CeskaTelevizeIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://(?:www\.)?ceskatelevize\.cz/(?:ivysilani|porady|zive)/(?:[^/?#&]+/)*(?P<id>[^/#?]+)'
22 'url': 'http://www.ceskatelevize.cz/ivysilani/10441294653-hyde-park-civilizace/215411058090502/bonus/20641-bonus-01-en',
24 'id': '61924494877028507',
26 'title': 'Bonus 01 - En - Hyde Park Civilizace',
27 'description': 'English Subtittles',
28 'thumbnail': r
're:^https?://.*\.jpg',
33 'skip_download': True,
37 'url': 'http://www.ceskatelevize.cz/zive/ct1/',
41 'title': r
'ČT1 - živé vysílání online',
42 'description': 'Sledujte živé vysílání kanálu ČT1 online. Vybírat si můžete i z dalších kanálů České televize na kterémkoli z vašich zařízení.',
47 'skip_download': True,
51 'url': 'http://www.ceskatelevize.cz/ivysilani/zive/ct4/',
52 'only_matching': True,
56 'title': r
're:^ČT Sport \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
59 # 'skip': 'Georestricted to Czech Republic',
61 'url': 'http://www.ceskatelevize.cz/ivysilani/embed/iFramePlayer.php?hash=d6a3e1370d2e4fa76296b90bad4dfc19673b641e&IDEC=217 562 22150/0004&channelID=1&width=100%25',
62 'only_matching': True,
64 # video with 18+ caution trailer
65 'url': 'http://www.ceskatelevize.cz/porady/10520528904-queer/215562210900007-bogotart/',
67 'id': '215562210900007-bogotart',
68 'title': 'Bogotart - Queer',
69 'description': 'Hlavní město Kolumbie v doprovodu queer umělců. Vroucí svět plný vášně, sebevědomí, ale i násilí a bolesti',
73 'id': '61924494877311053',
75 'title': 'Bogotart - Queer (Varování 18+)',
80 'id': '61924494877068022',
82 'title': 'Bogotart - Queer (Queer)',
83 'thumbnail': r
're:^https?://.*\.jpg',
89 'skip_download': True,
93 'url': 'http://www.ceskatelevize.cz/porady/10614999031-neviditelni/21251212048/',
94 'only_matching': True,
97 def _real_extract(self
, url
):
98 playlist_id
= self
._match
_id
(url
)
99 webpage
, urlh
= self
._download
_webpage
_handle
(url
, playlist_id
)
100 parsed_url
= urllib
.parse
.urlparse(urlh
.url
)
101 site_name
= self
._og
_search
_property
('site_name', webpage
, fatal
=False, default
='Česká televize')
102 playlist_title
= self
._og
_search
_title
(webpage
, default
=None)
103 if site_name
and playlist_title
:
104 playlist_title
= re
.split(rf
'\s*[—|]\s*{site_name}', playlist_title
, maxsplit
=1)[0]
105 playlist_description
= self
._og
_search
_description
(webpage
, default
=None)
106 if playlist_description
:
107 playlist_description
= playlist_description
.replace('\xa0', ' ')
110 if re
.search(r
'(^/porady|/zive)/', parsed_url
.path
):
111 next_data
= self
._search
_nextjs
_data
(webpage
, playlist_id
)
112 if '/zive/' in parsed_url
.path
:
113 idec
= traverse_obj(next_data
, ('props', 'pageProps', 'data', 'liveBroadcast', 'current', 'idec'), get_all
=False)
115 idec
= traverse_obj(next_data
, ('props', 'pageProps', 'data', ('show', 'mediaMeta'), 'idec'), get_all
=False)
117 idec
= traverse_obj(next_data
, ('props', 'pageProps', 'data', 'videobonusDetail', 'bonusId'), get_all
=False)
121 raise ExtractorError('Failed to find IDEC id')
122 iframe_hash
= self
._download
_webpage
(
123 'https://www.ceskatelevize.cz/v-api/iframe-hash/',
124 playlist_id
, note
='Getting IFRAME hash')
125 query
= {'hash': iframe_hash
, 'origin': 'iVysilani', 'autoStart': 'true', type_
: idec
}
126 webpage
= self
._download
_webpage
(
127 'https://www.ceskatelevize.cz/ivysilani/embed/iFramePlayer.php',
128 playlist_id
, note
='Downloading player', query
=query
)
130 NOT_AVAILABLE_STRING
= 'This content is not available at your territory due to limited copyright.'
131 if f
'{NOT_AVAILABLE_STRING}</p>' in webpage
:
132 self
.raise_geo_restricted(NOT_AVAILABLE_STRING
)
133 if any(not_found
in webpage
for not_found
in ('Neplatný parametr pro videopřehrávač', 'IDEC nebyl nalezen')):
134 raise ExtractorError('no video with IDEC available', video_id
=idec
, expected
=True)
139 playlist
= self
._parse
_json
(
141 r
'getPlaylistUrl\(\[({.+?})\]', webpage
, 'playlist',
142 default
='{}'), playlist_id
)
144 type_
= playlist
.get('type')
145 episode_id
= playlist
.get('id')
148 type_
= self
._html
_search
_regex
(
149 r
'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],',
152 episode_id
= self
._html
_search
_regex
(
153 r
'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],',
154 webpage
, 'episode_id')
157 'playlist[0][type]': type_
,
158 'playlist[0][id]': episode_id
,
159 'requestUrl': parsed_url
.path
,
160 'requestSource': 'iVysilani',
165 for user_agent
in (None, USER_AGENTS
['Safari']):
167 'https://www.ceskatelevize.cz/ivysilani/ajax/get-client-playlist/',
168 data
=urlencode_postdata(data
))
170 req
.headers
['Content-type'] = 'application/x-www-form-urlencoded'
171 req
.headers
['x-addr'] = '127.0.0.1'
172 req
.headers
['X-Requested-With'] = 'XMLHttpRequest'
174 req
.headers
['User-Agent'] = user_agent
175 req
.headers
['Referer'] = url
177 playlistpage
= self
._download
_json
(req
, playlist_id
, fatal
=False)
182 playlist_url
= playlistpage
['url']
183 if playlist_url
== 'error_region':
184 raise ExtractorError(NOT_AVAILABLE_STRING
, expected
=True)
186 req
= Request(urllib
.parse
.unquote(playlist_url
))
187 req
.headers
['Referer'] = url
189 playlist
= self
._download
_json
(req
, playlist_id
, fatal
=False)
193 playlist
= playlist
.get('playlist')
194 if not isinstance(playlist
, list):
197 playlist_len
= len(playlist
)
199 for num
, item
in enumerate(playlist
):
200 is_live
= item
.get('type') == 'LIVE'
202 for format_id
, stream_url
in item
.get('streamUrls', {}).items():
203 if 'playerType=flash' in stream_url
:
204 stream_formats
= self
._extract
_m
3u8_formats
(
205 stream_url
, playlist_id
, 'mp4', 'm3u8_native',
206 m3u8_id
=f
'hls-{format_id}', fatal
=False)
208 stream_formats
= self
._extract
_mpd
_formats
(
209 stream_url
, playlist_id
,
210 mpd_id
=f
'dash-{format_id}', fatal
=False)
211 if 'drmOnly=true' in stream_url
:
212 for f
in stream_formats
:
214 # See https://github.com/ytdl-org/youtube-dl/issues/12119#issuecomment-280037031
215 if format_id
== 'audioDescription':
216 for f
in stream_formats
:
217 f
['source_preference'] = -10
218 formats
.extend(stream_formats
)
220 if user_agent
and len(entries
) == playlist_len
:
221 entries
[num
]['formats'].extend(formats
)
224 item_id
= str_or_none(item
.get('id') or item
['assetId'])
225 title
= item
['title']
227 duration
= float_or_none(item
.get('duration'))
228 thumbnail
= item
.get('previewImageUrl')
231 if item
.get('type') == 'VOD':
232 subs
= item
.get('subtitles')
234 subtitles
= self
.extract_subtitles(episode_id
, subs
)
236 if playlist_len
== 1:
237 final_title
= playlist_title
or title
239 final_title
= f
'{playlist_title} ({title})'
243 'title': final_title
,
244 'description': playlist_description
if playlist_len
== 1 else None,
245 'thumbnail': thumbnail
,
246 'duration': duration
,
248 'subtitles': subtitles
,
252 if len(entries
) == 1:
254 return self
.playlist_result(entries
, playlist_id
, playlist_title
, playlist_description
)
256 def _get_subtitles(self
, episode_id
, subs
):
257 original_subtitles
= self
._download
_webpage
(
258 subs
[0]['url'], episode_id
, 'Downloading subtitles')
259 srt_subs
= self
._fix
_subtitles
(original_subtitles
)
268 def _fix_subtitles(subtitles
):
269 """ Convert millisecond-based subtitles to SRT """
271 def _msectotimecode(msec
):
272 """ Helper utility to convert milliseconds to timecode """
274 for divider
in [1000, 60, 60, 100]:
275 components
.append(msec
% divider
)
277 return '{3:02}:{2:02}:{1:02},{0:03}'.format(*components
)
279 def _fix_subtitle(subtitle
):
280 for line
in subtitle
.splitlines():
281 m
= re
.match(r
'^\s*([0-9]+);\s*([0-9]+)\s+([0-9]+)\s*$', line
)
284 start
, stop
= (_msectotimecode(int(t
)) for t
in m
.groups()[1:])
285 yield f
'{start} --> {stop}'
289 return '\r\n'.join(_fix_subtitle(subtitles
))