]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/lecturio.py
3 from .common
import InfoExtractor
17 class LecturioBaseIE(InfoExtractor
):
18 _API_BASE_URL
= 'https://app.lecturio.com/api/en/latest/html5/'
19 _LOGIN_URL
= 'https://app.lecturio.com/en/login'
20 _NETRC_MACHINE
= 'lecturio'
22 def _perform_login(self
, username
, password
):
24 _
, urlh
= self
._download
_webpage
_handle
(
25 self
._LOGIN
_URL
, None, 'Downloading login popup')
27 def is_logged(url_handle
):
28 return self
._LOGIN
_URL
not in url_handle
.url
35 'signin[email]': username
,
36 'signin[password]': password
,
37 'signin[remember]': 'on',
40 response
, urlh
= self
._download
_webpage
_handle
(
41 self
._LOGIN
_URL
, None, 'Logging in',
42 data
=urlencode_postdata(login_form
))
44 # Logged in successfully
48 errors
= self
._html
_search
_regex
(
49 r
'(?s)<ul[^>]+class=["\']error_list
[^
>]+>(.+?
)</ul
>', response,
50 'errors
', default=None)
52 raise ExtractorError('Unable to login
: %s' % errors, expected=True)
53 raise ExtractorError('Unable to log
in')
56 class LecturioIE(LecturioBaseIE):
60 app\.lecturio\.com/([^/?#]+/(?P<nt>[^/?#&]+)\.lecture|(?:\#/)?lecture/c/\d+/(?P<id>\d+))|
61 (?:www\.)?lecturio\.de/(?:[^/?#]+/)+(?P<nt_de>[^/?#&]+)\.vortrag
65 'url
': 'https
://app
.lecturio
.com
/medical
-courses
/important
-concepts
-and-terms
-introduction
-to
-microbiology
.lecture
#tab/videos',
66 'md5': '9a42cf1d8282a6311bf7211bbde26fde',
70 'title': 'Important Concepts and Terms — Introduction to Microbiology',
72 'skip': 'Requires lecturio account credentials',
74 'url': 'https://www.lecturio.de/jura/oeffentliches-recht-staatsexamen.vortrag',
75 'only_matching': True,
77 'url': 'https://www.lecturio.de/jura/oeffentliches-recht-at-1-staatsexamen/oeffentliches-recht-staatsexamen.vortrag',
78 'only_matching': True,
80 'url': 'https://app.lecturio.com/#/lecture/c/6434/39634',
81 'only_matching': True,
98 def _real_extract(self
, url
):
99 mobj
= self
._match
_valid
_url
(url
)
100 nt
= mobj
.group('nt') or mobj
.group('nt_de')
101 lecture_id
= mobj
.group('id')
102 display_id
= nt
or lecture_id
103 api_path
= 'lectures/' + lecture_id
if lecture_id
else 'lecture/' + nt
+ '.json'
104 video
= self
._download
_json
(
105 self
._API
_BASE
_URL
+ api_path
, display_id
)
106 title
= video
['title'].strip()
108 pid
= video
.get('productId') or video
.get('uid')
110 spid
= pid
.split('_')
111 if spid
and len(spid
) == 2:
115 for format_
in video
['content']['media']:
116 if not isinstance(format_
, dict):
118 file_
= format_
.get('file')
121 ext
= determine_ext(file_
)
123 # smil contains only broken RTMP formats anyway
125 file_url
= url_or_none(file_
)
128 label
= str_or_none(format_
.get('label'))
129 filesize
= int_or_none(format_
.get('fileSize'))
133 'filesize': float_or_none(filesize
, invscale
=1000)
136 mobj
= re
.match(r
'(\d+)p\s*\(([^)]+)\)', label
)
139 'format_id': mobj
.group(2),
140 'height': int(mobj
.group(1)),
145 automatic_captions
= {}
146 captions
= video
.get('captions') or []
148 cc_url
= cc
.get('url')
151 cc_label
= cc
.get('translatedCode')
152 lang
= cc
.get('languageCode') or self
._search
_regex
(
153 r
'/([a-z]{2})_', cc_url
, 'lang',
154 default
=cc_label
.split()[0] if cc_label
else 'en')
155 original_lang
= self
._search
_regex
(
156 r
'/[a-z]{2}_([a-z]{2})_', cc_url
, 'original lang',
158 sub_dict
= (automatic_captions
159 if 'auto-translated' in cc_label
or original_lang
161 sub_dict
.setdefault(self
._CC
_LANGS
.get(lang
, lang
), []).append({
166 'id': lecture_id
or nt
,
169 'subtitles': subtitles
,
170 'automatic_captions': automatic_captions
,
174 class LecturioCourseIE(LecturioBaseIE
):
175 _VALID_URL
= r
'https://app\.lecturio\.com/(?:[^/]+/(?P<nt>[^/?#&]+)\.course|(?:#/)?course/c/(?P<id>\d+))'
177 'url': 'https://app.lecturio.com/medical-courses/microbiology-introduction.course#/',
179 'id': 'microbiology-introduction',
180 'title': 'Microbiology: Introduction',
181 'description': 'md5:13da8500c25880c6016ae1e6d78c386a',
183 'playlist_count': 45,
184 'skip': 'Requires lecturio account credentials',
186 'url': 'https://app.lecturio.com/#/course/c/6434',
187 'only_matching': True,
190 def _real_extract(self
, url
):
191 nt
, course_id
= self
._match
_valid
_url
(url
).groups()
192 display_id
= nt
or course_id
193 api_path
= 'courses/' + course_id
if course_id
else 'course/content/' + nt
+ '.json'
194 course
= self
._download
_json
(
195 self
._API
_BASE
_URL
+ api_path
, display_id
)
197 for lecture
in course
.get('lectures', []):
198 lecture_id
= str_or_none(lecture
.get('id'))
199 lecture_url
= lecture
.get('url')
201 lecture_url
= urljoin(url
, lecture_url
)
203 lecture_url
= 'https://app.lecturio.com/#/lecture/c/%s/%s' % (course_id
, lecture_id
)
204 entries
.append(self
.url_result(
205 lecture_url
, ie
=LecturioIE
.ie_key(), video_id
=lecture_id
))
206 return self
.playlist_result(
207 entries
, display_id
, course
.get('title'),
208 clean_html(course
.get('description')))
211 class LecturioDeCourseIE(LecturioBaseIE
):
212 _VALID_URL
= r
'https://(?:www\.)?lecturio\.de/[^/]+/(?P<id>[^/?#&]+)\.kurs'
214 'url': 'https://www.lecturio.de/jura/grundrechte.kurs',
215 'only_matching': True,
218 def _real_extract(self
, url
):
219 display_id
= self
._match
_id
(url
)
221 webpage
= self
._download
_webpage
(url
, display_id
)
224 for mobj
in re
.finditer(
225 r
'(?s)<td[^>]+\bdata-lecture-id=["\'](?P
<id>\d
+).+?
\bhref
=(["\'])(?P<url>(?:(?!\2).)+\.vortrag)\b[^>]+>',
227 lecture_url = urljoin(url, mobj.group('url'))
228 lecture_id = mobj.group('id')
229 entries.append(self.url_result(
230 lecture_url, ie=LecturioIE.ie_key(), video_id=lecture_id))
232 title = self._search_regex(
233 r'<h1[^>]*>([^<]+)', webpage, 'title', default=None)
235 return self.playlist_result(entries, display_id, title)