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