youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

zoom.py (2658B)


      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 )
     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 = re.match(self._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._downloader.params.get('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         return {
     59             'id': play_id,
     60             'title': data['topic'],
     61             'url': data['viewMp4Url'],
     62             'width': int_or_none(data.get('viewResolvtionsWidth')),
     63             'height': int_or_none(data.get('viewResolvtionsHeight')),
     64             'http_headers': {
     65                 'Referer': base_url,
     66             },
     67             'filesize_approx': parse_filesize(data.get('fileSize')),
     68         }