screencastomatic.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. get_element_by_class,
  5. int_or_none,
  6. remove_start,
  7. strip_or_none,
  8. unified_strdate,
  9. urlencode_postdata,
  10. )
  11. class ScreencastOMaticIE(InfoExtractor):
  12. _VALID_URL = r'https?://screencast-o-matic\.com/(?:(?:watch|player)/|embed\?.*?\bsc=)(?P<id>[0-9a-zA-Z]+)'
  13. _TESTS = [{
  14. 'url': 'http://screencast-o-matic.com/watch/c2lD3BeOPl',
  15. 'md5': '483583cb80d92588f15ccbedd90f0c18',
  16. 'info_dict': {
  17. 'id': 'c2lD3BeOPl',
  18. 'ext': 'mp4',
  19. 'title': 'Welcome to 3-4 Philosophy @ DECV!',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'description': 'as the title says! also: some general info re 1) VCE philosophy and 2) distance learning.',
  22. 'duration': 369,
  23. 'upload_date': '20141216',
  24. },
  25. }, {
  26. 'url': 'http://screencast-o-matic.com/player/c2lD3BeOPl',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'http://screencast-o-matic.com/embed?ff=true&sc=cbV2r4Q5TL&fromPH=true&a=1',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(
  35. 'https://screencast-o-matic.com/player/' + video_id, video_id)
  36. if (self._html_extract_title(webpage) == 'Protected Content'
  37. or 'This video is private and requires a password' in webpage):
  38. password = self.get_param('videopassword')
  39. if not password:
  40. raise ExtractorError('Password protected video, use --video-password <password>', expected=True)
  41. form = self._search_regex(
  42. r'(?is)<form[^>]*>(?P<form>.+?)</form>', webpage, 'login form', group='form')
  43. form_data = self._hidden_inputs(form)
  44. form_data.update({
  45. 'scPassword': password,
  46. })
  47. webpage = self._download_webpage(
  48. 'https://screencast-o-matic.com/player/password', video_id, 'Logging in',
  49. data=urlencode_postdata(form_data))
  50. if '<small class="text-danger">Invalid password</small>' in webpage:
  51. raise ExtractorError('Unable to login: Invalid password', expected=True)
  52. info = self._parse_html5_media_entries(url, webpage, video_id)[0]
  53. info.update({
  54. 'id': video_id,
  55. 'title': get_element_by_class('overlayTitle', webpage),
  56. 'description': strip_or_none(get_element_by_class('overlayDescription', webpage)) or None,
  57. 'duration': int_or_none(self._search_regex(
  58. r'player\.duration\s*=\s*function\(\)\s*{\s*return\s+(\d+);\s*};',
  59. webpage, 'duration', default=None)),
  60. 'upload_date': unified_strdate(remove_start(
  61. get_element_by_class('overlayPublished', webpage), 'Published: ')),
  62. })
  63. return info