]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ceskatelevize.py
debian/changelog: Finalize release.
[youtubedl] / youtube_dl / extractor / ceskatelevize.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 compat_urllib_request,
9 compat_urllib_parse,
10 compat_urllib_parse_urlparse,
11 ExtractorError,
12 )
13
14
15 class CeskaTelevizeIE(InfoExtractor):
16 _VALID_URL = r'https?://www\.ceskatelevize\.cz/(porady|ivysilani)/(.+/)?(?P<id>[^?#]+)'
17
18 _TESTS = [
19 {
20 'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/213512120230004-spanelska-chripka',
21 'info_dict': {
22 'id': '213512120230004',
23 'ext': 'flv',
24 'title': 'První republika: Španělská chřipka',
25 'duration': 3107.4,
26 },
27 'params': {
28 'skip_download': True, # requires rtmpdump
29 },
30 'skip': 'Works only from Czech Republic.',
31 },
32 {
33 'url': 'http://www.ceskatelevize.cz/ivysilani/1030584952-tsatsiki-maminka-a-policajt',
34 'info_dict': {
35 'id': '20138143440',
36 'ext': 'flv',
37 'title': 'Tsatsiki, maminka a policajt',
38 'duration': 6754.1,
39 },
40 'params': {
41 'skip_download': True, # requires rtmpdump
42 },
43 'skip': 'Works only from Czech Republic.',
44 },
45 {
46 'url': 'http://www.ceskatelevize.cz/ivysilani/10532695142-prvni-republika/bonus/14716-zpevacka-z-duparny-bobina',
47 'info_dict': {
48 'id': '14716',
49 'ext': 'flv',
50 'title': 'První republika: Zpěvačka z Dupárny Bobina',
51 'duration': 90,
52 },
53 'params': {
54 'skip_download': True, # requires rtmpdump
55 },
56 },
57 ]
58
59 def _real_extract(self, url):
60 url = url.replace('/porady/', '/ivysilani/').replace('/video/', '')
61
62 mobj = re.match(self._VALID_URL, url)
63 video_id = mobj.group('id')
64
65 webpage = self._download_webpage(url, video_id)
66
67 NOT_AVAILABLE_STRING = 'This content is not available at your territory due to limited copyright.'
68 if '%s</p>' % NOT_AVAILABLE_STRING in webpage:
69 raise ExtractorError(NOT_AVAILABLE_STRING, expected=True)
70
71 typ = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":"(.+?)","id":".+?"\}\],', webpage, 'type')
72 episode_id = self._html_search_regex(r'getPlaylistUrl\(\[\{"type":".+?","id":"(.+?)"\}\],', webpage, 'episode_id')
73
74 data = {
75 'playlist[0][type]': typ,
76 'playlist[0][id]': episode_id,
77 'requestUrl': compat_urllib_parse_urlparse(url).path,
78 'requestSource': 'iVysilani',
79 }
80
81 req = compat_urllib_request.Request('http://www.ceskatelevize.cz/ivysilani/ajax/get-playlist-url',
82 data=compat_urllib_parse.urlencode(data))
83
84 req.add_header('Content-type', 'application/x-www-form-urlencoded')
85 req.add_header('x-addr', '127.0.0.1')
86 req.add_header('X-Requested-With', 'XMLHttpRequest')
87 req.add_header('Referer', url)
88
89 playlistpage = self._download_json(req, video_id)
90
91 req = compat_urllib_request.Request(compat_urllib_parse.unquote(playlistpage['url']))
92 req.add_header('Referer', url)
93
94 playlist = self._download_xml(req, video_id)
95
96 formats = []
97 for i in playlist.find('smilRoot/body'):
98 if 'AD' not in i.attrib['id']:
99 base_url = i.attrib['base']
100 parsedurl = compat_urllib_parse_urlparse(base_url)
101 duration = i.attrib['duration']
102
103 for video in i.findall('video'):
104 if video.attrib['label'] != 'AD':
105 format_id = video.attrib['label']
106 play_path = video.attrib['src']
107 vbr = int(video.attrib['system-bitrate'])
108
109 formats.append({
110 'format_id': format_id,
111 'url': base_url,
112 'vbr': vbr,
113 'play_path': play_path,
114 'app': parsedurl.path[1:] + '?' + parsedurl.query,
115 'rtmp_live': True,
116 'ext': 'flv',
117 })
118
119 self._sort_formats(formats)
120
121 return {
122 'id': episode_id,
123 'title': self._html_search_regex(r'<title>(.+?) — iVysílání — Česká televize</title>', webpage, 'title'),
124 'duration': float(duration),
125 'formats': formats,
126 }