]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/theplatform.py
1 from __future__
import unicode_literals
6 from .subtitles
import SubtitlesInfoExtractor
16 _x
= lambda p
: xpath_with_ns(p
, {'smil': 'http://www.w3.org/2005/SMIL21/Language'})
19 class ThePlatformIE(SubtitlesInfoExtractor
):
21 (?:https?://(?:link|player)\.theplatform\.com/[sp]/[^/]+/
22 (?P<config>(?:[^/\?]+/(?:swf|config)|onsite)/select/)?
23 |theplatform:)(?P<id>[^/\?&]+)'''
26 # from http://www.metacafe.com/watch/cb-e9I_cZgTgIPd/blackberrys_big_bold_z30/
27 'url': 'http://link.theplatform.com/s/dJ5BDC/e9I_cZgTgIPd/meta.smil?format=smil&Tracking=true&mbr=true',
31 'title': 'Blackberry\'s big, bold Z30',
32 'description': 'The Z30 is Blackberry\'s biggest, baddest mobile messaging device yet.',
37 'skip_download': True,
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'):
45 config_url
= url
+ '&form=json'
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'
51 smil_url
= ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?'
52 'format=smil&mbr=true'.format(video_id
))
54 meta
= self
._download
_xml
(smil_url
, video_id
)
58 for n
in meta
.findall(_x('.//smil:ref'))
59 if n
.attrib
.get('title') == 'Geographic Restriction')
63 raise ExtractorError(error_msg
, expected
=True)
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
)
70 captions
= info
.get('captions')
71 if isinstance(captions
, list):
72 for caption
in captions
:
73 lang
, src
= caption
.get('lang'), caption
.get('src')
77 if self
._downloader
.params
.get('listsubtitles', False):
78 self
._list
_available
_subtitles
(video_id
, subtitles
)
81 subtitles
= self
.extract_subtitles(video_id
, subtitles
)
83 head
= meta
.find(_x('smil:head'))
84 body
= meta
.find(_x('smil:body'))
86 f4m_node
= body
.find(_x('smil:seq//smil:video'))
87 if f4m_node
is not None and '.f4m' in f4m_node
.attrib
['src']:
88 f4m_url
= f4m_node
.attrib
['src']
89 if 'manifest.f4m?' not in 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'
94 formats
= self
._extract
_f
4m
_formats
(f4m_url
, video_id
)
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')):
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
)
107 'format_id': format_id
,
109 'play_path': 'mp4:' + attr
['src'],
116 switch
= body
.find(_x('smil:seq//smil:switch'))
117 for f
in switch
.findall(_x('smil:video')):
119 vbr
= int(attr
['system-bitrate']) // 1000
120 ext
= determine_ext(attr
['src'])
124 'format_id': compat_str(vbr
),
129 self
._sort
_formats
(formats
)
133 'title': info
['title'],
134 'subtitles': subtitles
,
136 'description': info
['description'],
137 'thumbnail': info
['defaultThumbnailUrl'],
138 'duration': info
['duration'] // 1000,