]>
Commit | Line | Data |
---|---|---|
c6d4b82a DV |
1 | import re |
2 | import urllib.parse | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | ExtractorError, | |
7 | determine_ext, | |
8 | url_or_none, | |
9 | urlencode_postdata, | |
10 | ) | |
11 | ||
12 | ||
13 | class OwnCloudIE(InfoExtractor): | |
14 | _INSTANCES_RE = '|'.join(( | |
15 | r'(?:[^\.]+\.)?sciebo\.de', | |
16 | r'cloud\.uni-koblenz-landau\.de', | |
17 | )) | |
18 | _VALID_URL = rf'https?://(?:{_INSTANCES_RE})/s/(?P<id>[\w.-]+)' | |
19 | ||
20 | _TESTS = [ | |
21 | { | |
22 | 'url': 'https://ruhr-uni-bochum.sciebo.de/s/wWhqZzh9jTumVFN', | |
23 | 'info_dict': { | |
24 | 'id': 'wWhqZzh9jTumVFN', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'CmvpJST.mp4', | |
27 | }, | |
28 | }, | |
29 | { | |
30 | 'url': 'https://ruhr-uni-bochum.sciebo.de/s/WNDuFu0XuFtmm3f', | |
31 | 'info_dict': { | |
32 | 'id': 'WNDuFu0XuFtmm3f', | |
33 | 'ext': 'mp4', | |
34 | 'title': 'CmvpJST.mp4', | |
35 | }, | |
36 | 'params': { | |
37 | 'videopassword': '12345', | |
38 | }, | |
39 | }, | |
40 | ] | |
41 | ||
42 | def _real_extract(self, url): | |
43 | video_id = self._match_id(url) | |
44 | webpage, urlh = self._download_webpage_handle(url, video_id) | |
45 | ||
46 | if re.search(r'<label[^>]+for="password"', webpage): | |
47 | webpage = self._verify_video_password(webpage, urlh.geturl(), video_id) | |
48 | ||
49 | hidden_inputs = self._hidden_inputs(webpage) | |
50 | title = hidden_inputs.get('filename') | |
51 | parsed_url = urllib.parse.urlparse(url) | |
52 | ||
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), | |
59 | } | |
60 | ||
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) | |
67 | ||
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 | })) | |
74 | ||
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 |