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