]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ninecninemedia.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_str
 
  16 class NineCNineMediaBaseIE(InfoExtractor
): 
  17     _API_BASE_TEMPLATE 
= 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/' 
  20 class NineCNineMediaStackIE(NineCNineMediaBaseIE
): 
  21     IE_NAME 
= '9c9media:stack' 
  22     _GEO_COUNTRIES 
= ['CA'] 
  23     _VALID_URL 
= r
'9c9media:stack:(?P<destination_code>[^:]+):(?P<content_id>\d+):(?P<content_package>\d+):(?P<id>\d+)' 
  25     def _real_extract(self
, url
): 
  26         destination_code
, content_id
, package_id
, stack_id 
= re
.match(self
._VALID
_URL
, url
).groups() 
  27         stack_base_url_template 
= self
._API
_BASE
_TEMPLATE 
+ 'contentpackages/%s/stacks/%s/manifest.' 
  28         stack_base_url 
= stack_base_url_template 
% (destination_code
, content_id
, package_id
, stack_id
) 
  31         formats
.extend(self
._extract
_m
3u8_formats
( 
  32             stack_base_url 
+ 'm3u8', stack_id
, 'mp4', 
  33             'm3u8_native', m3u8_id
='hls', fatal
=False)) 
  34         formats
.extend(self
._extract
_f
4m
_formats
( 
  35             stack_base_url 
+ 'f4m', stack_id
, 
  36             f4m_id
='hds', fatal
=False)) 
  37         self
._sort
_formats
(formats
) 
  45 class NineCNineMediaIE(NineCNineMediaBaseIE
): 
  47     _VALID_URL 
= r
'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)' 
  49     def _real_extract(self
, url
): 
  50         destination_code
, content_id 
= re
.match(self
._VALID
_URL
, url
).groups() 
  51         api_base_url 
= self
._API
_BASE
_TEMPLATE 
% (destination_code
, content_id
) 
  52         content 
= self
._download
_json
(api_base_url
, content_id
, query
={ 
  53             '$include': '[Media,Season,ContentPackages]', 
  55         title 
= content
['Name'] 
  56         if len(content
['ContentPackages']) > 1: 
  57             raise ExtractorError('multiple content packages') 
  58         content_package 
= content
['ContentPackages'][0] 
  59         package_id 
= content_package
['Id'] 
  60         content_package_url 
= api_base_url 
+ 'contentpackages/%s/' % package_id
 
  61         content_package 
= self
._download
_json
(content_package_url
, content_id
) 
  63         if content_package
.get('Constraints', {}).get('Security', {}).get('Type') == 'adobe-drm': 
  64             raise ExtractorError('This video is DRM protected.', expected
=True) 
  66         stacks 
= self
._download
_json
(content_package_url 
+ 'stacks/', package_id
)['Items'] 
  67         multistacks 
= len(stacks
) > 1 
  70         for image 
in content
.get('Images', []): 
  71             image_url 
= image
.get('Url') 
  76                 'width': int_or_none(image
.get('Width')), 
  77                 'height': int_or_none(image
.get('Height')), 
  80         tags
, categories 
= [], [] 
  81         for source_name
, container 
in (('Tags', tags
), ('Genres', categories
)): 
  82             for e 
in content
.get(source_name
, []): 
  83                 e_name 
= e
.get('Name') 
  86                 container
.append(e_name
) 
  88         description 
= content
.get('Desc') or content
.get('ShortDesc') 
  89         season 
= content
.get('Season', {}) 
  91             'description': description
, 
  92             'timestamp': parse_iso8601(content
.get('BroadcastDateTime')), 
  93             'episode_number': int_or_none(content
.get('Episode')), 
  94             'season': season
.get('Name'), 
  95             'season_number': season
.get('Number'), 
  96             'season_id': season
.get('Id'), 
  97             'series': content
.get('Media', {}).get('Name'), 
  99             'categories': categories
, 
 104             stack_id 
= compat_str(stack
['Id']) 
 106                 '_type': 'url_transparent', 
 107                 'url': '9c9media:stack:%s:%s:%s:%s' % (destination_code
, content_id
, package_id
, stack_id
), 
 109                 'title': '%s_part%s' % (title
, stack
['Name']) if multistacks 
else title
, 
 110                 'duration': float_or_none(stack
.get('Duration')), 
 111                 'ie_key': 'NineCNineMediaStack', 
 113             entry
.update(base_info
) 
 114             entries
.append(entry
) 
 117             '_type': 'multi_video', 
 120             'description': description
,