1 from __future__ import unicode_literals
11 from .common import InfoExtractor
12 from ..compat import (
23 _x = lambda p: xpath_with_ns(p, {'smil': 'http://www.w3.org/2005/SMIL21/Language'})
26 class ThePlatformIE(InfoExtractor):
28 (?:https?://(?:link|player)\.theplatform\.com/[sp]/(?P<provider_id>[^/]+)/
29 (?:(?P<media>(?:[^/]+/)+select/media/)|(?P<config>(?:[^/\?]+/(?:swf|config)|onsite)/select/))?
30 |theplatform:)(?P<id>[^/\?&]+)'''
33 # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
34 'url': 'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
38 'title': 'Blackberry\'s big, bold Z30',
39 'description': 'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
44 'skip_download': True,
47 # from http://www.cnet.com/videos/tesla-model-s-a-second-step-towards-a-cleaner-motoring-future/
48 'url': 'http://link.theplatform.com/s/kYEXFC/22d_qsQ6MIRT',
52 'description': 'md5:ac330c9258c04f9d7512cf26b9595409',
53 'title': 'Tesla Model S: A second step towards a cleaner motoring future',
57 'skip_download': True,
60 'url': 'https://player.theplatform.com/p/D6x-PC/pulse_preview/embed/select/media/yMBg9E8KFxZD',
64 'description': 'md5:644ad9188d655b742f942bf2e06b002d',
65 'title': 'HIGHLIGHTS: USA bag first ever series Cup win',
68 'url': 'http://player.theplatform.com/p/NnzsPC/widget/select/media/4Y0TlYUr_ZT7',
69 'only_matching': True,
73 def _sign_url(url, sig_key, sig_secret, life=600, include_qs=False):
74 flags = '10' if include_qs else '00'
75 expiration_date = '%x' % (int(time.time()) + life)
78 return binascii.b2a_hex(str.encode('ascii')).decode('ascii')
81 return binascii.a2b_hex(hex)
83 relative_path = url.split('http://link.theplatform.com/s/')[1].split('?')[0]
84 clear_text = hex_to_str(flags + expiration_date + str_to_hex(relative_path))
85 checksum = hmac.new(sig_key.encode('ascii'), clear_text, hashlib.sha1).hexdigest()
86 sig = flags + expiration_date + checksum + str_to_hex(sig_secret)
87 return '%s&sig=%s' % (url, sig)
89 def _real_extract(self, url):
90 url, smuggled_data = unsmuggle_url(url, {})
92 mobj = re.match(self._VALID_URL, url)
93 provider_id = mobj.group('provider_id')
94 video_id = mobj.group('id')
97 provider_id = 'dJ5BDC'
100 if mobj.group('media'):
102 path += '/' + video_id
104 if smuggled_data.get('force_smil_url', False):
106 elif mobj.group('config'):
107 config_url = url + '&form=json'
108 config_url = config_url.replace('swf/', 'config/')
109 config_url = config_url.replace('onsite/', 'onsite/config/')
110 config = self._download_json(config_url, video_id, 'Downloading config')
111 if 'releaseUrl' in config:
112 release_url = config['releaseUrl']
114 release_url = 'http://link.theplatform.com/s/%s?mbr=true' % path
115 smil_url = release_url + '&format=SMIL&formats=MPEG4&manifest=f4m'
117 smil_url = 'http://link.theplatform.com/s/%s/meta.smil?format=smil&mbr=true' % path
119 sig = smuggled_data.get('sig')
121 smil_url = self._sign_url(smil_url, sig['key'], sig['secret'])
123 meta = self._download_xml(smil_url, video_id)
127 for n in meta.findall(_x('.//smil:ref'))
128 if n.attrib.get('title') == 'Geographic Restriction' or n.attrib.get('title') == 'Expired')
129 except StopIteration:
132 raise ExtractorError(error_msg, expected=True)
134 info_url = 'http://link.theplatform.com/s/%s?format=preview' % path
135 info_json = self._download_webpage(info_url, video_id)
136 info = json.loads(info_json)
139 captions = info.get('captions')
140 if isinstance(captions, list):
141 for caption in captions:
142 lang, src, mime = caption.get('lang', 'en'), caption.get('src'), caption.get('type')
144 'ext': 'srt' if mime == 'text/srt' else 'ttml',
148 head = meta.find(_x('smil:head'))
149 body = meta.find(_x('smil:body'))
151 f4m_node = body.find(_x('smil:seq//smil:video'))
153 f4m_node = body.find(_x('smil:seq/smil:video'))
154 if f4m_node is not None and '.f4m' in f4m_node.attrib['src']:
155 f4m_url = f4m_node.attrib['src']
156 if 'manifest.f4m?' not in f4m_url:
158 # the parameters are from syfy.com, other sites may use others,
159 # they also work for nbc.com
160 f4m_url += '&g=UXWGVKRWHFSP&hdcore=3.0.3'
161 formats = self._extract_f4m_formats(f4m_url, video_id)
164 switch = body.find(_x('smil:switch'))
166 switch = body.find(_x('smil:par//smil:switch'))
168 switch = body.find(_x('smil:par/smil:switch'))
170 switch = body.find(_x('smil:par'))
171 if switch is not None:
172 base_url = head.find(_x('smil:meta')).attrib['base']
173 for f in switch.findall(_x('smil:video')):
175 width = int_or_none(attr.get('width'))
176 height = int_or_none(attr.get('height'))
177 vbr = int_or_none(attr.get('system-bitrate'), 1000)
178 format_id = '%dx%d_%dk' % (width, height, vbr)
180 'format_id': format_id,
182 'play_path': 'mp4:' + attr['src'],
189 switch = body.find(_x('smil:seq//smil:switch'))
191 switch = body.find(_x('smil:seq/smil:switch'))
192 for f in switch.findall(_x('smil:video')):
194 vbr = int_or_none(attr.get('system-bitrate'), 1000)
195 ext = determine_ext(attr['src'])
199 'format_id': compat_str(vbr),
204 self._sort_formats(formats)
208 'title': info['title'],
209 'subtitles': subtitles,
211 'description': info['description'],
212 'thumbnail': info['defaultThumbnailUrl'],
213 'duration': int_or_none(info.get('duration'), 1000),