]> jfr.im git - yt-dlp.git/commitdiff
[afreecatv] Support password-protected livestreams (#2738)
authorLuc Ritchie <redacted>
Fri, 11 Feb 2022 14:15:59 +0000 (09:15 -0500)
committerGitHub <redacted>
Fri, 11 Feb 2022 14:15:59 +0000 (06:15 -0800)
Authored by: wlritchi

yt_dlp/extractor/afreecatv.py

index 80853487ef9be382de10a1b29cb796328d555527..f25fc47fab5151802c332c5954a7f51f17f6b7a8 100644 (file)
@@ -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'))