1 from __future__ import unicode_literals
6 from .common import InfoExtractor
14 _x = lambda p: xpath_with_ns(p, {'smil': 'http://www.w3.org/2005/SMIL21/Language'})
17 class ThePlatformIE(InfoExtractor):
19 (?:https?://(?:link|player)\.theplatform\.com/[sp]/[^/]+/
20 (?P<config>(?:[^/\?]+/(?:swf|config)|onsite)/select/)?
21 |theplatform:)(?P<id>[^/\?&]+)'''
24 # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
25 'url': 'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
29 'title': 'Blackberry\'s big, bold Z30',
30 'description': 'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
35 'skip_download': True,
39 def _real_extract(self, url):
40 mobj = re.match(self._VALID_URL, url)
41 video_id = mobj.group('id')
42 if mobj.group('config'):
43 config_url = url + '&form=json'
44 config_url = config_url.replace('swf/', 'config/')
45 config_url = config_url.replace('onsite/', 'onsite/config/')
46 config = self._download_json(config_url, video_id, 'Downloading config')
47 smil_url = config['releaseUrl'] + '&format=SMIL&formats=MPEG4&manifest=f4m'
49 smil_url = ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?'
50 'format=smil&mbr=true'.format(video_id))
52 meta = self._download_xml(smil_url, video_id)
56 for n in meta.findall(_x('.//smil:ref'))
57 if n.attrib.get('title') == 'Geographic Restriction')
61 raise ExtractorError(error_msg, expected=True)
63 info_url = 'http://link.theplatform.com/s/dJ5BDC/{0}?format=preview'.format(video_id)
64 info_json = self._download_webpage(info_url, video_id)
65 info = json.loads(info_json)
67 head = meta.find(_x('smil:head'))
68 body = meta.find(_x('smil:body'))
70 f4m_node = body.find(_x('smil:seq//smil:video'))
71 if f4m_node is not None and '.f4m' in f4m_node.attrib['src']:
72 f4m_url = f4m_node.attrib['src']
73 if 'manifest.f4m?' not in f4m_url:
75 # the parameters are from syfy.com, other sites may use others,
76 # they also work for nbc.com
77 f4m_url += '&g=UXWGVKRWHFSP&hdcore=3.0.3'
78 formats = self._extract_f4m_formats(f4m_url, video_id)
81 switch = body.find(_x('smil:switch'))
82 if switch is not None:
83 base_url = head.find(_x('smil:meta')).attrib['base']
84 for f in switch.findall(_x('smil:video')):
86 width = int(attr['width'])
87 height = int(attr['height'])
88 vbr = int(attr['system-bitrate']) // 1000
89 format_id = '%dx%d_%dk' % (width, height, vbr)
91 'format_id': format_id,
93 'play_path': 'mp4:' + attr['src'],
100 switch = body.find(_x('smil:seq//smil:switch'))
101 for f in switch.findall(_x('smil:video')):
103 vbr = int(attr['system-bitrate']) // 1000
104 ext = determine_ext(attr['src'])
108 'format_id': compat_str(vbr),
113 self._sort_formats(formats)
117 'title': info['title'],
119 'description': info['description'],
120 'thumbnail': info['defaultThumbnailUrl'],
121 'duration': info['duration'] // 1000,