2 from __future__ import unicode_literals
4 from .common import InfoExtractor
12 class HotStarIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?hotstar\.com/(?:.+?[/-])?(?P<id>\d{10})'
15 'url': 'http://www.hotstar.com/on-air-with-aib--english-1000076273',
19 'title': 'On Air With AIB - English',
20 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
21 'timestamp': 1447227000,
22 'upload_date': '20151111',
27 'skip_download': True,
30 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
31 'only_matching': True,
33 'url': 'http://www.hotstar.com/1000000515',
34 'only_matching': True,
37 _GET_CONTENT_TEMPLATE = 'http://account.hotstar.com/AVS/besc?action=GetAggregatedContentDetails&channel=PCTV&contentId=%s'
38 _GET_CDN_TEMPLATE = 'http://getcdn.hotstar.com/AVS/besc?action=GetCDN&asJson=Y&channel=%s&id=%s&type=%s'
40 def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True):
41 json_data = super(HotStarIE, self)._download_json(url_or_request, video_id, note, fatal=fatal)
42 if json_data['resultCode'] != 'OK':
44 raise ExtractorError(json_data['errorDescription'])
46 return json_data['resultObj']
48 def _real_extract(self, url):
49 video_id = self._match_id(url)
50 video_data = self._download_json(
51 self._GET_CONTENT_TEMPLATE % video_id,
52 video_id)['contentInfo'][0]
55 # PCTV for extracting f4m manifest
57 format_data = self._download_json(
58 self._GET_CDN_TEMPLATE % (f, video_id, 'VOD'),
59 video_id, 'Downloading %s JSON metadata' % f, fatal=False)
61 format_url = format_data['src']
62 ext = determine_ext(format_url)
64 formats.extend(self._extract_m3u8_formats(format_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
66 # produce broken files
71 'width': int_or_none(format_data.get('width')),
72 'height': int_or_none(format_data.get('height')),
74 self._sort_formats(formats)
78 'title': video_data['episodeTitle'],
79 'description': video_data.get('description'),
80 'duration': int_or_none(video_data.get('duration')),
81 'timestamp': int_or_none(video_data.get('broadcastDate')),