[afreecatv] Support password-protected livestreams (#2738)

Authored by: wlritchi
This commit is contained in:
Luc Ritchie 2022-02-11 09:15:59 -05:00 committed by GitHub
parent 079a7cfc71
commit 5dee3ad037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -416,26 +416,35 @@ class AfreecaTVLiveIE(AfreecaTVIE):
def _real_extract(self, url): def _real_extract(self, url):
broadcaster_id, broadcast_no = self._match_valid_url(url).group('id', 'bno') broadcaster_id, broadcast_no = self._match_valid_url(url).group('id', 'bno')
password = self.get_param('videopassword')
info = self._download_json(self._LIVE_API_URL, broadcaster_id, fatal=False, info = self._download_json(self._LIVE_API_URL, broadcaster_id, fatal=False,
data=urlencode_postdata({'bid': broadcaster_id})) or {} data=urlencode_postdata({'bid': broadcaster_id})) or {}
channel_info = info.get('CHANNEL') or {} channel_info = info.get('CHANNEL') or {}
broadcaster_id = channel_info.get('BJID') or broadcaster_id broadcaster_id = channel_info.get('BJID') or broadcaster_id
broadcast_no = channel_info.get('BNO') or broadcast_no broadcast_no = channel_info.get('BNO') or broadcast_no
password_protected = channel_info.get('BPWD')
if not broadcast_no: if not broadcast_no:
raise ExtractorError(f'Unable to extract broadcast number ({broadcaster_id} may not be live)', expected=True) raise ExtractorError(f'Unable to extract broadcast number ({broadcaster_id} may not be live)', expected=True)
if password_protected == 'Y' and password is None:
raise ExtractorError(
'This livestream is protected by a password, use the --video-password option',
expected=True)
formats = [] formats = []
quality_key = qualities(self._QUALITIES) quality_key = qualities(self._QUALITIES)
for quality_str in self._QUALITIES: for quality_str in self._QUALITIES:
params = {
'bno': broadcast_no,
'stream_type': 'common',
'type': 'aid',
'quality': quality_str,
}
if password is not None:
params['pwd'] = password
aid_response = self._download_json( aid_response = self._download_json(
self._LIVE_API_URL, broadcast_no, fatal=False, self._LIVE_API_URL, broadcast_no, fatal=False,
data=urlencode_postdata({ data=urlencode_postdata(params),
'bno': broadcast_no,
'stream_type': 'common',
'type': 'aid',
'quality': quality_str,
}),
note=f'Downloading access token for {quality_str} stream', note=f'Downloading access token for {quality_str} stream',
errnote=f'Unable to download access token for {quality_str} stream') errnote=f'Unable to download access token for {quality_str} stream')
aid = traverse_obj(aid_response, ('CHANNEL', 'AID')) aid = traverse_obj(aid_response, ('CHANNEL', 'AID'))