zoom.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. int_or_none,
  5. js_to_json,
  6. parse_filesize,
  7. parse_resolution,
  8. str_or_none,
  9. traverse_obj,
  10. url_basename,
  11. urlencode_postdata,
  12. urljoin,
  13. )
  14. class ZoomIE(InfoExtractor):
  15. IE_NAME = 'zoom'
  16. _VALID_URL = r'(?P<base_url>https?://(?:[^.]+\.)?zoom\.us/)rec(?:ording)?/(?P<type>play|share)/(?P<id>[\w.-]+)'
  17. _TESTS = [{
  18. 'url': 'https://economist.zoom.us/rec/play/dUk_CNBETmZ5VA2BwEl-jjakPpJ3M1pcfVYAPRsoIbEByGsLjUZtaa4yCATQuOL3der8BlTwxQePl_j0.EImBkXzTIaPvdZO5',
  19. 'md5': 'ab445e8c911fddc4f9adc842c2c5d434',
  20. 'info_dict': {
  21. 'id': 'dUk_CNBETmZ5VA2BwEl-jjakPpJ3M1pcfVYAPRsoIbEByGsLjUZtaa4yCATQuOL3der8BlTwxQePl_j0.EImBkXzTIaPvdZO5',
  22. 'ext': 'mp4',
  23. 'title': 'China\'s "two sessions" and the new five-year plan',
  24. },
  25. 'skip': 'Recording requires email authentication to access',
  26. }, {
  27. # play URL
  28. 'url': 'https://ffgolf.zoom.us/rec/play/qhEhXbrxq1Zoucx8CMtHzq1Z_2YZRPVCqWK_K-2FkEGRsSLDeOX8Tu4P6jtjZcRry8QhIbvKZdtr4UNo.QcPn2debFskI9whJ',
  29. 'md5': '2c4b1c4e5213ebf9db293e88d9385bee',
  30. 'info_dict': {
  31. 'id': 'qhEhXbrxq1Zoucx8CMtHzq1Z_2YZRPVCqWK_K-2FkEGRsSLDeOX8Tu4P6jtjZcRry8QhIbvKZdtr4UNo.QcPn2debFskI9whJ',
  32. 'ext': 'mp4',
  33. 'title': 'Prépa AF2023 - Séance 5 du 11 avril - R20/VM/GO',
  34. },
  35. }, {
  36. # share URL
  37. 'url': 'https://us02web.zoom.us/rec/share/hkUk5Zxcga0nkyNGhVCRfzkA2gX_mzgS3LpTxEEWJz9Y_QpIQ4mZFOUx7KZRZDQA.9LGQBdqmDAYgiZ_8',
  38. 'md5': '90fdc7cfcaee5d52d1c817fc03c43c9b',
  39. 'info_dict': {
  40. 'id': 'hkUk5Zxcga0nkyNGhVCRfzkA2gX_mzgS3LpTxEEWJz9Y_QpIQ4mZFOUx7KZRZDQA.9LGQBdqmDAYgiZ_8',
  41. 'ext': 'mp4',
  42. 'title': 'Timea Andrea Lelik\'s Personal Meeting Room',
  43. },
  44. 'skip': 'This recording has expired',
  45. }, {
  46. # view_with_share URL
  47. 'url': 'https://cityofdetroit.zoom.us/rec/share/VjE-5kW3xmgbEYqR5KzRgZ1OFZvtMtiXk5HyRJo5kK4m5PYE6RF4rF_oiiO_9qaM.UTAg1MI7JSnF3ZjX',
  48. 'md5': 'bdc7867a5934c151957fb81321b3c024',
  49. 'info_dict': {
  50. 'id': 'VjE-5kW3xmgbEYqR5KzRgZ1OFZvtMtiXk5HyRJo5kK4m5PYE6RF4rF_oiiO_9qaM.UTAg1MI7JSnF3ZjX',
  51. 'ext': 'mp4',
  52. 'title': 'February 2022 Detroit Revenue Estimating Conference',
  53. 'duration': 7299,
  54. 'formats': 'mincount:3',
  55. },
  56. }]
  57. def _get_page_data(self, webpage, video_id):
  58. return self._search_json(
  59. r'window\.__data__\s*=', webpage, 'data', video_id, transform_source=js_to_json)
  60. def _get_real_webpage(self, url, base_url, video_id, url_type):
  61. webpage = self._download_webpage(url, video_id, note=f'Downloading {url_type} webpage')
  62. try:
  63. form = self._form_hidden_inputs('password_form', webpage)
  64. except ExtractorError:
  65. return webpage
  66. password = self.get_param('videopassword')
  67. if not password:
  68. raise ExtractorError(
  69. 'This video is protected by a passcode, use the --video-password option', expected=True)
  70. is_meeting = form.get('useWhichPasswd') == 'meeting'
  71. validation = self._download_json(
  72. base_url + 'rec/validate%s_passwd' % ('_meet' if is_meeting else ''),
  73. video_id, 'Validating passcode', 'Wrong passcode', data=urlencode_postdata({
  74. 'id': form[('meet' if is_meeting else 'file') + 'Id'],
  75. 'passwd': password,
  76. 'action': form.get('action'),
  77. }))
  78. if not validation.get('status'):
  79. raise ExtractorError(validation['errorMessage'], expected=True)
  80. return self._download_webpage(url, video_id, note=f'Re-downloading {url_type} webpage')
  81. def _real_extract(self, url):
  82. base_url, url_type, video_id = self._match_valid_url(url).group('base_url', 'type', 'id')
  83. query = {}
  84. if url_type == 'share':
  85. webpage = self._get_real_webpage(url, base_url, video_id, 'share')
  86. meeting_id = self._get_page_data(webpage, video_id)['meetingId']
  87. redirect_path = self._download_json(
  88. f'{base_url}nws/recording/1.0/play/share-info/{meeting_id}',
  89. video_id, note='Downloading share info JSON')['result']['redirectUrl']
  90. url = urljoin(base_url, redirect_path)
  91. query['continueMode'] = 'true'
  92. webpage = self._get_real_webpage(url, base_url, video_id, 'play')
  93. file_id = self._get_page_data(webpage, video_id)['fileId']
  94. if not file_id:
  95. # When things go wrong, file_id can be empty string
  96. raise ExtractorError('Unable to extract file ID')
  97. data = self._download_json(
  98. f'{base_url}nws/recording/1.0/play/info/{file_id}', video_id, query=query,
  99. note='Downloading play info JSON')['result']
  100. subtitles = {}
  101. for _type in ('transcript', 'cc', 'chapter'):
  102. if data.get(f'{_type}Url'):
  103. subtitles[_type] = [{
  104. 'url': urljoin(base_url, data[f'{_type}Url']),
  105. 'ext': 'vtt',
  106. }]
  107. formats = []
  108. if data.get('viewMp4Url'):
  109. formats.append({
  110. 'format_note': 'Camera stream',
  111. 'url': data['viewMp4Url'],
  112. 'width': int_or_none(traverse_obj(data, ('viewResolvtions', 0))),
  113. 'height': int_or_none(traverse_obj(data, ('viewResolvtions', 1))),
  114. 'format_id': 'view',
  115. 'ext': 'mp4',
  116. 'filesize_approx': parse_filesize(str_or_none(traverse_obj(data, ('recording', 'fileSizeInMB')))),
  117. 'preference': 0,
  118. })
  119. if data.get('shareMp4Url'):
  120. formats.append({
  121. 'format_note': 'Screen share stream',
  122. 'url': data['shareMp4Url'],
  123. 'width': int_or_none(traverse_obj(data, ('shareResolvtions', 0))),
  124. 'height': int_or_none(traverse_obj(data, ('shareResolvtions', 1))),
  125. 'format_id': 'share',
  126. 'ext': 'mp4',
  127. 'preference': -1,
  128. })
  129. view_with_share_url = data.get('viewMp4WithshareUrl')
  130. if view_with_share_url:
  131. formats.append({
  132. **parse_resolution(self._search_regex(
  133. r'_(\d+x\d+)\.mp4', url_basename(view_with_share_url), 'resolution', default=None)),
  134. 'format_note': 'Screen share with camera',
  135. 'url': view_with_share_url,
  136. 'format_id': 'view_with_share',
  137. 'ext': 'mp4',
  138. 'preference': 1,
  139. })
  140. return {
  141. 'id': video_id,
  142. 'title': str_or_none(traverse_obj(data, ('meet', 'topic'))),
  143. 'duration': int_or_none(data.get('duration')),
  144. 'subtitles': subtitles,
  145. 'formats': formats,
  146. 'http_headers': {
  147. 'Referer': base_url,
  148. },
  149. }