]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/lecturio.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
20 class LecturioBaseIE(InfoExtractor
):
21 _API_BASE_URL
= 'https://app.lecturio.com/api/en/latest/html5/'
22 _LOGIN_URL
= 'https://app.lecturio.com/en/login'
23 _NETRC_MACHINE
= 'lecturio'
25 def _perform_login(self
, username
, password
):
27 _
, urlh
= self
._download
_webpage
_handle
(
28 self
._LOGIN
_URL
, None, 'Downloading login popup')
30 def is_logged(url_handle
):
31 return self
._LOGIN
_URL
not in url_handle
.geturl()
38 'signin[email]': username
,
39 'signin[password]': password
,
40 'signin[remember]': 'on',
43 response
, urlh
= self
._download
_webpage
_handle
(
44 self
._LOGIN
_URL
, None, 'Logging in',
45 data
=urlencode_postdata(login_form
))
47 # Logged in successfully
51 errors
= self
._html
_search
_regex
(
52 r
'(?s)<ul[^>]+class=["\']error_list
[^
>]+>(.+?
)</ul
>', response,
53 'errors
', default=None)
55 raise ExtractorError('Unable to login
: %s' % errors, expected=True)
56 raise ExtractorError('Unable to log
in')
59 class LecturioIE(LecturioBaseIE):
63 app\.lecturio\.com/([^/]+/(?P<nt>[^/?#&]+)\.lecture|(?:\#/)?lecture/c/\d+/(?P<id>\d+))|
64 (?:www\.)?lecturio\.de/[^/]+/(?P<nt_de>[^/?#&]+)\.vortrag
68 'url
': 'https
://app
.lecturio
.com
/medical
-courses
/important
-concepts
-and-terms
-introduction
-to
-microbiology
.lecture
#tab/videos',
69 'md5': '9a42cf1d8282a6311bf7211bbde26fde',
73 'title': 'Important Concepts and Terms — Introduction to Microbiology',
75 'skip': 'Requires lecturio account credentials',
77 'url': 'https://www.lecturio.de/jura/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)),
143 self
._sort
_formats
(formats
)
146 automatic_captions
= {}
147 captions
= video
.get('captions') or []
149 cc_url
= cc
.get('url')
152 cc_label
= cc
.get('translatedCode')
153 lang
= cc
.get('languageCode') or self
._search
_regex
(
154 r
'/([a-z]{2})_', cc_url
, 'lang',
155 default
=cc_label
.split()[0] if cc_label
else 'en')
156 original_lang
= self
._search
_regex
(
157 r
'/[a-z]{2}_([a-z]{2})_', cc_url
, 'original lang',
159 sub_dict
= (automatic_captions
160 if 'auto-translated' in cc_label
or original_lang
162 sub_dict
.setdefault(self
._CC
_LANGS
.get(lang
, lang
), []).append({
167 'id': lecture_id
or nt
,
170 'subtitles': subtitles
,
171 'automatic_captions': automatic_captions
,
175 class LecturioCourseIE(LecturioBaseIE
):
176 _VALID_URL
= r
'https://app\.lecturio\.com/(?:[^/]+/(?P<nt>[^/?#&]+)\.course|(?:#/)?course/c/(?P<id>\d+))'
178 'url': 'https://app.lecturio.com/medical-courses/microbiology-introduction.course#/',
180 'id': 'microbiology-introduction',
181 'title': 'Microbiology: Introduction',
182 'description': 'md5:13da8500c25880c6016ae1e6d78c386a',
184 'playlist_count': 45,
185 'skip': 'Requires lecturio account credentials',
187 'url': 'https://app.lecturio.com/#/course/c/6434',
188 'only_matching': True,
191 def _real_extract(self
, url
):
192 nt
, course_id
= self
._match
_valid
_url
(url
).groups()
193 display_id
= nt
or course_id
194 api_path
= 'courses/' + course_id
if course_id
else 'course/content/' + nt
+ '.json'
195 course
= self
._download
_json
(
196 self
._API
_BASE
_URL
+ api_path
, display_id
)
198 for lecture
in course
.get('lectures', []):
199 lecture_id
= str_or_none(lecture
.get('id'))
200 lecture_url
= lecture
.get('url')
202 lecture_url
= urljoin(url
, lecture_url
)
204 lecture_url
= 'https://app.lecturio.com/#/lecture/c/%s/%s' % (course_id
, lecture_id
)
205 entries
.append(self
.url_result(
206 lecture_url
, ie
=LecturioIE
.ie_key(), video_id
=lecture_id
))
207 return self
.playlist_result(
208 entries
, display_id
, course
.get('title'),
209 clean_html(course
.get('description')))
212 class LecturioDeCourseIE(LecturioBaseIE
):
213 _VALID_URL
= r
'https://(?:www\.)?lecturio\.de/[^/]+/(?P<id>[^/?#&]+)\.kurs'
215 'url': 'https://www.lecturio.de/jura/grundrechte.kurs',
216 'only_matching': True,
219 def _real_extract(self
, url
):
220 display_id
= self
._match
_id
(url
)
222 webpage
= self
._download
_webpage
(url
, display_id
)
225 for mobj
in re
.finditer(
226 r
'(?s)<td[^>]+\bdata-lecture-id=["\'](?P
<id>\d
+).+?
\bhref
=(["\'])(?P<url>(?:(?!\2).)+\.vortrag)\b[^>]+>',
228 lecture_url = urljoin(url, mobj.group('url'))
229 lecture_id = mobj.group('id')
230 entries.append(self.url_result(
231 lecture_url, ie=LecturioIE.ie_key(), video_id=lecture_id))
233 title = self._search_regex(
234 r'<h1[^>]*>([^<]+)', webpage, 'title', default=None)
236 return self.playlist_result(entries, display_id, title)