2 from __future__ import unicode_literals
6 from .common import InfoExtractor
17 class TurnerBaseIE(InfoExtractor):
18 def _extract_cvp_info(self, data_src, video_id, path_data={}):
19 video_data = self._download_xml(data_src, video_id)
20 video_id = video_data.attrib['id'].split('/')[-1].split('.')[0]
21 title = xpath_text(video_data, 'headline', fatal=True)
22 # rtmp_src = xpath_text(video_data, 'akamai/src')
24 # splited_rtmp_src = rtmp_src.split(',')
25 # if len(splited_rtmp_src) == 2:
26 # rtmp_src = splited_rtmp_src[1]
27 # aifp = xpath_text(video_data, 'akamai/aifp', default='')
32 rex = re.compile(r'''(?x)
33 (?P<width>[0-9]+)x(?P<height>[0-9]+)
34 (?:_(?P<bitrate>[0-9]+))?
36 for video_file in video_data.findall('files/file'):
37 video_url = video_file.text.strip()
40 ext = determine_ext(video_url)
41 if video_url.startswith('/mp4:protected/'):
43 # TODO Correct extraction for these files
44 # protected_path_data = path_data.get('protected')
45 # if not protected_path_data or not rtmp_src:
47 # protected_path = self._search_regex(
48 # r'/mp4:(.+)\.[a-z0-9]', video_url, 'secure path')
49 # auth = self._download_webpage(
50 # protected_path_data['tokenizer_src'], query={
51 # 'path': protected_path,
52 # 'videoId': video_id,
55 # token = xpath_text(auth, 'token')
58 # video_url = rtmp_src + video_url + '?' + token
59 elif video_url.startswith('/secure/'):
60 secure_path_data = path_data.get('secure')
61 if not secure_path_data:
63 video_url = secure_path_data['media_src'] + video_url
64 secure_path = self._search_regex(r'https?://[^/]+(.+/)', video_url, 'secure path') + '*'
65 token = tokens.get(secure_path)
67 auth = self._download_xml(
68 secure_path_data['tokenizer_src'], video_id, query={
72 token = xpath_text(auth, 'token')
75 tokens[secure_path] = token
76 video_url = video_url + '?hdnea=' + token
77 elif not re.match('https?://', video_url):
78 base_path_data = path_data.get(ext, path_data.get('default', {}))
79 media_src = base_path_data.get('media_src')
82 video_url = media_src + video_url
85 urls.append(video_url)
86 format_id = video_file.attrib['bitrate']
88 formats.extend(self._extract_smil_formats(video_url, video_id, fatal=False))
90 formats.extend(self._extract_m3u8_formats(
91 video_url, video_id, 'mp4', m3u8_id=format_id, fatal=False))
93 formats.extend(self._extract_f4m_formats(
94 update_url_query(video_url, {'hdcore': '3.7.0'}),
95 video_id, f4m_id=format_id, fatal=False))
98 'format_id': format_id,
102 mobj = rex.search(format_id + video_url)
105 'width': int(mobj.group('width')),
106 'height': int(mobj.group('height')),
107 'tbr': int_or_none(mobj.group('bitrate')),
109 elif format_id.isdigit():
110 f['tbr'] = int(format_id)
112 mobj = re.match(r'ios_(audio|[0-9]+)$', format_id)
114 if mobj.group(1) == 'audio':
120 f['tbr'] = int(mobj.group(1))
122 self._sort_formats(formats)
125 for source in video_data.findall('closedCaptions/source'):
126 for track in source.findall('track'):
127 source_url = source.get('url')
130 subtitles.set_default(source.get('lang') or source.get('label') or 'en', []).append({
136 }.get(source.get('format'))
140 'id': image.get('cut'),
142 'width': int_or_none(image.get('width')),
143 'height': int_or_none(image.get('height')),
144 } for image in video_data.findall('images/image')]
147 if 'cnn.com' not in data_src:
148 timestamp = int_or_none(xpath_attr(video_data, 'dateCreated', 'uts'))
154 'subtitles': subtitles,
155 'thumbnails': thumbnails,
156 'description': xpath_text(video_data, 'description'),
157 'duration': parse_duration(xpath_text(video_data, 'length') or xpath_text(video_data, 'trt')),
158 'timestamp': timestamp,
159 'upload_date': xpath_attr(video_data, 'metas', 'version'),
160 'series': xpath_text(video_data, 'showTitle'),
161 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
162 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),