]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/theplatform.py
   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' 
  70             base_url 
= head
.find(_x('smil:meta')).attrib
['base'] 
  71             switch 
= body
.find(_x('smil:switch')) 
  73             for f 
in switch
.findall(_x('smil:video')): 
  75                 width 
= int(attr
['width']) 
  76                 height 
= int(attr
['height']) 
  77                 vbr 
= int(attr
['system-bitrate']) // 1000 
  78                 format_id 
= '%dx%d_%dk' % (width
, height
, vbr
) 
  80                     'format_id': format_id
, 
  82                     'play_path': 'mp4:' + attr
['src'], 
  88             self
._sort
_formats
(formats
) 
  92             'title': info
['title'], 
  94             'description': info
['description'], 
  95             'thumbnail': info
['defaultThumbnailUrl'], 
  96             'duration': info
['duration']//1000, 
  99     def _real_extract(self
, url
): 
 100         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 101         video_id 
= mobj
.group('id') 
 102         if mobj
.group('config'): 
 103             config_url 
= url
+ '&form=json' 
 104             config_url 
= config_url
.replace('swf/', 'config/') 
 105             config_url 
= config_url
.replace('onsite/', 'onsite/config/') 
 106             config 
= self
._download
_json
(config_url
, video_id
, 'Downloading config') 
 107             smil_url 
= config
['releaseUrl'] + '&format=SMIL&formats=MPEG4&manifest=f4m' 
 109             smil_url 
= ('http://link.theplatform.com/s/dJ5BDC/{0}/meta.smil?' 
 110                 'format=smil&mbr=true'.format(video_id
)) 
 111         return self
._get
_info
(video_id
, smil_url
)