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