]>
Commit | Line | Data |
---|---|---|
ed86f38a JMF |
1 | from __future__ import unicode_literals |
2 | ||
e9bf7479 JMF |
3 | import re |
4 | import json | |
5 | ||
748ec667 | 6 | from .subtitles import SubtitlesInfoExtractor |
1cc79574 | 7 | from ..compat import ( |
e35cb78c | 8 | compat_str, |
1cc79574 PH |
9 | ) |
10 | from ..utils import ( | |
10e3d734 | 11 | determine_ext, |
f8b56e95 | 12 | ExtractorError, |
e9bf7479 | 13 | xpath_with_ns, |
e9bf7479 JMF |
14 | ) |
15 | ||
16 | _x = lambda p: xpath_with_ns(p, {'smil': 'http://www.w3.org/2005/SMIL21/Language'}) | |
17 | ||
18 | ||
748ec667 | 19 | class ThePlatformIE(SubtitlesInfoExtractor): |
a97bcd80 JMF |
20 | _VALID_URL = r'''(?x) |
21 | (?:https?://(?:link|player)\.theplatform\.com/[sp]/[^/]+/ | |
020cf5eb | 22 | (?P<config>(?:[^/\?]+/(?:swf|config)|onsite)/select/)? |
a97bcd80 | 23 | |theplatform:)(?P<id>[^/\?&]+)''' |
e9bf7479 JMF |
24 | |
25 | _TEST = { | |
26 | # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/ | |
ed86f38a JMF |
27 | 'url': 'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true', |
28 | 'info_dict': { | |
29 | 'id': 'e9I_cZgTgIPd', | |
30 | 'ext': 'flv', | |
31 | 'title': 'Blackberry\'s big, bold Z30', | |
32 | 'description': 'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.', | |
33 | 'duration': 247, | |
e9bf7479 | 34 | }, |
ed86f38a | 35 | 'params': { |
e9bf7479 | 36 | # rtmp download |
ed86f38a | 37 | 'skip_download': True, |
e9bf7479 JMF |
38 | }, |
39 | } | |
5f6a1245 | 40 | |
10e3d734 PH |
41 | def _real_extract(self, url): |
42 | mobj = re.match(self._VALID_URL, url) | |
43 | video_id = mobj.group('id') | |
44 | if mobj.group('config'): | |
5f6a1245 | 45 | config_url = url + '&form=json' |
10e3d734 PH |
46 | config_url = config_url.replace('swf/', 'config/') |
47 | config_url = config_url.replace('onsite/', 'onsite/config/') | |
48 | config = self._download_json(config_url, video_id, 'Downloading config') | |
49 | smil_url = config['releaseUrl'] + '&format=SMIL&formats=MPEG4&manifest=f4m' | |
50 | else: | |
51 | smil_url = ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?' | |
9e1a5b84 | 52 | 'format=smil&mbr=true'.format(video_id)) |
e9bf7479 | 53 | |
10e3d734 | 54 | meta = self._download_xml(smil_url, video_id) |
f8b56e95 PH |
55 | try: |
56 | error_msg = next( | |
57 | n.attrib['abstract'] | |
58 | for n in meta.findall(_x('.//smil:ref')) | |
ed86f38a | 59 | if n.attrib.get('title') == 'Geographic Restriction') |
f8b56e95 PH |
60 | except StopIteration: |
61 | pass | |
62 | else: | |
63 | raise ExtractorError(error_msg, expected=True) | |
64 | ||
e9bf7479 JMF |
65 | info_url = 'http://link.theplatform.com/s/dJ5BDC/{0}?format=preview'.format(video_id) |
66 | info_json = self._download_webpage(info_url, video_id) | |
67 | info = json.loads(info_json) | |
68 | ||
748ec667 S |
69 | subtitles = {} |
70 | captions = info.get('captions') | |
71 | if isinstance(captions, list): | |
72 | for caption in captions: | |
73 | lang, src = caption.get('lang'), caption.get('src') | |
74 | if lang and src: | |
75 | subtitles[lang] = src | |
76 | ||
77 | if self._downloader.params.get('listsubtitles', False): | |
78 | self._list_available_subtitles(video_id, subtitles) | |
79 | return | |
80 | ||
81 | subtitles = self.extract_subtitles(video_id, subtitles) | |
82 | ||
e9bf7479 JMF |
83 | head = meta.find(_x('smil:head')) |
84 | body = meta.find(_x('smil:body')) | |
360babf7 | 85 | |
22d99a80 | 86 | f4m_node = body.find(_x('smil:seq//smil:video')) |
e35cb78c | 87 | if f4m_node is not None and '.f4m' in f4m_node.attrib['src']: |
020cf5eb JMF |
88 | f4m_url = f4m_node.attrib['src'] |
89 | if 'manifest.f4m?' not in f4m_url: | |
90 | f4m_url += '?' | |
91 | # the parameters are from syfy.com, other sites may use others, | |
92 | # they also work for nbc.com | |
93 | f4m_url += '&g=UXWGVKRWHFSP&hdcore=3.0.3' | |
dd41e8c8 | 94 | formats = self._extract_f4m_formats(f4m_url, video_id) |
a97bcd80 | 95 | else: |
a97bcd80 | 96 | formats = [] |
e35cb78c JMF |
97 | switch = body.find(_x('smil:switch')) |
98 | if switch is not None: | |
99 | base_url = head.find(_x('smil:meta')).attrib['base'] | |
100 | for f in switch.findall(_x('smil:video')): | |
101 | attr = f.attrib | |
102 | width = int(attr['width']) | |
103 | height = int(attr['height']) | |
104 | vbr = int(attr['system-bitrate']) // 1000 | |
105 | format_id = '%dx%d_%dk' % (width, height, vbr) | |
106 | formats.append({ | |
107 | 'format_id': format_id, | |
108 | 'url': base_url, | |
109 | 'play_path': 'mp4:' + attr['src'], | |
110 | 'ext': 'flv', | |
111 | 'width': width, | |
112 | 'height': height, | |
113 | 'vbr': vbr, | |
114 | }) | |
115 | else: | |
116 | switch = body.find(_x('smil:seq//smil:switch')) | |
117 | for f in switch.findall(_x('smil:video')): | |
118 | attr = f.attrib | |
119 | vbr = int(attr['system-bitrate']) // 1000 | |
10e3d734 PH |
120 | ext = determine_ext(attr['src']) |
121 | if ext == 'once': | |
122 | ext = 'mp4' | |
e35cb78c JMF |
123 | formats.append({ |
124 | 'format_id': compat_str(vbr), | |
125 | 'url': attr['src'], | |
126 | 'vbr': vbr, | |
10e3d734 | 127 | 'ext': ext, |
e35cb78c | 128 | }) |
a97bcd80 | 129 | self._sort_formats(formats) |
e9bf7479 JMF |
130 | |
131 | return { | |
132 | 'id': video_id, | |
133 | 'title': info['title'], | |
748ec667 | 134 | 'subtitles': subtitles, |
e9bf7479 JMF |
135 | 'formats': formats, |
136 | 'description': info['description'], | |
137 | 'thumbnail': info['defaultThumbnailUrl'], | |
2514d263 | 138 | 'duration': info['duration'] // 1000, |
e9bf7479 | 139 | } |