From 00dcde728635633eee969ad4d498b9f233c4a94e Mon Sep 17 00:00:00 2001 From: bashonly <88596187+bashonly@users.noreply.github.com> Date: Wed, 27 Nov 2024 01:47:28 +0000 Subject: [PATCH] [ie/dropbox] Fix password-protected video extraction (#11636) Closes #11634 Authored by: bashonly --- yt_dlp/extractor/dropbox.py | 38 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/yt_dlp/extractor/dropbox.py b/yt_dlp/extractor/dropbox.py index c122096230..2bfeebc7cb 100644 --- a/yt_dlp/extractor/dropbox.py +++ b/yt_dlp/extractor/dropbox.py @@ -48,32 +48,30 @@ def _real_extract(self, url): webpage = self._download_webpage(url, video_id) fn = urllib.parse.unquote(url_basename(url)) title = os.path.splitext(fn)[0] - password = self.get_param('videopassword') + content_id = None for part in self._yield_decoded_parts(webpage): if '/sm/password' in part: - webpage = self._download_webpage( - update_url('https://www.dropbox.com/sm/password', query=part.partition('?')[2]), video_id) + content_id = self._search_regex(r'content_id=([\w.+=/-]+)', part, 'content ID') break - if (self._og_search_title(webpage, default=None) == 'Dropbox - Password Required' - or 'Enter the password for this link' in webpage): - if password: - response = self._download_json( - 'https://www.dropbox.com/sm/auth', video_id, 'POSTing video password', - headers={'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, - data=urlencode_postdata({ - 'is_xhr': 'true', - 't': self._get_cookies('https://www.dropbox.com')['t'].value, - 'content_id': self._search_regex(r'content_id=([\w.+=/-]+)["\']', webpage, 'content id'), - 'password': password, - 'url': url, - })) - - if response.get('status') != 'authed': - raise ExtractorError('Invalid password', expected=True) - elif not self._get_cookies('https://dropbox.com').get('sm_auth'): + if content_id: + password = self.get_param('videopassword') + if not password: raise ExtractorError('Password protected video, use --video-password ', expected=True) + + response = self._download_json( + 'https://www.dropbox.com/sm/auth', video_id, 'POSTing video password', + data=urlencode_postdata({ + 'is_xhr': 'true', + 't': self._get_cookies('https://www.dropbox.com')['t'].value, + 'content_id': content_id, + 'password': password, + 'url': update_url(url, scheme='', netloc=''), + })) + if response.get('status') != 'authed': + raise ExtractorError('Invalid password', expected=True) + webpage = self._download_webpage(url, video_id) formats, subtitles = [], {}