]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/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 _real_initialize(self
):
29 username
, password
= self
._get
_login
_info
()
34 _
, urlh
= self
._download
_webpage
_handle
(
35 self
._LOGIN
_URL
, None, 'Downloading login popup')
37 def is_logged(url_handle
):
38 return self
._LOGIN
_URL
not in url_handle
.geturl()
45 'signin[email]': username
,
46 'signin[password]': password
,
47 'signin[remember]': 'on',
50 response
, urlh
= self
._download
_webpage
_handle
(
51 self
._LOGIN
_URL
, None, 'Logging in',
52 data
=urlencode_postdata(login_form
))
54 # Logged in successfully
58 errors
= self
._html
_search
_regex
(
59 r
'(?s)<ul[^>]+class=["\']error_list
[^
>]+>(.+?
)</ul
>', response,
60 'errors
', default=None)
62 raise ExtractorError('Unable to login
: %s' % errors, expected=True)
63 raise ExtractorError('Unable to log
in')
66 class LecturioIE(LecturioBaseIE):
70 app\.lecturio\.com/([^/]+/(?P<nt>[^/?#&]+)\.lecture|(?:\#/)?lecture/c/\d+/(?P<id>\d+))|
71 (?:www\.)?lecturio\.de/[^/]+/(?P<nt_de>[^/?#&]+)\.vortrag
75 'url
': 'https
://app
.lecturio
.com
/medical
-courses
/important
-concepts
-and-terms
-introduction
-to
-microbiology
.lecture
#tab/videos',
76 'md5': '9a42cf1d8282a6311bf7211bbde26fde',
80 'title': 'Important Concepts and Terms — Introduction to Microbiology',
82 'skip': 'Requires lecturio account credentials',
84 'url': 'https://www.lecturio.de/jura/oeffentliches-recht-staatsexamen.vortrag',
85 'only_matching': True,
87 'url': 'https://app.lecturio.com/#/lecture/c/6434/39634',
88 'only_matching': True,
105 def _real_extract(self
, url
):
106 mobj
= re
.match(self
._VALID
_URL
, url
)
107 nt
= mobj
.group('nt') or mobj
.group('nt_de')
108 lecture_id
= mobj
.group('id')
109 display_id
= nt
or lecture_id
110 api_path
= 'lectures/' + lecture_id
if lecture_id
else 'lecture/' + nt
+ '.json'
111 video
= self
._download
_json
(
112 self
._API
_BASE
_URL
+ api_path
, display_id
)
113 title
= video
['title'].strip()
115 pid
= video
.get('productId') or video
.get('uid')
117 spid
= pid
.split('_')
118 if spid
and len(spid
) == 2:
122 for format_
in video
['content']['media']:
123 if not isinstance(format_
, dict):
125 file_
= format_
.get('file')
128 ext
= determine_ext(file_
)
130 # smil contains only broken RTMP formats anyway
132 file_url
= url_or_none(file_
)
135 label
= str_or_none(format_
.get('label'))
136 filesize
= int_or_none(format_
.get('fileSize'))
140 'filesize': float_or_none(filesize
, invscale
=1000)
143 mobj
= re
.match(r
'(\d+)p\s*\(([^)]+)\)', label
)
146 'format_id': mobj
.group(2),
147 'height': int(mobj
.group(1)),
150 self
._sort
_formats
(formats
)
153 automatic_captions
= {}
154 captions
= video
.get('captions') or []
156 cc_url
= cc
.get('url')
159 cc_label
= cc
.get('translatedCode')
160 lang
= cc
.get('languageCode') or self
._search
_regex
(
161 r
'/([a-z]{2})_', cc_url
, 'lang',
162 default
=cc_label
.split()[0] if cc_label
else 'en')
163 original_lang
= self
._search
_regex
(
164 r
'/[a-z]{2}_([a-z]{2})_', cc_url
, 'original lang',
166 sub_dict
= (automatic_captions
167 if 'auto-translated' in cc_label
or original_lang
169 sub_dict
.setdefault(self
._CC
_LANGS
.get(lang
, lang
), []).append({
174 'id': lecture_id
or nt
,
177 'subtitles': subtitles
,
178 'automatic_captions': automatic_captions
,
182 class LecturioCourseIE(LecturioBaseIE
):
183 _VALID_URL
= r
'https://app\.lecturio\.com/(?:[^/]+/(?P<nt>[^/?#&]+)\.course|(?:#/)?course/c/(?P<id>\d+))'
185 'url': 'https://app.lecturio.com/medical-courses/microbiology-introduction.course#/',
187 'id': 'microbiology-introduction',
188 'title': 'Microbiology: Introduction',
189 'description': 'md5:13da8500c25880c6016ae1e6d78c386a',
191 'playlist_count': 45,
192 'skip': 'Requires lecturio account credentials',
194 'url': 'https://app.lecturio.com/#/course/c/6434',
195 'only_matching': True,
198 def _real_extract(self
, url
):
199 nt
, course_id
= re
.match(self
._VALID
_URL
, url
).groups()
200 display_id
= nt
or course_id
201 api_path
= 'courses/' + course_id
if course_id
else 'course/content/' + nt
+ '.json'
202 course
= self
._download
_json
(
203 self
._API
_BASE
_URL
+ api_path
, display_id
)
205 for lecture
in course
.get('lectures', []):
206 lecture_id
= str_or_none(lecture
.get('id'))
207 lecture_url
= lecture
.get('url')
209 lecture_url
= urljoin(url
, lecture_url
)
211 lecture_url
= 'https://app.lecturio.com/#/lecture/c/%s/%s' % (course_id
, lecture_id
)
212 entries
.append(self
.url_result(
213 lecture_url
, ie
=LecturioIE
.ie_key(), video_id
=lecture_id
))
214 return self
.playlist_result(
215 entries
, display_id
, course
.get('title'),
216 clean_html(course
.get('description')))
219 class LecturioDeCourseIE(LecturioBaseIE
):
220 _VALID_URL
= r
'https://(?:www\.)?lecturio\.de/[^/]+/(?P<id>[^/?#&]+)\.kurs'
222 'url': 'https://www.lecturio.de/jura/grundrechte.kurs',
223 'only_matching': True,
226 def _real_extract(self
, url
):
227 display_id
= self
._match
_id
(url
)
229 webpage
= self
._download
_webpage
(url
, display_id
)
232 for mobj
in re
.finditer(
233 r
'(?s)<td[^>]+\bdata-lecture-id=["\'](?P
<id>\d
+).+?
\bhref
=(["\'])(?P<url>(?:(?!\2).)+\.vortrag)\b[^>]+>',
235 lecture_url = urljoin(url, mobj.group('url'))
236 lecture_id = mobj.group('id')
237 entries.append(self.url_result(
238 lecture_url, ie=LecturioIE.ie_key(), video_id=lecture_id))
240 title = self._search_regex(
241 r'<h1[^>]*>([^<]+)', webpage, 'title', default=None)
243 return self.playlist_result(entries, display_id, title)