[ceskatelevize] Add support for live streams

Live streams has no playlist title, use title of the stream containing
TV channel name. Internal m3u8 handler doesn't seem to handle well
continuous streams. Add test for live stream. Remove no longer
reachable test.
This commit is contained in:
Tomáš Čech 2016-05-07 20:15:49 +02:00 committed by Sergey M․
parent eb785b856f
commit f1f6f5aa5e
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D
1 changed files with 25 additions and 10 deletions

View File

@ -33,14 +33,13 @@ class CeskaTelevizeIE(InfoExtractor):
'skip_download': True, 'skip_download': True,
}, },
}, { }, {
'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/bonus/14716-zpevacka-z-duparny-bobina', # live stream
'url': 'http://www.ceskatelevize.cz/ivysilani/zive/ct4/',
'info_dict': { 'info_dict': {
'id': '61924494876844374', 'id': 402,
'ext': 'mp4', 'ext': 'mp4',
'title': 'První republika: Zpěvačka z Dupárny Bobina', 'title': 're:ČT Sport.*',
'description': 'Sága mapující atmosféru první republiky od r. 1918 do r. 1945.', 'is_live': True,
'thumbnail': 're:^https?://.*\.jpg',
'duration': 88.4,
}, },
'params': { 'params': {
# m3u8 download # m3u8 download
@ -118,19 +117,21 @@ class CeskaTelevizeIE(InfoExtractor):
req = sanitized_Request(compat_urllib_parse_unquote(playlist_url)) req = sanitized_Request(compat_urllib_parse_unquote(playlist_url))
req.add_header('Referer', url) req.add_header('Referer', url)
playlist_title = self._og_search_title(webpage) playlist_title = self._og_search_title(webpage, default=None)
playlist_description = self._og_search_description(webpage) playlist_description = self._og_search_description(webpage, default=None)
playlist = self._download_json(req, playlist_id)['playlist'] playlist = self._download_json(req, playlist_id)['playlist']
playlist_len = len(playlist) playlist_len = len(playlist)
entries = [] entries = []
for item in playlist: for item in playlist:
is_live = item['type'] == 'LIVE'
formats = [] formats = []
for format_id, stream_url in item['streamUrls'].items(): for format_id, stream_url in item['streamUrls'].items():
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
stream_url, playlist_id, 'mp4', stream_url, playlist_id, 'mp4',
entry_protocol='m3u8_native', fatal=False)) entry_protocol='m3u8' if is_live else 'm3u8_native',
fatal=False))
self._sort_formats(formats) self._sort_formats(formats)
item_id = item.get('id') or item['assetId'] item_id = item.get('id') or item['assetId']
@ -145,14 +146,28 @@ class CeskaTelevizeIE(InfoExtractor):
if subs: if subs:
subtitles = self.extract_subtitles(episode_id, subs) subtitles = self.extract_subtitles(episode_id, subs)
if playlist_len == 1:
if is_live:
# live streams has channel name in title
final_title = self._live_title(title)
elif playlist_title:
# title is always set (no KeyError caught)
# and gives good fallback
final_title = title
else:
final_title = playlist_title
else:
final_title = '%s (%s)' % (playlist_title, title)
entries.append({ entries.append({
'id': item_id, 'id': item_id,
'title': playlist_title if playlist_len == 1 else '%s (%s)' % (playlist_title, title), 'title': final_title,
'description': playlist_description if playlist_len == 1 else None, 'description': playlist_description if playlist_len == 1 else None,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'duration': duration, 'duration': duration,
'formats': formats, 'formats': formats,
'subtitles': subtitles, 'subtitles': subtitles,
'is_live': is_live,
}) })
return self.playlist_result(entries, playlist_id, playlist_title, playlist_description) return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)