1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from .wistia
import WistiaIE
18 class TeachableBaseIE(InfoExtractor
):
19 _NETRC_MACHINE
= 'teachable'
20 _URL_PREFIX
= 'teachable:'
23 # Only notable ones here
24 'v1.upskillcourses.com': 'upskill',
25 'gns3.teachable.com': 'gns3',
26 'academyhacker.com': 'academyhacker',
27 'stackskills.com': 'stackskills',
28 'market.saleshacker.com': 'saleshacker',
29 'learnability.org': 'learnability',
30 'edurila.com': 'edurila',
31 'courses.workitdaily.com': 'workitdaily',
34 _VALID_URL_SUB_TUPLE
= (_URL_PREFIX
, '|'.join(re
.escape(site
) for site
in _SITES
.keys()))
36 def _real_initialize(self
):
37 self
._logged
_in
= False
39 def _login(self
, site
):
43 username
, password
= self
._get
_login
_info
(
44 netrc_machine
=self
._SITES
.get(site
, site
))
48 login_page
, urlh
= self
._download
_webpage
_handle
(
49 'https://%s/sign_in' % site
, None,
50 'Downloading %s login page' % site
)
52 def is_logged(webpage
):
53 return any(re
.search(p
, webpage
) for p
in (
54 r
'class=["\']user
-signout
',
55 r'<a
[^
>]+\bhref
=["\']/sign_out',
58 if is_logged(login_page):
59 self._logged_in = True
62 login_url = urlh.geturl()
64 login_form = self._hidden_inputs(login_page)
67 'user[email]': username,
68 'user[password]': password,
71 post_url = self._search_regex(
72 r'<form[^>]+action=(["\'])(?P
<url
>(?
:(?
!\
1).)+)\
1', login_page,
73 'post url
', default=login_url, group='url
')
75 if not post_url.startswith('http
'):
76 post_url = urljoin(login_url, post_url)
78 response = self._download_webpage(
79 post_url, None, 'Logging
in to
%s' % site,
80 data=urlencode_postdata(login_form),
82 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
',
86 if '>I accept the new Privacy Policy
<' in response:
88 'Unable to login
: %s asks you to accept new Privacy Policy
. '
89 'Go to https
://%s/ and accept
.' % (site, site), expected=True)
92 if is_logged(response):
93 self._logged_in = True
96 message = get_element_by_class('alert
', response)
97 if message is not None:
99 'Unable to login
: %s' % clean_html(message), expected=True)
101 raise ExtractorError('Unable to log
in')
104 class TeachableIE(TeachableBaseIE):
105 _VALID_URL = r'''(?x)
107 %shttps?://(?P<site_t>[^/]+)|
108 https?://(?:www\.)?(?P<site>%s)
110 /courses/[^/]+/lectures/(?P<id>\d+)
111 ''' % TeachableBaseIE._VALID_URL_SUB_TUPLE
114 'url
': 'https
://gns3
.teachable
.com
/courses
/gns3
-certified
-associate
/lectures
/6842364',
119 'description
': 'md5
:071463ff08b86c208811130ea1c2464c
',
121 'timestamp
': 1542315762,
122 'upload_date
': '20181115',
123 'chapter
': 'Welcome
',
127 'skip_download
': True,
130 'url
': 'http
://v1
.upskillcourses
.com
/courses
/119763/lectures
/1747100',
131 'only_matching
': True,
133 'url
': 'https
://gns3
.teachable
.com
/courses
/423415/lectures
/6885939',
134 'only_matching
': True,
136 'url
': 'teachable
:https
://v1
.upskillcourses
.com
/courses
/essential
-web
-developer
-course
/lectures
/1747100',
137 'only_matching
': True,
141 def _is_teachable(webpage):
142 return 'teachableTracker
.linker
:autoLink
' in webpage and re.search(
143 r'<link
[^
>]+href
=["\']https?://process\.fs\.teachablecdn\.com',
147 def _extract_url(webpage, source_url):
148 if not TeachableIE._is_teachable(webpage):
150 if re.match(r'https?://[^/]+/(?:courses|p)', source_url):
151 return '%s%s' % (TeachableBaseIE._URL_PREFIX, source_url)
153 def _real_extract(self, url):
154 mobj = re.match(self._VALID_URL, url)
155 site = mobj.group('site') or mobj.group('site_t')
156 video_id = mobj.group('id')
160 prefixed = url.startswith(self._URL_PREFIX)
162 url = url[len(self._URL_PREFIX):]
164 webpage = self._download_webpage(url, video_id)
166 wistia_urls = WistiaIE._extract_urls(webpage)
168 if any(re.search(p, webpage) for p in (
169 r'class=["\']lecture
-contents
-locked
',
170 r'>\s
*Lecture contents locked
',
171 r'id=["\']lecture-locked',
172 # https://academy.tailoredtutors.co.uk/courses/108779/lectures/1955313
173 r'class=["\'](?
:inner
-)?lesson
-locked
',
174 r'>LESSON LOCKED
<')):
175 self.raise_login_required('Lecture contents locked
')
176 raise ExtractorError('Unable to find video URL
')
178 title = self._og_search_title(webpage, default=None)
181 chapter_number = None
182 section_item = self._search_regex(
183 r'(?s
)(?P
<li
><li
[^
>]+\bdata
-lecture
-id=["\']%s[^>]+>.+?</li>)' % video_id,
184 webpage, 'section item', default=None, group='li')
186 chapter_number = int_or_none(self._search_regex(
187 r'data-ss-position=["\'](\d
+)', section_item, 'section
id',
189 if chapter_number is not None:
192 r'(?s
)<div
[^
>]+\bclass
=["\']section-title[^>]+>(.+?)</div>', webpage):
193 section = strip_or_none(clean_html(s))
197 sections.append(section)
198 if chapter_number <= len(sections):
199 chapter = sections[chapter_number - 1]
202 '_type': 'url_transparent',
204 'ie_key': WistiaIE.ie_key(),
207 'chapter_number': chapter_number,
208 } for wistia_url in wistia_urls]
210 return self.playlist_result(entries, video_id, title)
213 class TeachableCourseIE(TeachableBaseIE):
214 _VALID_URL = r'''(?x)
216 %shttps?://(?P<site_t>[^/]+)|
217 https?://(?:www\.)?(?P<site>%s)
219 /(?:courses|p)/(?:enrolled/)?(?P<id>[^/?#&]+)
220 ''' % TeachableBaseIE._VALID_URL_SUB_TUPLE
222 'url': 'http://v1.upskillcourses.com/courses/essential-web-developer-course/',
224 'id': 'essential-web-developer-course',
225 'title': 'The Essential Web Developer Course (Free)',
227 'playlist_count': 192,
229 'url': 'http://v1.upskillcourses.com/courses/119763/',
230 'only_matching': True,
232 'url': 'http://v1.upskillcourses.com/courses/enrolled/119763',
233 'only_matching': True,
235 'url': 'https://gns3.teachable.com/courses/enrolled/423415',
236 'only_matching': True,
238 'url': 'teachable:https://learn.vrdev.school/p/gear-vr-developer-mini',
239 'only_matching': True,
241 'url': 'teachable:https://filmsimplified.com/p/davinci-resolve-15-crash-course',
242 'only_matching': True,
246 def suitable(cls, url):
247 return False if TeachableIE.suitable(url) else super(
248 TeachableCourseIE, cls).suitable(url)
250 def _real_extract(self, url):
251 mobj = re.match(self._VALID_URL, url)
252 site = mobj.group('site') or mobj.group('site_t')
253 course_id = mobj.group('id')
257 prefixed = url.startswith(self._URL_PREFIX)
259 prefix = self._URL_PREFIX
260 url = url[len(prefix):]
262 webpage = self._download_webpage(url, course_id)
264 url_base = 'https://%s/' % site
268 for mobj in re.finditer(
269 r'(?s)(?P<li><li[^>]+class=(["\'])(?
:(?
!\
2).)*?section
-item
[^
>]+>.+?
</li
>)',
271 li = mobj.group('li
')
272 if 'fa
-youtube
-play
' not in li:
274 lecture_url = self._search_regex(
275 r'<a
[^
>]+href
=(["\'])(?P<url>(?:(?!\1).)+)\1', li,
276 'lecture url', default=None, group='url')
279 lecture_id = self._search_regex(
280 r'/lectures/(\d+)', lecture_url, 'lecture id', default=None)
281 title = self._html_search_regex(
282 r'<span[^>]+class=["\']lecture
-name
[^
>]+>([^
<]+)', li,
283 'title
', default=None)
284 entry_url = urljoin(url_base, lecture_url)
286 entry_url = self._URL_PREFIX + entry_url
290 ie=TeachableIE.ie_key(), video_id=lecture_id,
291 video_title=clean_html(title)))
293 course_title = self._html_search_regex(
294 (r'(?s
)<img
[^
>]+class=["\']course-image[^>]+>\s*<h\d>(.+?)</h',
295 r'(?s)<h\d[^>]+class=["\']course
-title
[^
>]+>(.+?
)</h
'),
296 webpage, 'course title
', fatal=False)
298 return self.playlist_result(entries, course_id, course_title)