1 from __future__ import unicode_literals
6 from .common import InfoExtractor
12 _x = lambda p: xpath_with_ns(p, {'smil': 'http://www.w3.org/2005/SMIL21/Language'})
15 class ThePlatformIE(InfoExtractor):
17 (?:https?://(?:link|player)\.theplatform\.com/[sp]/[^/]+/
18 (?P<config>(?:[^/\?]+/(?:swf|config)|onsite)/select/)?
19 |theplatform:)(?P<id>[^/\?&]+)'''
22 # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
23 'url': 'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
27 'title': 'Blackberry\'s big, bold Z30',
28 'description': 'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
33 'skip_download': True,
37 def _get_info(self, video_id, smil_url):
38 meta = self._download_xml(smil_url, video_id)
43 for n in meta.findall(_x('.//smil:ref'))
44 if n.attrib.get('title') == 'Geographic Restriction')
48 raise ExtractorError(error_msg, expected=True)
50 info_url = 'http://link.theplatform.com/s/dJ5BDC/{0}?format=preview'.format(video_id)
51 info_json = self._download_webpage(info_url, video_id)
52 info = json.loads(info_json)
54 head = meta.find(_x('smil:head'))
55 body = meta.find(_x('smil:body'))
57 f4m_node = body.find(_x('smil:seq//smil:video'))
58 if f4m_node is not None:
59 f4m_url = f4m_node.attrib['src']
60 if 'manifest.f4m?' not in f4m_url:
62 # the parameters are from syfy.com, other sites may use others,
63 # they also work for nbc.com
64 f4m_url += '&g=UXWGVKRWHFSP&hdcore=3.0.3'
65 formats = self._extract_f4m_formats(f4m_url, video_id)
67 base_url = head.find(_x('smil:meta')).attrib['base']
68 switch = body.find(_x('smil:switch'))
70 for f in switch.findall(_x('smil:video')):
72 width = int(attr['width'])
73 height = int(attr['height'])
74 vbr = int(attr['system-bitrate']) // 1000
75 format_id = '%dx%d_%dk' % (width, height, vbr)
77 'format_id': format_id,
79 'play_path': 'mp4:' + attr['src'],
85 self._sort_formats(formats)
89 'title': info['title'],
91 'description': info['description'],
92 'thumbnail': info['defaultThumbnailUrl'],
93 'duration': info['duration']//1000,
96 def _real_extract(self, url):
97 mobj = re.match(self._VALID_URL, url)
98 video_id = mobj.group('id')
99 if mobj.group('config'):
100 config_url = url+ '&form=json'
101 config_url = config_url.replace('swf/', 'config/')
102 config_url = config_url.replace('onsite/', 'onsite/config/')
103 config = self._download_json(config_url, video_id, 'Downloading config')
104 smil_url = config['releaseUrl'] + '&format=SMIL&formats=MPEG4&manifest=f4m'
106 smil_url = ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?'
107 'format=smil&mbr=true'.format(video_id))
108 return self._get_info(video_id, smil_url)