]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/sonyliv.py
8 from .common
import InfoExtractor
9 from ..compat
import compat_HTTPError
19 class SonyLIVIE(InfoExtractor
):
23 https?://(?:www\.)?sonyliv\.com/(?:s(?:how|port)s/[^/]+|movies|clip|trailer|music-videos)/[^/?#&]+-
28 'url': 'https://www.sonyliv.com/shows/bachelors-delight-1700000113/achaari-cheese-toast-1000022678?watch=true',
30 'title': 'Achaari Cheese Toast',
33 'upload_date': '20200411',
34 'description': 'md5:3957fa31d9309bf336ceb3f37ad5b7cb',
35 'timestamp': 1586632091,
38 'series': 'Bachelors Delight',
43 'skip_download': True,
46 'url': 'https://www.sonyliv.com/movies/tahalka-1000050121?watch=true',
47 'only_matching': True,
49 'url': 'https://www.sonyliv.com/clip/jigarbaaz-1000098925',
50 'only_matching': True,
52 'url': 'https://www.sonyliv.com/trailer/sandwiched-forever-1000100286?watch=true',
53 'only_matching': True,
55 'url': 'https://www.sonyliv.com/sports/india-tour-of-australia-2020-21-1700000286/cricket-hls-day-3-1st-test-aus-vs-ind-19-dec-2020-1000100959?watch=true',
56 'only_matching': True,
58 'url': 'https://www.sonyliv.com/music-videos/yeh-un-dinon-ki-baat-hai-1000018779',
59 'only_matching': True,
61 _GEO_COUNTRIES
= ['IN']
63 _LOGIN_HINT
= 'Use "--username <mobile_number>" to login using OTP or "--username token --password <auth_token>" to login using auth token.'
64 _NETRC_MACHINE
= 'sonyliv'
66 def _get_device_id(self
):
67 e
= int(time
.time() * 1000)
68 t
= list('xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx')
69 for i
, c
in enumerate(t
):
70 n
= int((e
+ 16 * random
.random()) % 16) |
0
71 e
= math
.floor(e
/ 16)
75 t
[i
] = '{:x}'.format(3 & n |
8)
76 return ''.join(t
) + '-' + str(int(time
.time() * 1000))
78 def _perform_login(self
, username
, password
):
79 self
._HEADERS
['device_id'] = self
._get
_device
_id
()
80 self
._HEADERS
['content-type'] = 'application/json'
82 if username
.lower() == 'token' and try_call(lambda: jwt_decode_hs256(password
)):
83 self
._HEADERS
['authorization'] = password
86 elif len(username
) != 10 or not username
.isdigit():
87 raise ExtractorError(f
'Invalid username/password; {self._LOGIN_HINT}')
90 otp_request_json
= self
._download
_json
(
91 'https://apiv2.sonyliv.com/AGL/1.6/A/ENG/WEB/IN/HR/CREATEOTP-V2',
92 None, note
='Sending OTP', headers
=self
._HEADERS
, data
=json
.dumps({
93 'mobileNumber': username
,
94 'channelPartnerID': 'MSMIND',
96 'timestamp': datetime
.datetime
.now().strftime('%Y-%m-%dT%H:%M:%S.%MZ'),
98 'loginType': 'REGISTERORSIGNIN',
99 'isMobileMandatory': True,
101 if otp_request_json
['resultCode'] == 'KO':
102 raise ExtractorError(otp_request_json
['message'], expected
=True)
104 otp_verify_json
= self
._download
_json
(
105 'https://apiv2.sonyliv.com/AGL/2.0/A/ENG/WEB/IN/HR/CONFIRMOTP-V2',
106 None, note
='Verifying OTP', headers
=self
._HEADERS
, data
=json
.dumps({
107 'channelPartnerID': 'MSMIND',
108 'mobileNumber': username
,
110 'otp': self
._get
_tfa
_info
('OTP'),
112 'ageConfirmation': True,
113 'timestamp': datetime
.datetime
.now().strftime('%Y-%m-%dT%H:%M:%S.%MZ'),
114 'isMobileMandatory': True,
116 if otp_verify_json
['resultCode'] == 'KO':
117 raise ExtractorError(otp_request_json
['message'], expected
=True)
118 self
._HEADERS
['authorization'] = otp_verify_json
['resultObj']['accessToken']
120 def _call_api(self
, version
, path
, video_id
):
122 return self
._download
_json
(
123 'https://apiv2.sonyliv.com/AGL/%s/A/ENG/WEB/%s' % (version
, path
),
124 video_id
, headers
=self
._HEADERS
)['resultObj']
125 except ExtractorError
as e
:
126 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 406 and self
._parse
_json
(
127 e
.cause
.read().decode(), video_id
)['message'] == 'Please subscribe to watch this content':
128 self
.raise_login_required(self
._LOGIN
_HINT
, method
=None)
129 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
130 message
= self
._parse
_json
(
131 e
.cause
.read().decode(), video_id
)['message']
132 if message
== 'Geoblocked Country':
133 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
134 raise ExtractorError(message
)
137 def _initialize_pre_login(self
):
138 self
._HEADERS
['security_token'] = self
._call
_api
('1.4', 'ALL/GETTOKEN', None)
140 def _real_extract(self
, url
):
141 video_id
= self
._match
_id
(url
)
142 content
= self
._call
_api
(
143 '1.5', 'IN/CONTENT/VIDEOURL/VOD/' + video_id
, video_id
)
144 if not self
.get_param('allow_unplayable_formats') and content
.get('isEncrypted'):
145 self
.report_drm(video_id
)
146 dash_url
= content
['videoURL']
148 'x-playback-session-id': '%s-%d' % (uuid
.uuid4().hex, time
.time() * 1000)
150 formats
= self
._extract
_mpd
_formats
(
151 dash_url
, video_id
, mpd_id
='dash', headers
=headers
, fatal
=False)
152 formats
.extend(self
._extract
_m
3u8_formats
(
153 dash_url
.replace('.mpd', '.m3u8').replace('/DASH/', '/HLS/'),
154 video_id
, 'mp4', m3u8_id
='hls', headers
=headers
, fatal
=False))
156 f
.setdefault('http_headers', {}).update(headers
)
158 metadata
= self
._call
_api
(
159 '1.6', 'IN/DETAIL/' + video_id
, video_id
)['containers'][0]['metadata']
160 title
= metadata
['episodeTitle']
162 for sub
in content
.get('subtitle', []):
163 sub_url
= sub
.get('subtitleUrl')
166 subtitles
.setdefault(sub
.get('subtitleLanguageName', 'ENG'), []).append({
173 'thumbnail': content
.get('posterURL'),
174 'description': metadata
.get('longDescription') or metadata
.get('shortDescription'),
175 'timestamp': int_or_none(metadata
.get('creationDate'), 1000),
176 'duration': int_or_none(metadata
.get('duration')),
177 'season_number': int_or_none(metadata
.get('season')),
178 'series': metadata
.get('title'),
179 'episode_number': int_or_none(metadata
.get('episodeNumber')),
180 'release_year': int_or_none(metadata
.get('year')),
181 'subtitles': subtitles
,
185 class SonyLIVSeriesIE(InfoExtractor
):
186 _VALID_URL
= r
'https?://(?:www\.)?sonyliv\.com/shows/[^/?#&]+-(?P<id>\d{10})$'
188 'url': 'https://www.sonyliv.com/shows/adaalat-1700000091',
189 'playlist_mincount': 456,
194 _API_SHOW_URL
= "https://apiv2.sonyliv.com/AGL/1.9/R/ENG/WEB/IN/DL/DETAIL/{}?kids_safe=false&from=0&to=49"
195 _API_EPISODES_URL
= "https://apiv2.sonyliv.com/AGL/1.4/R/ENG/WEB/IN/CONTENT/DETAIL/BUNDLE/{}?from=0&to=1000&orderBy=episodeNumber&sortOrder=asc"
196 _API_SECURITY_URL
= 'https://apiv2.sonyliv.com/AGL/1.4/A/ENG/WEB/ALL/GETTOKEN'
198 def _entries(self
, show_id
):
200 'Accept': 'application/json, text/plain, */*',
201 'Referer': 'https://www.sonyliv.com',
203 headers
['security_token'] = self
._download
_json
(
204 self
._API
_SECURITY
_URL
, video_id
=show_id
, headers
=headers
,
205 note
='Downloading security token')['resultObj']
207 self
._download
_json
(self
._API
_SHOW
_URL
.format(show_id
), video_id
=show_id
, headers
=headers
),
208 lambda x
: x
['resultObj']['containers'][0]['containers'], list)
209 for season
in seasons
or []:
210 season_id
= season
['id']
212 self
._download
_json
(self
._API
_EPISODES
_URL
.format(season_id
), video_id
=season_id
, headers
=headers
),
213 lambda x
: x
['resultObj']['containers'][0]['containers'], list)
214 for episode
in episodes
or []:
215 video_id
= episode
.get('id')
216 yield self
.url_result('sonyliv:%s' % video_id
, ie
=SonyLIVIE
.ie_key(), video_id
=video_id
)
218 def _real_extract(self
, url
):
219 show_id
= self
._match
_id
(url
)
220 return self
.playlist_result(self
._entries
(show_id
), playlist_id
=show_id
)