2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
19 class TurnerBaseIE(InfoExtractor):
20 def _extract_cvp_info(self, data_src, video_id, path_data={}):
21 video_data = self._download_xml(data_src, video_id)
22 video_id = video_data.attrib['id'].split('/')[-1].split('.')[0]
23 title = xpath_text(video_data, 'headline', fatal=True)
24 # rtmp_src = xpath_text(video_data, 'akamai/src')
26 # splited_rtmp_src = rtmp_src.split(',')
27 # if len(splited_rtmp_src) == 2:
28 # rtmp_src = splited_rtmp_src[1]
29 # aifp = xpath_text(video_data, 'akamai/aifp', default='')
35 r'(?P<width>[0-9]+)x(?P<height>[0-9]+)(?:_(?P<bitrate>[0-9]+))?')
36 # Possible formats locations: files/file, files/groupFiles/files
38 for video_file in video_data.findall('.//file'):
39 video_url = video_file.text.strip()
42 ext = determine_ext(video_url)
43 if video_url.startswith('/mp4:protected/'):
45 # TODO Correct extraction for these files
46 # protected_path_data = path_data.get('protected')
47 # if not protected_path_data or not rtmp_src:
49 # protected_path = self._search_regex(
50 # r'/mp4:(.+)\.[a-z0-9]', video_url, 'secure path')
51 # auth = self._download_webpage(
52 # protected_path_data['tokenizer_src'], query={
53 # 'path': protected_path,
54 # 'videoId': video_id,
57 # token = xpath_text(auth, 'token')
60 # video_url = rtmp_src + video_url + '?' + token
61 elif video_url.startswith('/secure/'):
62 secure_path_data = path_data.get('secure')
63 if not secure_path_data:
65 video_url = secure_path_data['media_src'] + video_url
66 secure_path = self._search_regex(r'https?://[^/]+(.+/)', video_url, 'secure path') + '*'
67 token = tokens.get(secure_path)
69 auth = self._download_xml(
70 secure_path_data['tokenizer_src'], video_id, query={
74 token = xpath_text(auth, 'token')
77 tokens[secure_path] = token
78 video_url = video_url + '?hdnea=' + token
79 elif not re.match('https?://', video_url):
80 base_path_data = path_data.get(ext, path_data.get('default', {}))
81 media_src = base_path_data.get('media_src')
84 video_url = media_src + video_url
87 urls.append(video_url)
88 format_id = video_file.get('bitrate')
90 formats.extend(self._extract_smil_formats(
91 video_url, video_id, fatal=False))
93 m3u8_formats = self._extract_m3u8_formats(
94 video_url, video_id, 'mp4', m3u8_id=format_id or 'hls',
97 # Sometimes final URLs inside m3u8 are unsigned, let's fix this
99 qs = compat_urlparse.urlparse(video_url).query
101 query = compat_urlparse.parse_qs(qs)
102 for m3u8_format in m3u8_formats:
103 m3u8_format['url'] = update_url_query(m3u8_format['url'], query)
104 m3u8_format['extra_param_to_segment_url'] = qs
105 formats.extend(m3u8_formats)
107 formats.extend(self._extract_f4m_formats(
108 update_url_query(video_url, {'hdcore': '3.7.0'}),
109 video_id, f4m_id=format_id or 'hds', fatal=False))
112 'format_id': format_id,
116 mobj = rex.search(format_id + video_url)
119 'width': int(mobj.group('width')),
120 'height': int(mobj.group('height')),
121 'tbr': int_or_none(mobj.group('bitrate')),
123 elif isinstance(format_id, compat_str):
124 if format_id.isdigit():
125 f['tbr'] = int(format_id)
127 mobj = re.match(r'ios_(audio|[0-9]+)$', format_id)
129 if mobj.group(1) == 'audio':
135 f['tbr'] = int(mobj.group(1))
137 self._sort_formats(formats)
140 for source in video_data.findall('closedCaptions/source'):
141 for track in source.findall('track'):
142 track_url = track.get('url')
143 if not isinstance(track_url, compat_str) or track_url.endswith('/big'):
145 lang = track.get('lang') or track.get('label') or 'en'
146 subtitles.setdefault(lang, []).append({
152 }.get(source.get('format'))
156 'id': image.get('cut'),
158 'width': int_or_none(image.get('width')),
159 'height': int_or_none(image.get('height')),
160 } for image in video_data.findall('images/image')]
163 if 'cnn.com' not in data_src:
164 timestamp = int_or_none(xpath_attr(video_data, 'dateCreated', 'uts'))
170 'subtitles': subtitles,
171 'thumbnails': thumbnails,
172 'description': xpath_text(video_data, 'description'),
173 'duration': parse_duration(xpath_text(video_data, 'length') or xpath_text(video_data, 'trt')),
174 'timestamp': timestamp,
175 'upload_date': xpath_attr(video_data, 'metas', 'version'),
176 'series': xpath_text(video_data, 'showTitle'),
177 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
178 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),