]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ninecninemedia.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class NineCNineMediaIE(InfoExtractor
):
18 _GEO_COUNTRIES
= ['CA']
19 _VALID_URL
= r
'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
20 _API_BASE_TEMPLATE
= 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/'
22 def _real_extract(self
, url
):
23 destination_code
, content_id
= re
.match(self
._VALID
_URL
, url
).groups()
24 api_base_url
= self
._API
_BASE
_TEMPLATE
% (destination_code
, content_id
)
25 content
= self
._download
_json
(api_base_url
, content_id
, query
={
26 '$include': '[Media.Name,Season,ContentPackages.Duration,ContentPackages.Id]',
28 title
= content
['Name']
29 content_package
= content
['ContentPackages'][0]
30 package_id
= content_package
['Id']
31 content_package_url
= api_base_url
+ 'contentpackages/%s/' % package_id
32 content_package
= self
._download
_json
(
33 content_package_url
, content_id
, query
={
34 '$include': '[HasClosedCaptions]',
37 if (not self
._downloader
.params
.get('allow_unplayable_formats')
38 and try_get(content_package
, lambda x
: x
['Constraints']['Security']['Type'])):
39 raise ExtractorError('This video is DRM protected.', expected
=True)
41 manifest_base_url
= content_package_url
+ 'manifest.'
43 formats
.extend(self
._extract
_m
3u8_formats
(
44 manifest_base_url
+ 'm3u8', content_id
, 'mp4',
45 'm3u8_native', m3u8_id
='hls', fatal
=False))
46 formats
.extend(self
._extract
_f
4m
_formats
(
47 manifest_base_url
+ 'f4m', content_id
,
48 f4m_id
='hds', fatal
=False))
49 formats
.extend(self
._extract
_mpd
_formats
(
50 manifest_base_url
+ 'mpd', content_id
,
51 mpd_id
='dash', fatal
=False))
52 self
._sort
_formats
(formats
)
55 for image
in (content
.get('Images') or []):
56 image_url
= image
.get('Url')
61 'width': int_or_none(image
.get('Width')),
62 'height': int_or_none(image
.get('Height')),
65 tags
, categories
= [], []
66 for source_name
, container
in (('Tags', tags
), ('Genres', categories
)):
67 for e
in content
.get(source_name
, []):
68 e_name
= e
.get('Name')
71 container
.append(e_name
)
73 season
= content
.get('Season') or {}
78 'description': content
.get('Desc') or content
.get('ShortDesc'),
79 'timestamp': parse_iso8601(content
.get('BroadcastDateTime')),
80 'episode_number': int_or_none(content
.get('Episode')),
81 'season': season
.get('Name'),
82 'season_number': int_or_none(season
.get('Number')),
83 'season_id': season
.get('Id'),
84 'series': try_get(content
, lambda x
: x
['Media']['Name']),
86 'categories': categories
,
87 'duration': float_or_none(content_package
.get('Duration')),
89 'thumbnails': thumbnails
,
92 if content_package
.get('HasClosedCaptions'):
95 'url': manifest_base_url
+ 'vtt',
98 'url': manifest_base_url
+ 'srt',