zoom.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. int_or_none,
  5. str_or_none,
  6. js_to_json,
  7. parse_filesize,
  8. urlencode_postdata,
  9. urljoin,
  10. )
  11. class ZoomIE(InfoExtractor):
  12. IE_NAME = 'zoom'
  13. _VALID_URL = r'(?P<base_url>https?://(?:[^.]+\.)?zoom.us/)rec(?:ording)?/(?:play|share)/(?P<id>[A-Za-z0-9_.-]+)'
  14. _TEST = {
  15. 'url': 'https://economist.zoom.us/rec/play/dUk_CNBETmZ5VA2BwEl-jjakPpJ3M1pcfVYAPRsoIbEByGsLjUZtaa4yCATQuOL3der8BlTwxQePl_j0.EImBkXzTIaPvdZO5',
  16. 'md5': 'ab445e8c911fddc4f9adc842c2c5d434',
  17. 'info_dict': {
  18. 'id': 'dUk_CNBETmZ5VA2BwEl-jjakPpJ3M1pcfVYAPRsoIbEByGsLjUZtaa4yCATQuOL3der8BlTwxQePl_j0.EImBkXzTIaPvdZO5',
  19. 'ext': 'mp4',
  20. 'title': 'China\'s "two sessions" and the new five-year plan',
  21. },
  22. 'skip': 'Recording requires email authentication to access',
  23. }
  24. def _real_extract(self, url):
  25. base_url, play_id = self._match_valid_url(url).groups()
  26. webpage = self._download_webpage(url, play_id)
  27. try:
  28. form = self._form_hidden_inputs('password_form', webpage)
  29. except ExtractorError:
  30. form = None
  31. if form:
  32. password = self.get_param('videopassword')
  33. if not password:
  34. raise ExtractorError(
  35. 'This video is protected by a passcode, use the --video-password option', expected=True)
  36. is_meeting = form.get('useWhichPasswd') == 'meeting'
  37. validation = self._download_json(
  38. base_url + 'rec/validate%s_passwd' % ('_meet' if is_meeting else ''),
  39. play_id, 'Validating passcode', 'Wrong passcode', data=urlencode_postdata({
  40. 'id': form[('meet' if is_meeting else 'file') + 'Id'],
  41. 'passwd': password,
  42. 'action': form.get('action'),
  43. }))
  44. if not validation.get('status'):
  45. raise ExtractorError(validation['errorMessage'], expected=True)
  46. webpage = self._download_webpage(url, play_id)
  47. data = self._parse_json(self._search_regex(
  48. r'(?s)window\.__data__\s*=\s*({.+?});',
  49. webpage, 'data'), play_id, js_to_json)
  50. subtitles = {}
  51. for _type in ('transcript', 'cc', 'chapter'):
  52. if data.get('%sUrl' % _type):
  53. subtitles[_type] = [{
  54. 'url': urljoin(base_url, data['%sUrl' % _type]),
  55. 'ext': 'vtt',
  56. }]
  57. formats = []
  58. if data.get('viewMp4Url'):
  59. formats.append({
  60. 'format_note': 'Camera stream',
  61. 'url': str_or_none(data.get('viewMp4Url')),
  62. 'width': int_or_none(data.get('viewResolvtionsWidth')),
  63. 'height': int_or_none(data.get('viewResolvtionsHeight')),
  64. 'format_id': str_or_none(data.get('recordingId')),
  65. 'ext': 'mp4',
  66. 'filesize_approx': parse_filesize(data.get('fileSize')),
  67. 'preference': 0
  68. })
  69. if data.get('shareMp4Url'):
  70. formats.append({
  71. 'format_note': 'Screen share stream',
  72. 'url': str_or_none(data.get('shareMp4Url')),
  73. 'width': int_or_none(data.get('shareResolvtionsWidth')),
  74. 'height': int_or_none(data.get('shareResolvtionsHeight')),
  75. 'format_id': str_or_none(data.get('shareVideoId')),
  76. 'ext': 'mp4',
  77. 'preference': -1
  78. })
  79. return {
  80. 'id': play_id,
  81. 'title': data.get('topic'),
  82. 'subtitles': subtitles,
  83. 'formats': formats,
  84. 'http_headers': {
  85. 'Referer': base_url,
  86. },
  87. }