]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/lecturio.py
24f78d928449b999f09acec8337297fa62da8f55
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
21 class LecturioBaseIE(InfoExtractor
):
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 compat_str(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<id>[^/?#&]+)\.lecture|
71 (?:www\.)?lecturio\.de/[^/]+/(?P<id_de>[^/?#&]+)\.vortrag
75 'url
': 'https
://app
.lecturio
.com
/medical
-courses
/important
-concepts
-and-terms
-introduction
-to
-microbiology
.lecture
#tab/videos',
76 'md5': 'f576a797a5b7a5e4e4bbdfc25a6a6870',
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,
97 def _real_extract(self
, url
):
98 mobj
= re
.match(self
._VALID
_URL
, url
)
99 display_id
= mobj
.group('id') or mobj
.group('id_de')
101 webpage
= self
._download
_webpage
(
102 'https://app.lecturio.com/en/lecture/%s/player.html' % display_id
,
105 lecture_id
= self
._search
_regex
(
106 r
'lecture_id\s*=\s*(?:L_)?(\d+)', webpage
, 'lecture id')
108 api_url
= self
._search
_regex
(
109 r
'lectureDataLink\s*:\s*(["\'])(?P
<url
>(?
:(?
!\
1).)+)\
1', webpage,
110 'api url
', group='url
')
112 video = self._download_json(api_url, display_id)
114 title = video['title
'].strip()
117 for format_ in video['content
']['media
']:
118 if not isinstance(format_, dict):
120 file_ = format_.get('file')
123 ext = determine_ext(file_)
125 # smil contains only broken RTMP formats anyway
127 file_url = url_or_none(file_)
130 label = str_or_none(format_.get('label
'))
131 filesize = int_or_none(format_.get('fileSize
'))
135 'filesize
': float_or_none(filesize, invscale=1000)
137 self._sort_formats(formats)
140 automatic_captions = {}
141 cc = self._parse_json(
143 r'subtitleUrls\s
*:\s
*({.+?
})\s
*,', webpage, 'subtitles
',
144 default='{}'), display_id, fatal=False)
145 for cc_label, cc_url in cc.items():
146 cc_url = url_or_none(cc_url)
149 lang = self._search_regex(
150 r'/([a
-z
]{2}
)_
', cc_url, 'lang
',
151 default=cc_label.split()[0] if cc_label else 'en
')
152 original_lang = self._search_regex(
153 r'/[a
-z
]{2}
_([a
-z
]{2}
)_
', cc_url, 'original lang
',
155 sub_dict = (automatic_captions
156 if 'auto
-translated
' in cc_label or original_lang
158 sub_dict.setdefault(self._CC_LANGS.get(lang, lang), []).append({
166 'subtitles
': subtitles,
167 'automatic_captions
': automatic_captions,
171 class LecturioCourseIE(LecturioBaseIE):
172 _VALID_URL = r'https
://app\
.lecturio\
.com
/[^
/]+/(?P
<id>[^
/?
#&]+)\.course'
174 'url': 'https://app.lecturio.com/medical-courses/microbiology-introduction.course#/',
176 'id': 'microbiology-introduction',
177 'title': 'Microbiology: Introduction',
179 'playlist_count': 45,
180 'skip': 'Requires lecturio account credentials',
183 def _real_extract(self
, url
):
184 display_id
= self
._match
_id
(url
)
186 webpage
= self
._download
_webpage
(url
, display_id
)
189 for mobj
in re
.finditer(
190 r
'(?s)<[^>]+\bdata-url=(["\'])(?
:(?
!\
1).)+\
.lecture
\b[^
>]+>',
192 params = extract_attributes(mobj.group(0))
193 lecture_url = urljoin(url, params.get('data
-url
'))
194 lecture_id = params.get('data
-id')
195 entries.append(self.url_result(
196 lecture_url, ie=LecturioIE.ie_key(), video_id=lecture_id))
198 title = self._search_regex(
199 r'<span
[^
>]+class=["\']content-title[^>]+>([^<]+)', webpage,
200 'title', default=None)
202 return self.playlist_result(entries, display_id, title)
205 class LecturioDeCourseIE(LecturioBaseIE):
206 _VALID_URL = r'https://(?:www\.)?lecturio\.de/[^/]+/(?P<id>[^/?#&]+)\.kurs'
208 'url': 'https://www.lecturio.de/jura/grundrechte.kurs',
209 'only_matching': True,
212 def _real_extract(self, url):
213 display_id = self._match_id(url)
215 webpage = self._download_webpage(url, display_id)
218 for mobj in re.finditer(
219 r'(?s)<td[^>]+\bdata-lecture-id=["\'](?P
<id>\d
+).+?
\bhref
=(["\'])(?P<url>(?:(?!\2).)+\.vortrag)\b[^>]+>',
221 lecture_url = urljoin(url, mobj.group('url'))
222 lecture_id = mobj.group('id')
223 entries.append(self.url_result(
224 lecture_url, ie=LecturioIE.ie_key(), video_id=lecture_id))
226 title = self._search_regex(
227 r'<h1[^>]*>([^<]+)', webpage, 'title', default=None)
229 return self.playlist_result(entries, display_id, title)