From 5dee3ad037d197d5efb35bac6819d36ba19a9974 Mon Sep 17 00:00:00 2001 From: Luc Ritchie Date: Fri, 11 Feb 2022 09:15:59 -0500 Subject: [PATCH] [afreecatv] Support password-protected livestreams (#2738) Authored by: wlritchi --- yt_dlp/extractor/afreecatv.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/yt_dlp/extractor/afreecatv.py b/yt_dlp/extractor/afreecatv.py index 80853487e..f25fc47fa 100644 --- a/yt_dlp/extractor/afreecatv.py +++ b/yt_dlp/extractor/afreecatv.py @@ -416,26 +416,35 @@ class AfreecaTVLiveIE(AfreecaTVIE): def _real_extract(self, url): 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, data=urlencode_postdata({'bid': broadcaster_id})) or {} channel_info = info.get('CHANNEL') or {} broadcaster_id = channel_info.get('BJID') or broadcaster_id broadcast_no = channel_info.get('BNO') or broadcast_no + password_protected = channel_info.get('BPWD') if not broadcast_no: 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 = [] quality_key = qualities(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( self._LIVE_API_URL, broadcast_no, fatal=False, - data=urlencode_postdata({ - 'bno': broadcast_no, - 'stream_type': 'common', - 'type': 'aid', - 'quality': quality_str, - }), + data=urlencode_postdata(params), note=f'Downloading access token for {quality_str} stream', errnote=f'Unable to download access token for {quality_str} stream') aid = traverse_obj(aid_response, ('CHANNEL', 'AID'))