1 # -*- coding: utf-8 -*-
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
10 compat_urllib_parse_urlparse
,
17 class CeskaTelevizeIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://www\.ceskatelevize\.cz/(porady|ivysilani)/(.+/)?(?P<id>[^?#]+)'
22 'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/213512120230004-spanelska-chripka',
24 'id': '213512120230004',
26 'title': 'První republika: Španělská chřipka',
30 'skip_download': True, # requires rtmpdump
32 'skip': 'Works only from Czech Republic.',
35 'url': 'http://www.ceskatelevize.cz/ivysilani/1030584952-tsatsiki-maminka-a-policajt',
39 'title': 'Tsatsiki, maminka a policajt',
43 'skip_download': True, # requires rtmpdump
45 'skip': 'Works only from Czech Republic.',
48 'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/bonus/14716-zpevacka-z-duparny-bobina',
52 'title': 'První republika: Zpěvačka z Dupárny Bobina',
56 'skip_download': True, # requires rtmpdump
61 def _real_extract(self
, url
):
62 url
= url
.replace('/porady/', '/ivysilani/').replace('/video/', '')
64 mobj
= re
.match(self
._VALID
_URL
, url
)
65 video_id
= mobj
.group('id')
67 webpage
= self
._download
_webpage
(url
, video_id
)
69 NOT_AVAILABLE_STRING
= 'This content is not available at your territory due to limited copyright.'
70 if '%s</p>' % NOT_AVAILABLE_STRING
in webpage
:
71 raise ExtractorError(NOT_AVAILABLE_STRING
, expected
=True)
73 typ
= self
._html
_search
_regex
(r
'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],', webpage
, 'type')
74 episode_id
= self
._html
_search
_regex
(r
'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],', webpage
, 'episode_id')
77 'playlist[0][type]': typ
,
78 'playlist[0][id]': episode_id
,
79 'requestUrl': compat_urllib_parse_urlparse(url
).path
,
80 'requestSource': 'iVysilani',
83 req
= compat_urllib_request
.Request('http://www.ceskatelevize.cz/ivysilani/ajax/get-playlist-url',
84 data
=compat_urllib_parse
.urlencode(data
))
86 req
.add_header('Content-type', 'application/x-www-form-urlencoded')
87 req
.add_header('x-addr', '127.0.0.1')
88 req
.add_header('X-Requested-With', 'XMLHttpRequest')
89 req
.add_header('Referer', url
)
91 playlistpage
= self
._download
_json
(req
, video_id
)
93 req
= compat_urllib_request
.Request(compat_urllib_parse
.unquote(playlistpage
['url']))
94 req
.add_header('Referer', url
)
96 playlist
= self
._download
_xml
(req
, video_id
)
99 for i
in playlist
.find('smilRoot/body'):
100 if 'AD' not in i
.attrib
['id']:
101 base_url
= i
.attrib
['base']
102 parsedurl
= compat_urllib_parse_urlparse(base_url
)
103 duration
= i
.attrib
['duration']
105 for video
in i
.findall('video'):
106 if video
.attrib
['label'] != 'AD':
107 format_id
= video
.attrib
['label']
108 play_path
= video
.attrib
['src']
109 vbr
= int(video
.attrib
['system-bitrate'])
112 'format_id': format_id
,
115 'play_path': play_path
,
116 'app': parsedurl
.path
[1:] + '?' + parsedurl
.query
,
121 self
._sort
_formats
(formats
)
125 'title': self
._html
_search
_regex
(r
'<title>(.+?) — iVysílání — Česká televize</title>', webpage
, 'title'),
126 'duration': float(duration
),