screencastify.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. from ..utils import traverse_obj, update_url_query
  4. class ScreencastifyIE(InfoExtractor):
  5. _VALID_URL = r'https?://watch\.screencastify\.com/v/(?P<id>[^/?#]+)'
  6. _TESTS = [{
  7. 'url': 'https://watch.screencastify.com/v/sYVkZip3quLKhHw4Ybk8',
  8. 'info_dict': {
  9. 'id': 'sYVkZip3quLKhHw4Ybk8',
  10. 'ext': 'mp4',
  11. 'title': 'Inserting and Aligning the Case Top and Bottom',
  12. 'description': '',
  13. 'uploader': 'Paul Gunn',
  14. 'extra_param_to_segment_url': str,
  15. },
  16. 'params': {
  17. 'skip_download': 'm3u8',
  18. },
  19. }]
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. info = self._download_json(
  23. f'https://umbrella.svc.screencastify.com/api/umbrellaService/watch/{video_id}', video_id)
  24. query_string = traverse_obj(info, ('manifest', 'auth', 'query'))
  25. query = urllib.parse.parse_qs(query_string)
  26. formats = []
  27. dash_manifest_url = traverse_obj(info, ('manifest', 'url'))
  28. if dash_manifest_url:
  29. formats.extend(
  30. self._extract_mpd_formats(
  31. dash_manifest_url, video_id, mpd_id='dash', query=query, fatal=False))
  32. hls_manifest_url = traverse_obj(info, ('manifest', 'hlsUrl'))
  33. if hls_manifest_url:
  34. formats.extend(
  35. self._extract_m3u8_formats(
  36. hls_manifest_url, video_id, ext='mp4', m3u8_id='hls', query=query, fatal=False))
  37. for f in formats:
  38. f['url'] = update_url_query(f['url'], query)
  39. return {
  40. 'id': video_id,
  41. 'title': info.get('title'),
  42. 'description': info.get('description'),
  43. 'uploader': info.get('userName'),
  44. 'formats': formats,
  45. 'extra_param_to_segment_url': query_string,
  46. }