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