1 from __future__ import unicode_literals
6 from .common import InfoExtractor
13 _x = lambda p: xpath_with_ns(p, {'smil': 'http://www.w3.org/2005/SMIL21/Language'})
16 class ThePlatformIE(InfoExtractor):
18 (?:https?://(?:link|player)\.theplatform\.com/[sp]/[^/]+/
19 (?P<config>(?:[^/\?]+/(?:swf|config)|onsite)/select/)?
20 |theplatform:)(?P<id>[^/\?&]+)'''
23 # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
24 'url': 'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
28 'title': 'Blackberry\'s big, bold Z30',
29 'description': 'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
34 'skip_download': True,
38 def _get_info(self, video_id, smil_url):
39 meta = self._download_xml(smil_url, video_id)
44 for n in meta.findall(_x('.//smil:ref'))
45 if n.attrib.get('title') == 'Geographic Restriction')
49 raise ExtractorError(error_msg, expected=True)
51 info_url = 'http://link.theplatform.com/s/dJ5BDC/{0}?format=preview'.format(video_id)
52 info_json = self._download_webpage(info_url, video_id)
53 info = json.loads(info_json)
55 head = meta.find(_x('smil:head'))
56 body = meta.find(_x('smil:body'))
58 f4m_node = body.find(_x('smil:seq//smil:video'))
59 if f4m_node is not None and '.f4m' in f4m_node.attrib['src']:
60 f4m_url = f4m_node.attrib['src']
61 if 'manifest.f4m?' not in f4m_url:
63 # the parameters are from syfy.com, other sites may use others,
64 # they also work for nbc.com
65 f4m_url += '&g=UXWGVKRWHFSP&hdcore=3.0.3'
66 formats = self._extract_f4m_formats(f4m_url, video_id)
69 switch = body.find(_x('smil:switch'))
70 if switch is not None:
71 base_url = head.find(_x('smil:meta')).attrib['base']
72 for f in switch.findall(_x('smil:video')):
74 width = int(attr['width'])
75 height = int(attr['height'])
76 vbr = int(attr['system-bitrate']) // 1000
77 format_id = '%dx%d_%dk' % (width, height, vbr)
79 'format_id': format_id,
81 'play_path': 'mp4:' + attr['src'],
88 switch = body.find(_x('smil:seq//smil:switch'))
89 for f in switch.findall(_x('smil:video')):
91 vbr = int(attr['system-bitrate']) // 1000
93 'format_id': compat_str(vbr),
97 self._sort_formats(formats)
101 'title': info['title'],
103 'description': info['description'],
104 'thumbnail': info['defaultThumbnailUrl'],
105 'duration': info['duration']//1000,
108 def _real_extract(self, url):
109 mobj = re.match(self._VALID_URL, url)
110 video_id = mobj.group('id')
111 if mobj.group('config'):
112 config_url = url+ '&form=json'
113 config_url = config_url.replace('swf/', 'config/')
114 config_url = config_url.replace('onsite/', 'onsite/config/')
115 config = self._download_json(config_url, video_id, 'Downloading config')
116 smil_url = config['releaseUrl'] + '&format=SMIL&formats=MPEG4&manifest=f4m'
118 smil_url = ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?'
119 'format=smil&mbr=true'.format(video_id))
120 return self._get_info(video_id, smil_url)