]>
Commit | Line | Data |
---|---|---|
05a0068a RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
05a0068a RA |
4 | |
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
fe45b0e0 | 7 | ExtractorError, |
29f7c58a | 8 | float_or_none, |
fe45b0e0 | 9 | int_or_none, |
29f7c58a | 10 | parse_iso8601, |
11 | try_get, | |
05a0068a RA |
12 | ) |
13 | ||
14 | ||
c9e12a61 | 15 | class NineCNineMediaIE(InfoExtractor): |
fe45b0e0 | 16 | IE_NAME = '9c9media' |
c9e12a61 | 17 | _GEO_COUNTRIES = ['CA'] |
fe45b0e0 | 18 | _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)' |
c9e12a61 | 19 | _API_BASE_TEMPLATE = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/' |
fe45b0e0 RA |
20 | |
21 | def _real_extract(self, url): | |
5ad28e7f | 22 | destination_code, content_id = self._match_valid_url(url).groups() |
fe45b0e0 RA |
23 | api_base_url = self._API_BASE_TEMPLATE % (destination_code, content_id) |
24 | content = self._download_json(api_base_url, content_id, query={ | |
3721515b | 25 | '$include': '[Media.Name,Season,ContentPackages.Duration,ContentPackages.Id]', |
fe45b0e0 RA |
26 | }) |
27 | title = content['Name'] | |
fe45b0e0 RA |
28 | content_package = content['ContentPackages'][0] |
29 | package_id = content_package['Id'] | |
30 | content_package_url = api_base_url + 'contentpackages/%s/' % package_id | |
c9e12a61 RA |
31 | content_package = self._download_json( |
32 | content_package_url, content_id, query={ | |
33 | '$include': '[HasClosedCaptions]', | |
34 | }) | |
fe45b0e0 | 35 | |
a06916d9 | 36 | if (not self.get_param('allow_unplayable_formats') |
06869367 | 37 | and try_get(content_package, lambda x: x['Constraints']['Security']['Type'])): |
fe45b0e0 RA |
38 | raise ExtractorError('This video is DRM protected.', expected=True) |
39 | ||
c9e12a61 RA |
40 | manifest_base_url = content_package_url + 'manifest.' |
41 | formats = [] | |
42 | formats.extend(self._extract_m3u8_formats( | |
43 | manifest_base_url + 'm3u8', content_id, 'mp4', | |
44 | 'm3u8_native', m3u8_id='hls', fatal=False)) | |
45 | formats.extend(self._extract_f4m_formats( | |
46 | manifest_base_url + 'f4m', content_id, | |
47 | f4m_id='hds', fatal=False)) | |
48 | formats.extend(self._extract_mpd_formats( | |
49 | manifest_base_url + 'mpd', content_id, | |
50 | mpd_id='dash', fatal=False)) | |
51 | self._sort_formats(formats) | |
fe45b0e0 RA |
52 | |
53 | thumbnails = [] | |
29f7c58a | 54 | for image in (content.get('Images') or []): |
fe45b0e0 RA |
55 | image_url = image.get('Url') |
56 | if not image_url: | |
57 | continue | |
58 | thumbnails.append({ | |
59 | 'url': image_url, | |
60 | 'width': int_or_none(image.get('Width')), | |
61 | 'height': int_or_none(image.get('Height')), | |
62 | }) | |
63 | ||
64 | tags, categories = [], [] | |
65 | for source_name, container in (('Tags', tags), ('Genres', categories)): | |
66 | for e in content.get(source_name, []): | |
67 | e_name = e.get('Name') | |
68 | if not e_name: | |
69 | continue | |
70 | container.append(e_name) | |
71 | ||
29f7c58a | 72 | season = content.get('Season') or {} |
c9e12a61 RA |
73 | |
74 | info = { | |
75 | 'id': content_id, | |
76 | 'title': title, | |
77 | 'description': content.get('Desc') or content.get('ShortDesc'), | |
fe45b0e0 RA |
78 | 'timestamp': parse_iso8601(content.get('BroadcastDateTime')), |
79 | 'episode_number': int_or_none(content.get('Episode')), | |
80 | 'season': season.get('Name'), | |
29f7c58a | 81 | 'season_number': int_or_none(season.get('Number')), |
fe45b0e0 | 82 | 'season_id': season.get('Id'), |
29f7c58a | 83 | 'series': try_get(content, lambda x: x['Media']['Name']), |
fe45b0e0 RA |
84 | 'tags': tags, |
85 | 'categories': categories, | |
c9e12a61 RA |
86 | 'duration': float_or_none(content_package.get('Duration')), |
87 | 'formats': formats, | |
29f7c58a | 88 | 'thumbnails': thumbnails, |
fe45b0e0 RA |
89 | } |
90 | ||
c9e12a61 RA |
91 | if content_package.get('HasClosedCaptions'): |
92 | info['subtitles'] = { | |
93 | 'en': [{ | |
94 | 'url': manifest_base_url + 'vtt', | |
95 | 'ext': 'vtt', | |
96 | }, { | |
97 | 'url': manifest_base_url + 'srt', | |
98 | 'ext': 'srt', | |
99 | }] | |
fe45b0e0 | 100 | } |
fe45b0e0 | 101 | |
c9e12a61 | 102 | return info |