[ie/dropbox] Fix password-protected video extraction (#11636)
[yt-dlp3.git] / yt_dlp / extractor / owncloud.py
blob79fd830bb32f31f102a5365feb0d33ad41352c42
1 import re
2 import urllib.parse
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 determine_ext,
8 url_or_none,
9 urlencode_postdata,
13 class OwnCloudIE(InfoExtractor):
14 _INSTANCES_RE = '|'.join((
15 r'(?:[^\.]+\.)?sciebo\.de',
16 r'cloud\.uni-koblenz-landau\.de',
18 _VALID_URL = rf'https?://(?:{_INSTANCES_RE})/s/(?P<id>[\w.-]+)'
20 _TESTS = [
22 'url': 'https://ruhr-uni-bochum.sciebo.de/s/wWhqZzh9jTumVFN',
23 'info_dict': {
24 'id': 'wWhqZzh9jTumVFN',
25 'ext': 'mp4',
26 'title': 'CmvpJST.mp4',
30 'url': 'https://ruhr-uni-bochum.sciebo.de/s/WNDuFu0XuFtmm3f',
31 'info_dict': {
32 'id': 'WNDuFu0XuFtmm3f',
33 'ext': 'mp4',
34 'title': 'CmvpJST.mp4',
36 'params': {
37 'videopassword': '12345',
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44 webpage, urlh = self._download_webpage_handle(url, video_id)
46 if re.search(r'<label[^>]+for="password"', webpage):
47 webpage = self._verify_video_password(webpage, urlh.url, video_id)
49 hidden_inputs = self._hidden_inputs(webpage)
50 title = hidden_inputs.get('filename')
51 parsed_url = urllib.parse.urlparse(url)
53 return {
54 'id': video_id,
55 'title': title,
56 'url': url_or_none(hidden_inputs.get('downloadURL')) or parsed_url._replace(
57 path=urllib.parse.urljoin(parsed_url.path, 'download')).geturl(),
58 'ext': determine_ext(title),
61 def _verify_video_password(self, webpage, url, video_id):
62 password = self.get_param('videopassword')
63 if password is None:
64 raise ExtractorError(
65 'This video is protected by a password, use the --video-password option',
66 expected=True)
68 validation_response = self._download_webpage(
69 url, video_id, 'Validating Password', 'Wrong password?',
70 data=urlencode_postdata({
71 'requesttoken': self._hidden_inputs(webpage)['requesttoken'],
72 'password': password,
73 }))
75 if re.search(r'<label[^>]+for="password"', validation_response):
76 warning = self._search_regex(
77 r'<div[^>]+class="warning">([^<]*)</div>', validation_response,
78 'warning', default='The password is wrong')
79 raise ExtractorError(f'Opening the video failed, {self.IE_NAME} said: {warning!r}', expected=True)
80 return validation_response