]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/ciscowebex.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / ciscowebex.py
index e1aae9bda6de12ec82fd3cfdd937957342167be4..d39347c82c10f9aa8a13c841b9ab8a6625c51b11 100644 (file)
@@ -1,5 +1,6 @@
 from .common import InfoExtractor
 from ..utils import (
+    ExtractorError,
     int_or_none,
     try_get,
     unified_timestamp,
@@ -32,17 +33,36 @@ def _real_extract(self, url):
         if rcid:
             webpage = self._download_webpage(url, None, note='Getting video ID')
             url = self._search_regex(self._VALID_URL, webpage, 'redirection url', group='url')
-        url = self._request_webpage(url, None, note='Resolving final URL').geturl()
+        url = self._request_webpage(url, None, note='Resolving final URL').url
         mobj = self._match_valid_url(url)
         subdomain = mobj.group('subdomain')
         siteurl = mobj.group('siteurl_1') or mobj.group('siteurl_2')
         video_id = mobj.group('id')
 
-        stream = self._download_json(
-            'https://%s.webex.com/webappng/api/v1/recordings/%s/stream' % (subdomain, video_id),
-            video_id, fatal=False, query={'siteurl': siteurl})
-        if not stream:
-            self.raise_login_required(method='cookies')
+        password = self.get_param('videopassword')
+
+        headers = {'Accept': 'application/json'}
+        if password:
+            headers['accessPwd'] = password
+
+        stream, urlh = self._download_json_handle(
+            f'https://{subdomain}.webex.com/webappng/api/v1/recordings/{video_id}/stream',
+            video_id, headers=headers, query={'siteurl': siteurl}, expected_status=(403, 429))
+
+        if urlh.status == 403:
+            if stream['code'] == 53004:
+                self.raise_login_required()
+            if stream['code'] == 53005:
+                if password:
+                    raise ExtractorError('Wrong password', expected=True)
+                raise ExtractorError(
+                    'This video is protected by a password, use the --video-password option', expected=True)
+            raise ExtractorError(f'{self.IE_NAME} said: {stream["code"]} - {stream["message"]}', expected=True)
+
+        if urlh.status == 429:
+            self.raise_login_required(
+                f'{self.IE_NAME} asks you to solve a CAPTCHA. Solve CAPTCHA in browser and',
+                method='cookies')
 
         video_id = stream.get('recordUUID') or video_id
 
@@ -72,16 +92,15 @@ def _real_extract(self, url):
                     'vcodec': 'none',
                     'acodec': 'mp3',
                 })
-        self._sort_formats(formats)
 
         return {
             'id': video_id,
             'title': stream['recordName'],
             'description': stream.get('description'),
             'uploader': stream.get('ownerDisplayName'),
-            'uploader_id': stream.get('ownerUserName') or stream.get('ownerId'),  # mail or id
+            'uploader_id': stream.get('ownerUserName') or stream.get('ownerId'),
             'timestamp': unified_timestamp(stream.get('createTime')),
             'duration': int_or_none(stream.get('duration'), 1000),
-            'webpage_url': 'https://%s.webex.com/recordingservice/sites/%s/recording/playback/%s' % (subdomain, siteurl, video_id),
+            'webpage_url': f'https://{subdomain}.webex.com/recordingservice/sites/{siteurl}/recording/playback/{video_id}',
             'formats': formats,
         }