]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/sonyliv.py
8 from .common
import InfoExtractor
9 from ..compat
import compat_HTTPError
17 class SonyLIVIE(InfoExtractor
):
21 https?://(?:www\.)?sonyliv\.com/(?:s(?:how|port)s/[^/]+|movies|clip|trailer|music-videos)/[^/?#&]+-
26 'url': 'https://www.sonyliv.com/shows/bachelors-delight-1700000113/achaari-cheese-toast-1000022678?watch=true',
28 'title': 'Achaari Cheese Toast',
31 'upload_date': '20200411',
32 'description': 'md5:3957fa31d9309bf336ceb3f37ad5b7cb',
33 'timestamp': 1586632091,
36 'series': 'Bachelors Delight',
41 'skip_download': True,
44 'url': 'https://www.sonyliv.com/movies/tahalka-1000050121?watch=true',
45 'only_matching': True,
47 'url': 'https://www.sonyliv.com/clip/jigarbaaz-1000098925',
48 'only_matching': True,
50 'url': 'https://www.sonyliv.com/trailer/sandwiched-forever-1000100286?watch=true',
51 'only_matching': True,
53 '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',
54 'only_matching': True,
56 'url': 'https://www.sonyliv.com/music-videos/yeh-un-dinon-ki-baat-hai-1000018779',
57 'only_matching': True,
59 _GEO_COUNTRIES
= ['IN']
61 _LOGIN_HINT
= 'Use "--username <mobile_number>" to login using OTP or "--username token --password <auth_token>" to login using auth token.'
62 _NETRC_MACHINE
= 'sonyliv'
64 def _get_device_id(self
):
65 e
= int(time
.time() * 1000)
66 t
= list('xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx')
67 for i
, c
in enumerate(t
):
68 n
= int((e
+ 16 * random
.random()) % 16) |
0
69 e
= math
.floor(e
/ 16)
73 t
[i
] = '{:x}'.format(3 & n |
8)
74 return ''.join(t
) + '-' + str(int(time
.time() * 1000))
76 def _perform_login(self
, username
, password
):
77 self
._HEADERS
['device_id'] = self
._get
_device
_id
()
78 self
._HEADERS
['content-type'] = 'application/json'
80 if username
.lower() == 'token' and len(password
) > 1198:
81 self
._HEADERS
['authorization'] = password
82 elif len(username
) != 10 or not username
.isdigit():
83 raise ExtractorError(f
'Invalid username/password; {self._LOGIN_HINT}')
86 otp_request_json
= self
._download
_json
(
87 'https://apiv2.sonyliv.com/AGL/1.6/A/ENG/WEB/IN/HR/CREATEOTP-V2',
88 None, note
='Sending OTP', headers
=self
._HEADERS
, data
=json
.dumps({
89 'mobileNumber': username
,
90 'channelPartnerID': 'MSMIND',
92 'timestamp': datetime
.datetime
.now().strftime('%Y-%m-%dT%H:%M:%S.%MZ'),
94 'loginType': 'REGISTERORSIGNIN',
95 'isMobileMandatory': True,
97 if otp_request_json
['resultCode'] == 'KO':
98 raise ExtractorError(otp_request_json
['message'], expected
=True)
100 otp_verify_json
= self
._download
_json
(
101 'https://apiv2.sonyliv.com/AGL/2.0/A/ENG/WEB/IN/HR/CONFIRMOTP-V2',
102 None, note
='Verifying OTP', headers
=self
._HEADERS
, data
=json
.dumps({
103 'channelPartnerID': 'MSMIND',
104 'mobileNumber': username
,
106 'otp': self
._get
_tfa
_info
('OTP'),
108 'ageConfirmation': True,
109 'timestamp': datetime
.datetime
.now().strftime('%Y-%m-%dT%H:%M:%S.%MZ'),
110 'isMobileMandatory': True,
112 if otp_verify_json
['resultCode'] == 'KO':
113 raise ExtractorError(otp_request_json
['message'], expected
=True)
114 self
._HEADERS
['authorization'] = otp_verify_json
['resultObj']['accessToken']
116 def _call_api(self
, version
, path
, video_id
):
118 return self
._download
_json
(
119 'https://apiv2.sonyliv.com/AGL/%s/A/ENG/WEB/%s' % (version
, path
),
120 video_id
, headers
=self
._HEADERS
)['resultObj']
121 except ExtractorError
as e
:
122 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 406 and self
._parse
_json
(
123 e
.cause
.read().decode(), video_id
)['message'] == 'Please subscribe to watch this content':
124 self
.raise_login_required(self
._LOGIN
_HINT
, method
=None)
125 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
126 message
= self
._parse
_json
(
127 e
.cause
.read().decode(), video_id
)['message']
128 if message
== 'Geoblocked Country':
129 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
130 raise ExtractorError(message
)
133 def _initialize_pre_login(self
):
134 self
._HEADERS
['security_token'] = self
._call
_api
('1.4', 'ALL/GETTOKEN', None)
136 def _real_extract(self
, url
):
137 video_id
= self
._match
_id
(url
)
138 content
= self
._call
_api
(
139 '1.5', 'IN/CONTENT/VIDEOURL/VOD/' + video_id
, video_id
)
140 if not self
.get_param('allow_unplayable_formats') and content
.get('isEncrypted'):
141 self
.report_drm(video_id
)
142 dash_url
= content
['videoURL']
144 'x-playback-session-id': '%s-%d' % (uuid
.uuid4().hex, time
.time() * 1000)
146 formats
= self
._extract
_mpd
_formats
(
147 dash_url
, video_id
, mpd_id
='dash', headers
=headers
, fatal
=False)
148 formats
.extend(self
._extract
_m
3u8_formats
(
149 dash_url
.replace('.mpd', '.m3u8').replace('/DASH/', '/HLS/'),
150 video_id
, 'mp4', m3u8_id
='hls', headers
=headers
, fatal
=False))
152 f
.setdefault('http_headers', {}).update(headers
)
153 self
._sort
_formats
(formats
)
155 metadata
= self
._call
_api
(
156 '1.6', 'IN/DETAIL/' + video_id
, video_id
)['containers'][0]['metadata']
157 title
= metadata
['episodeTitle']
159 for sub
in content
.get('subtitle', []):
160 sub_url
= sub
.get('subtitleUrl')
163 subtitles
.setdefault(sub
.get('subtitleLanguageName', 'ENG'), []).append({
170 'thumbnail': content
.get('posterURL'),
171 'description': metadata
.get('longDescription') or metadata
.get('shortDescription'),
172 'timestamp': int_or_none(metadata
.get('creationDate'), 1000),
173 'duration': int_or_none(metadata
.get('duration')),
174 'season_number': int_or_none(metadata
.get('season')),
175 'series': metadata
.get('title'),
176 'episode_number': int_or_none(metadata
.get('episodeNumber')),
177 'release_year': int_or_none(metadata
.get('year')),
178 'subtitles': subtitles
,
182 class SonyLIVSeriesIE(InfoExtractor
):
183 _VALID_URL
= r
'https?://(?:www\.)?sonyliv\.com/shows/[^/?#&]+-(?P<id>\d{10})$'
185 'url': 'https://www.sonyliv.com/shows/adaalat-1700000091',
186 'playlist_mincount': 456,
191 _API_SHOW_URL
= "https://apiv2.sonyliv.com/AGL/1.9/R/ENG/WEB/IN/DL/DETAIL/{}?kids_safe=false&from=0&to=49"
192 _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"
193 _API_SECURITY_URL
= 'https://apiv2.sonyliv.com/AGL/1.4/A/ENG/WEB/ALL/GETTOKEN'
195 def _entries(self
, show_id
):
197 'Accept': 'application/json, text/plain, */*',
198 'Referer': 'https://www.sonyliv.com',
200 headers
['security_token'] = self
._download
_json
(
201 self
._API
_SECURITY
_URL
, video_id
=show_id
, headers
=headers
,
202 note
='Downloading security token')['resultObj']
204 self
._download
_json
(self
._API
_SHOW
_URL
.format(show_id
), video_id
=show_id
, headers
=headers
),
205 lambda x
: x
['resultObj']['containers'][0]['containers'], list)
206 for season
in seasons
or []:
207 season_id
= season
['id']
209 self
._download
_json
(self
._API
_EPISODES
_URL
.format(season_id
), video_id
=season_id
, headers
=headers
),
210 lambda x
: x
['resultObj']['containers'][0]['containers'], list)
211 for episode
in episodes
or []:
212 video_id
= episode
.get('id')
213 yield self
.url_result('sonyliv:%s' % video_id
, ie
=SonyLIVIE
.ie_key(), video_id
=video_id
)
215 def _real_extract(self
, url
):
216 show_id
= self
._match
_id
(url
)
217 return self
.playlist_result(self
._entries
(show_id
), playlist_id
=show_id
)