owncloud.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import re
  2. import urllib.parse
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. determine_ext,
  7. url_or_none,
  8. urlencode_postdata,
  9. )
  10. class OwnCloudIE(InfoExtractor):
  11. _INSTANCES_RE = '|'.join((
  12. r'(?:[^\.]+\.)?sciebo\.de',
  13. r'cloud\.uni-koblenz-landau\.de',
  14. ))
  15. _VALID_URL = rf'https?://(?:{_INSTANCES_RE})/s/(?P<id>[\w.-]+)'
  16. _TESTS = [
  17. {
  18. 'url': 'https://ruhr-uni-bochum.sciebo.de/s/wWhqZzh9jTumVFN',
  19. 'info_dict': {
  20. 'id': 'wWhqZzh9jTumVFN',
  21. 'ext': 'mp4',
  22. 'title': 'CmvpJST.mp4',
  23. },
  24. },
  25. {
  26. 'url': 'https://ruhr-uni-bochum.sciebo.de/s/WNDuFu0XuFtmm3f',
  27. 'info_dict': {
  28. 'id': 'WNDuFu0XuFtmm3f',
  29. 'ext': 'mp4',
  30. 'title': 'CmvpJST.mp4',
  31. },
  32. 'params': {
  33. 'videopassword': '12345',
  34. },
  35. },
  36. ]
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage, urlh = self._download_webpage_handle(url, video_id)
  40. if re.search(r'<label[^>]+for="password"', webpage):
  41. webpage = self._verify_video_password(webpage, urlh.url, video_id)
  42. hidden_inputs = self._hidden_inputs(webpage)
  43. title = hidden_inputs.get('filename')
  44. parsed_url = urllib.parse.urlparse(url)
  45. return {
  46. 'id': video_id,
  47. 'title': title,
  48. 'url': url_or_none(hidden_inputs.get('downloadURL')) or parsed_url._replace(
  49. path=urllib.parse.urljoin(parsed_url.path, 'download')).geturl(),
  50. 'ext': determine_ext(title),
  51. }
  52. def _verify_video_password(self, webpage, url, video_id):
  53. password = self.get_param('videopassword')
  54. if password is None:
  55. raise ExtractorError(
  56. 'This video is protected by a password, use the --video-password option',
  57. expected=True)
  58. validation_response = self._download_webpage(
  59. url, video_id, 'Validating Password', 'Wrong password?',
  60. data=urlencode_postdata({
  61. 'requesttoken': self._hidden_inputs(webpage)['requesttoken'],
  62. 'password': password,
  63. }))
  64. if re.search(r'<label[^>]+for="password"', validation_response):
  65. warning = self._search_regex(
  66. r'<div[^>]+class="warning">([^<]*)</div>', validation_response,
  67. 'warning', default='The password is wrong')
  68. raise ExtractorError(f'Opening the video failed, {self.IE_NAME} said: {warning!r}', expected=True)
  69. return validation_response