2 from __future__ import unicode_literals
6 from .common import InfoExtractor
18 class TurnerBaseIE(InfoExtractor):
19 def _extract_cvp_info(self, data_src, video_id, path_data={}):
20 video_data = self._download_xml(data_src, video_id)
21 video_id = video_data.attrib['id'].split('/')[-1].split('.')[0]
22 title = xpath_text(video_data, 'headline', fatal=True)
23 # rtmp_src = xpath_text(video_data, 'akamai/src')
25 # splited_rtmp_src = rtmp_src.split(',')
26 # if len(splited_rtmp_src) == 2:
27 # rtmp_src = splited_rtmp_src[1]
28 # aifp = xpath_text(video_data, 'akamai/aifp', default='')
33 rex = re.compile(r'''(?x)
34 (?P<width>[0-9]+)x(?P<height>[0-9]+)
35 (?:_(?P<bitrate>[0-9]+))?
37 for video_file in video_data.findall('files/file'):
38 video_url = video_file.text.strip()
41 ext = determine_ext(video_url)
42 if video_url.startswith('/mp4:protected/'):
44 # TODO Correct extraction for these files
45 # protected_path_data = path_data.get('protected')
46 # if not protected_path_data or not rtmp_src:
48 # protected_path = self._search_regex(
49 # r'/mp4:(.+)\.[a-z0-9]', video_url, 'secure path')
50 # auth = self._download_webpage(
51 # protected_path_data['tokenizer_src'], query={
52 # 'path': protected_path,
53 # 'videoId': video_id,
56 # token = xpath_text(auth, 'token')
59 # video_url = rtmp_src + video_url + '?' + token
60 elif video_url.startswith('/secure/'):
61 secure_path_data = path_data.get('secure')
62 if not secure_path_data:
64 video_url = secure_path_data['media_src'] + video_url
65 secure_path = self._search_regex(r'https?://[^/]+(.+/)', video_url, 'secure path') + '*'
66 token = tokens.get(secure_path)
68 auth = self._download_xml(
69 secure_path_data['tokenizer_src'], video_id, query={
73 token = xpath_text(auth, 'token')
76 tokens[secure_path] = token
77 video_url = video_url + '?hdnea=' + token
78 elif not re.match('https?://', video_url):
79 base_path_data = path_data.get(ext, path_data.get('default', {}))
80 media_src = base_path_data.get('media_src')
83 video_url = media_src + video_url
86 urls.append(video_url)
87 format_id = video_file.attrib['bitrate']
89 formats.extend(self._extract_smil_formats(video_url, video_id, fatal=False))
91 m3u8_formats = self._extract_m3u8_formats(
92 video_url, video_id, 'mp4', m3u8_id=format_id, fatal=False)
94 # Sometimes final URLs inside m3u8 are unsigned, let's fix this
96 qs = compat_urlparse.urlparse(video_url).query
98 query = compat_urlparse.parse_qs(qs)
99 for m3u8_format in m3u8_formats:
100 m3u8_format['url'] = update_url_query(m3u8_format['url'], query)
101 m3u8_format['extra_param_to_segment_url'] = qs
102 formats.extend(m3u8_formats)
104 formats.extend(self._extract_f4m_formats(
105 update_url_query(video_url, {'hdcore': '3.7.0'}),
106 video_id, f4m_id=format_id, fatal=False))
109 'format_id': format_id,
113 mobj = rex.search(format_id + video_url)
116 'width': int(mobj.group('width')),
117 'height': int(mobj.group('height')),
118 'tbr': int_or_none(mobj.group('bitrate')),
120 elif format_id.isdigit():
121 f['tbr'] = int(format_id)
123 mobj = re.match(r'ios_(audio|[0-9]+)$', format_id)
125 if mobj.group(1) == 'audio':
131 f['tbr'] = int(mobj.group(1))
133 self._sort_formats(formats)
136 for source in video_data.findall('closedCaptions/source'):
137 for track in source.findall('track'):
138 source_url = source.get('url')
141 subtitles.set_default(source.get('lang') or source.get('label') or 'en', []).append({
147 }.get(source.get('format'))
151 'id': image.get('cut'),
153 'width': int_or_none(image.get('width')),
154 'height': int_or_none(image.get('height')),
155 } for image in video_data.findall('images/image')]
158 if 'cnn.com' not in data_src:
159 timestamp = int_or_none(xpath_attr(video_data, 'dateCreated', 'uts'))
165 'subtitles': subtitles,
166 'thumbnails': thumbnails,
167 'description': xpath_text(video_data, 'description'),
168 'duration': parse_duration(xpath_text(video_data, 'length') or xpath_text(video_data, 'trt')),
169 'timestamp': timestamp,
170 'upload_date': xpath_attr(video_data, 'metas', 'version'),
171 'series': xpath_text(video_data, 'showTitle'),
172 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
173 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),