2014-03-01 19:47:52 +09:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2014-12-13 20:24:42 +09:00
|
|
|
from ..compat import (
|
2014-03-01 19:47:52 +09:00
|
|
|
compat_urllib_request,
|
|
|
|
compat_urllib_parse,
|
2014-03-02 00:17:29 +09:00
|
|
|
compat_urllib_parse_urlparse,
|
2014-12-13 20:24:42 +09:00
|
|
|
)
|
|
|
|
from ..utils import (
|
2014-03-02 00:17:29 +09:00
|
|
|
ExtractorError,
|
2015-01-01 23:01:55 +09:00
|
|
|
float_or_none,
|
2014-03-01 19:47:52 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class CeskaTelevizeIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://www\.ceskatelevize\.cz/(porady|ivysilani)/(.+/)?(?P<id>[^?#]+)'
|
|
|
|
|
2014-03-02 00:54:37 +09:00
|
|
|
_TESTS = [
|
|
|
|
{
|
2015-01-01 23:01:55 +09:00
|
|
|
'url': 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220',
|
2014-03-02 00:54:37 +09:00
|
|
|
'info_dict': {
|
2015-01-01 23:01:55 +09:00
|
|
|
'id': '214411058091220',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Hyde Park Civilizace',
|
|
|
|
'description': 'Věda a současná civilizace. Interaktivní pořad - prostor pro vaše otázky a komentáře',
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
|
|
|
'duration': 3350,
|
2014-03-02 00:54:37 +09:00
|
|
|
},
|
|
|
|
'params': {
|
2015-01-01 23:01:55 +09:00
|
|
|
# m3u8 download
|
|
|
|
'skip_download': True,
|
2014-03-02 00:54:37 +09:00
|
|
|
},
|
2014-03-01 19:47:52 +09:00
|
|
|
},
|
2014-03-02 00:54:37 +09:00
|
|
|
{
|
|
|
|
'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/bonus/14716-zpevacka-z-duparny-bobina',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '14716',
|
2015-01-01 23:01:55 +09:00
|
|
|
'ext': 'mp4',
|
2014-03-02 00:54:37 +09:00
|
|
|
'title': 'První republika: Zpěvačka z Dupárny Bobina',
|
2015-01-01 23:01:55 +09:00
|
|
|
'description': 'Sága mapující atmosféru první republiky od r. 1918 do r. 1945.',
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
|
|
|
'duration': 88.4,
|
2014-03-02 00:54:37 +09:00
|
|
|
},
|
|
|
|
'params': {
|
2015-01-01 23:01:55 +09:00
|
|
|
# m3u8 download
|
|
|
|
'skip_download': True,
|
2014-03-02 00:54:37 +09:00
|
|
|
},
|
2014-03-01 19:47:52 +09:00
|
|
|
},
|
2014-03-02 00:54:37 +09:00
|
|
|
]
|
2014-03-01 19:47:52 +09:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
url = url.replace('/porady/', '/ivysilani/').replace('/video/', '')
|
|
|
|
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
video_id = mobj.group('id')
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
2014-03-02 00:54:37 +09:00
|
|
|
NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
|
|
|
|
if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
|
|
|
|
raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
|
2014-03-02 00:17:29 +09:00
|
|
|
|
2014-03-01 19:47:52 +09:00
|
|
|
typ = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],', webpage, 'type')
|
|
|
|
episode_id = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],', webpage, 'episode_id')
|
|
|
|
|
|
|
|
data = {
|
|
|
|
'playlist[0][type]': typ,
|
|
|
|
'playlist[0][id]': episode_id,
|
|
|
|
'requestUrl': compat_urllib_parse_urlparse(url).path,
|
|
|
|
'requestSource': 'iVysilani',
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:01:55 +09:00
|
|
|
req = compat_urllib_request.Request(
|
|
|
|
'http://www.ceskatelevize.cz/ivysilani/ajax/get-client-playlist',
|
|
|
|
data=compat_urllib_parse.urlencode(data))
|
2014-03-01 19:47:52 +09:00
|
|
|
|
|
|
|
req.add_header('Content-type', 'application/x-www-form-urlencoded')
|
|
|
|
req.add_header('x-addr', '127.0.0.1')
|
|
|
|
req.add_header('X-Requested-With', 'XMLHttpRequest')
|
|
|
|
req.add_header('Referer', url)
|
|
|
|
|
2014-03-02 01:05:33 +09:00
|
|
|
playlistpage = self._download_json(req, video_id)
|
2014-03-01 19:47:52 +09:00
|
|
|
|
2015-01-01 23:01:55 +09:00
|
|
|
playlist_url = playlistpage['url']
|
|
|
|
if playlist_url == 'error_region':
|
|
|
|
raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
|
|
|
|
|
|
|
|
req = compat_urllib_request.Request(compat_urllib_parse.unquote(playlist_url))
|
2014-03-01 19:47:52 +09:00
|
|
|
req.add_header('Referer', url)
|
|
|
|
|
2015-01-01 23:01:55 +09:00
|
|
|
playlist = self._download_json(req, video_id)
|
2014-11-24 04:41:03 +09:00
|
|
|
|
2015-01-01 23:01:55 +09:00
|
|
|
item = playlist['playlist'][0]
|
2014-03-01 19:47:52 +09:00
|
|
|
formats = []
|
2015-01-01 23:01:55 +09:00
|
|
|
for format_id, stream_url in item['streamUrls'].items():
|
|
|
|
formats.extend(self._extract_m3u8_formats(stream_url, video_id, 'mp4'))
|
2014-03-01 19:47:52 +09:00
|
|
|
self._sort_formats(formats)
|
|
|
|
|
2015-01-01 23:01:55 +09:00
|
|
|
title = self._og_search_title(webpage)
|
|
|
|
description = self._og_search_description(webpage)
|
|
|
|
duration = float_or_none(item.get('duration'))
|
|
|
|
thumbnail = item.get('previewImageUrl')
|
|
|
|
|
2014-03-01 19:47:52 +09:00
|
|
|
return {
|
|
|
|
'id': episode_id,
|
2015-01-01 23:01:55 +09:00
|
|
|
'title': title,
|
|
|
|
'description': description,
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'duration': duration,
|
2014-03-01 19:47:52 +09:00
|
|
|
'formats': formats,
|
|
|
|
}
|