2 from __future__ import unicode_literals
6 from .common import InfoExtractor
15 class NineCNineMediaIE(InfoExtractor):
17 _GEO_COUNTRIES = ['CA']
18 _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
19 _API_BASE_TEMPLATE = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/'
21 def _real_extract(self, url):
22 destination_code, content_id = re.match(self._VALID_URL, url).groups()
23 api_base_url = self._API_BASE_TEMPLATE % (destination_code, content_id)
24 content = self._download_json(api_base_url, content_id, query={
25 '$include': '[Media,Season,ContentPackages]',
27 title = content['Name']
28 if len(content['ContentPackages']) > 1:
29 raise ExtractorError('multiple content packages')
30 content_package = content['ContentPackages'][0]
31 package_id = content_package['Id']
32 content_package_url = api_base_url + 'contentpackages/%s/' % package_id
33 content_package = self._download_json(
34 content_package_url, content_id, query={
35 '$include': '[HasClosedCaptions]',
38 if content_package.get('Constraints', {}).get('Security', {}).get('Type'):
39 raise ExtractorError('This video is DRM protected.', expected=True)
41 manifest_base_url = content_package_url + 'manifest.'
43 formats.extend(self._extract_m3u8_formats(
44 manifest_base_url + 'm3u8', content_id, 'mp4',
45 'm3u8_native', m3u8_id='hls', fatal=False))
46 formats.extend(self._extract_f4m_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', []):
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', {})
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': season.get('Number'),
83 'season_id': season.get('Id'),
84 'series': content.get('Media', {}).get('Name'),
86 'categories': categories,
87 'duration': float_or_none(content_package.get('Duration')),
91 if content_package.get('HasClosedCaptions'):
94 'url': manifest_base_url + 'vtt',
97 'url': manifest_base_url + 'srt',