]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/hotstar.py
[6play] use geo verfication headers
[yt-dlp.git] / youtube_dl / extractor / hotstar.py
CommitLineData
fb8e402a 1# coding: utf-8
2from __future__ import unicode_literals
3
909191de
S
4import re
5
fb8e402a 6from .common import InfoExtractor
909191de 7from ..compat import compat_str
fb8e402a 8from ..utils import (
fb8e402a 9 determine_ext,
909191de 10 ExtractorError,
fb8e402a 11 int_or_none,
12)
13
14
909191de 15class HotStarBaseIE(InfoExtractor):
6e71bbf4 16 _GEO_COUNTRIES = ['IN']
909191de
S
17
18 def _download_json(self, *args, **kwargs):
19 response = super(HotStarBaseIE, self)._download_json(*args, **kwargs)
20 if response['resultCode'] != 'OK':
21 if kwargs.get('fatal'):
22 raise ExtractorError(
23 response['errorDescription'], expected=True)
24 return None
25 return response['resultObj']
26
27 def _download_content_info(self, content_id):
28 return self._download_json(
29 'https://account.hotstar.com/AVS/besc', content_id, query={
30 'action': 'GetAggregatedContentDetails',
31 'appVersion': '5.0.40',
32 'channel': 'PCTV',
33 'contentId': content_id,
34 })['contentInfo'][0]
35
36
37class HotStarIE(HotStarBaseIE):
38 _VALID_URL = r'https?://(?:www\.)?hotstar\.com/(?:.+?[/-])?(?P<id>\d{10})'
89d23f37 39 _TESTS = [{
fb8e402a 40 'url': 'http://www.hotstar.com/on-air-with-aib--english-1000076273',
41 'info_dict': {
42 'id': '1000076273',
43 'ext': 'mp4',
477c97f8 44 'title': 'On Air With AIB',
fb8e402a 45 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
46 'timestamp': 1447227000,
47 'upload_date': '20151111',
48 'duration': 381,
49 },
50 'params': {
51 # m3u8 download
52 'skip_download': True,
53 }
89d23f37
S
54 }, {
55 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
56 'only_matching': True,
57 }, {
58 'url': 'http://www.hotstar.com/1000000515',
59 'only_matching': True,
60 }]
fb8e402a 61
fb8e402a 62 def _real_extract(self, url):
63 video_id = self._match_id(url)
909191de
S
64
65 video_data = self._download_content_info(video_id)
66
0dac7cbb
RA
67 title = video_data['episodeTitle']
68
69 if video_data.get('encrypted') == 'Y':
70 raise ExtractorError('This video is DRM protected.', expected=True)
fb8e402a 71
72 formats = []
0dac7cbb 73 for f in ('JIO',):
fb8e402a 74 format_data = self._download_json(
0dac7cbb
RA
75 'http://getcdn.hotstar.com/AVS/besc',
76 video_id, 'Downloading %s JSON metadata' % f,
77 fatal=False, query={
78 'action': 'GetCDN',
79 'asJson': 'Y',
80 'channel': f,
81 'id': video_id,
82 'type': 'VOD',
83 })
fb8e402a 84 if format_data:
0dac7cbb
RA
85 format_url = format_data.get('src')
86 if not format_url:
87 continue
fb8e402a 88 ext = determine_ext(format_url)
89 if ext == 'm3u8':
0dac7cbb
RA
90 formats.extend(self._extract_m3u8_formats(
91 format_url, video_id, 'mp4',
92 m3u8_id='hls', fatal=False))
fb8e402a 93 elif ext == 'f4m':
94 # produce broken files
95 continue
96 else:
97 formats.append({
98 'url': format_url,
99 'width': int_or_none(format_data.get('width')),
100 'height': int_or_none(format_data.get('height')),
101 })
102 self._sort_formats(formats)
103
104 return {
105 'id': video_id,
0dac7cbb 106 'title': title,
fb8e402a 107 'description': video_data.get('description'),
108 'duration': int_or_none(video_data.get('duration')),
109 'timestamp': int_or_none(video_data.get('broadcastDate')),
110 'formats': formats,
0dac7cbb
RA
111 'episode': title,
112 'episode_number': int_or_none(video_data.get('episodeNumber')),
113 'series': video_data.get('contentTitle'),
fb8e402a 114 }
477c97f8
AV
115
116
909191de 117class HotStarPlaylistIE(HotStarBaseIE):
477c97f8 118 IE_NAME = 'hotstar:playlist'
909191de 119 _VALID_URL = r'(?P<url>https?://(?:www\.)?hotstar\.com/tv/[^/]+/(?P<content_id>\d+))/(?P<type>[^/]+)/(?P<id>\d+)'
477c97f8 120 _TESTS = [{
909191de 121 'url': 'http://www.hotstar.com/tv/pratidaan/14982/episodes/14812/9993',
477c97f8 122 'info_dict': {
909191de 123 'id': '14812',
477c97f8 124 },
909191de 125 'playlist_mincount': 75,
477c97f8 126 }, {
909191de 127 'url': 'http://www.hotstar.com/tv/pratidaan/14982/popular-clips/9998/9998',
477c97f8
AV
128 'only_matching': True,
129 }]
909191de
S
130 _ITEM_TYPES = {
131 'episodes': 'EPISODE',
132 'popular-clips': 'CLIPS',
133 }
477c97f8
AV
134
135 def _real_extract(self, url):
136 mobj = re.match(self._VALID_URL, url)
909191de
S
137 base_url = mobj.group('url')
138 content_id = mobj.group('content_id')
139 playlist_type = mobj.group('type')
140
141 content_info = self._download_content_info(content_id)
142 playlist_id = compat_str(content_info['categoryId'])
477c97f8
AV
143
144 collection = self._download_json(
909191de
S
145 'https://search.hotstar.com/AVS/besc', playlist_id, query={
146 'action': 'SearchContents',
147 'appVersion': '5.0.40',
148 'channel': 'PCTV',
149 'moreFilters': 'series:%s;' % playlist_id,
150 'query': '*',
151 'searchOrder': 'last_broadcast_date desc,year desc,title asc',
152 'type': self._ITEM_TYPES.get(playlist_type, 'EPISODE'),
153 })
477c97f8 154
477c97f8 155 entries = [
909191de
S
156 self.url_result(
157 '%s/_/%s' % (base_url, video['contentId']),
158 ie=HotStarIE.ie_key(), video_id=video['contentId'])
159 for video in collection['response']['docs']
160 if video.get('contentId')]
161
162 return self.playlist_result(entries, playlist_id)