]>
Commit | Line | Data |
---|---|---|
fb8e402a | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | ExtractorError, | |
7 | determine_ext, | |
8 | int_or_none, | |
9 | ) | |
10 | ||
11 | ||
12 | class HotStarIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://(?:www\.)?hotstar\.com/.*?[/-](?P<id>\d{10})' | |
14 | _TEST = { | |
15 | 'url': 'http://www.hotstar.com/on-air-with-aib--english-1000076273', | |
16 | 'info_dict': { | |
17 | 'id': '1000076273', | |
18 | 'ext': 'mp4', | |
19 | 'title': 'On Air With AIB - English', | |
20 | 'description': 'md5:c957d8868e9bc793ccb813691cc4c434', | |
21 | 'timestamp': 1447227000, | |
22 | 'upload_date': '20151111', | |
23 | 'duration': 381, | |
24 | }, | |
25 | 'params': { | |
26 | # m3u8 download | |
27 | 'skip_download': True, | |
28 | } | |
29 | } | |
30 | ||
31 | _GET_CONTENT_TEMPLATE = 'http://account.hotstar.com/AVS/besc?action=GetAggregatedContentDetails&channel=PCTV&contentId=%s' | |
32 | _GET_CDN_TEMPLATE = 'http://getcdn.hotstar.com/AVS/besc?action=GetCDN&asJson=Y&channel=%s&id=%s&type=%s' | |
33 | ||
34 | def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True): | |
35 | json_data = super(HotStarIE, self)._download_json(url_or_request, video_id, note, fatal=fatal) | |
36 | if json_data['resultCode'] != 'OK': | |
37 | if fatal: | |
38 | raise ExtractorError(json_data['errorDescription']) | |
39 | return None | |
40 | return json_data['resultObj'] | |
41 | ||
42 | def _real_extract(self, url): | |
43 | video_id = self._match_id(url) | |
44 | video_data = self._download_json( | |
45 | self._GET_CONTENT_TEMPLATE % video_id, | |
46 | video_id)['contentInfo'][0] | |
47 | ||
48 | formats = [] | |
49 | # PCTV for extracting f4m manifest | |
50 | for f in ('TABLET',): | |
51 | format_data = self._download_json( | |
52 | self._GET_CDN_TEMPLATE % (f, video_id, 'VOD'), | |
53 | video_id, 'Downloading %s JSON metadata' % f, fatal=False) | |
54 | if format_data: | |
55 | format_url = format_data['src'] | |
56 | ext = determine_ext(format_url) | |
57 | if ext == 'm3u8': | |
7e5edcfd | 58 | formats.extend(self._extract_m3u8_formats(format_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) |
fb8e402a | 59 | elif ext == 'f4m': |
60 | # produce broken files | |
61 | continue | |
62 | else: | |
63 | formats.append({ | |
64 | 'url': format_url, | |
65 | 'width': int_or_none(format_data.get('width')), | |
66 | 'height': int_or_none(format_data.get('height')), | |
67 | }) | |
68 | self._sort_formats(formats) | |
69 | ||
70 | return { | |
71 | 'id': video_id, | |
72 | 'title': video_data['episodeTitle'], | |
73 | 'description': video_data.get('description'), | |
74 | 'duration': int_or_none(video_data.get('duration')), | |
75 | 'timestamp': int_or_none(video_data.get('broadcastDate')), | |
76 | 'formats': formats, | |
77 | } |