1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from .wistia
import WistiaIE
7 from ..compat
import compat_str
17 class TeachableBaseIE(InfoExtractor
):
18 _NETRC_MACHINE
= 'teachable'
19 _URL_PREFIX
= 'teachable:'
22 # Only notable ones here
23 'upskillcourses.com': 'upskill',
24 'academy.gns3.com': 'gns3',
25 'academyhacker.com': 'academyhacker',
26 'stackskills.com': 'stackskills',
27 'market.saleshacker.com': 'saleshacker',
28 'learnability.org': 'learnability',
29 'edurila.com': 'edurila',
30 'courses.workitdaily.com': 'workitdaily',
33 _VALID_URL_SUB_TUPLE
= (_URL_PREFIX
, '|'.join(re
.escape(site
) for site
in _SITES
.keys()))
35 def _real_initialize(self
):
36 self
._logged
_in
= False
38 def _login(self
, site
):
42 username
, password
= self
._get
_login
_info
(
43 netrc_machine
=self
._SITES
.get(site
, site
))
47 login_page
, urlh
= self
._download
_webpage
_handle
(
48 'https://%s/sign_in' % site
, None,
49 'Downloading %s login page' % site
)
51 def is_logged(webpage
):
52 return any(re
.search(p
, webpage
) for p
in (
53 r
'class=["\']user
-signout
',
54 r'<a
[^
>]+\bhref
=["\']/sign_out',
57 if is_logged(login_page):
58 self._logged_in = True
61 login_url = compat_str(urlh.geturl())
63 login_form = self._hidden_inputs(login_page)
66 'user[email]': username,
67 'user[password]': password,
70 post_url = self._search_regex(
71 r'<form[^>]+action=(["\'])(?P
<url
>(?
:(?
!\
1).)+)\
1', login_page,
72 'post url
', default=login_url, group='url
')
74 if not post_url.startswith('http
'):
75 post_url = urljoin(login_url, post_url)
77 response = self._download_webpage(
78 post_url, None, 'Logging
in to
%s' % site,
79 data=urlencode_postdata(login_form),
81 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
',
85 if '>I accept the new Privacy Policy
<' in response:
87 'Unable to login
: %s asks you to accept new Privacy Policy
. '
88 'Go to https
://%s/ and accept
.' % (site, site), expected=True)
91 if is_logged(response):
92 self._logged_in = True
95 message = get_element_by_class('alert
', response)
96 if message is not None:
98 'Unable to login
: %s' % clean_html(message), expected=True)
100 raise ExtractorError('Unable to log
in')
103 class TeachableIE(TeachableBaseIE):
104 _VALID_URL = r'''(?x)
106 %shttps?://(?P<site_t>[^/]+)|
107 https?://(?:www\.)?(?P<site>%s)
109 /courses/[^/]+/lectures/(?P<id>\d+)
110 ''' % TeachableBaseIE._VALID_URL_SUB_TUPLE
113 'url
': 'http
://upskillcourses
.com
/courses
/essential
-web
-developer
-course
/lectures
/1747100',
117 'title
': 'Welcome to the Course
!',
118 'description
': 'md5
:65edb0affa582974de4625b9cdea1107
',
120 'timestamp
': 1479846621,
121 'upload_date
': '20161122',
124 'skip_download
': True,
127 'url
': 'http
://upskillcourses
.com
/courses
/119763/lectures
/1747100',
128 'only_matching
': True,
130 'url
': 'https
://academy
.gns3
.com
/courses
/423415/lectures
/6885939',
131 'only_matching
': True,
133 'url
': 'teachable
:https
://upskillcourses
.com
/courses
/essential
-web
-developer
-course
/lectures
/1747100',
134 'only_matching
': True,
138 def _is_teachable(webpage):
139 return 'teachableTracker
.linker
:autoLink
' in webpage and re.search(
140 r'<link
[^
>]+href
=["\']https?://process\.fs\.teachablecdn\.com',
144 def _extract_url(webpage, source_url):
145 if not TeachableIE._is_teachable(webpage):
147 if re.match(r'https?://[^/]+/(?:courses|p)', source_url):
148 return '%s%s' % (TeachableBaseIE._URL_PREFIX, source_url)
150 def _real_extract(self, url):
151 mobj = re.match(self._VALID_URL, url)
152 site = mobj.group('site') or mobj.group('site_t')
153 video_id = mobj.group('id')
157 prefixed = url.startswith(self._URL_PREFIX)
159 url = url[len(self._URL_PREFIX):]
161 webpage = self._download_webpage(url, video_id)
163 wistia_url = WistiaIE._extract_url(webpage)
165 if any(re.search(p, webpage) for p in (
166 r'class=["\']lecture
-contents
-locked
',
167 r'>\s
*Lecture contents locked
',
168 r'id=["\']lecture-locked',
169 # https://academy.tailoredtutors.co.uk/courses/108779/lectures/1955313
170 r'class=["\'](?
:inner
-)?lesson
-locked
',
171 r'>LESSON LOCKED
<')):
172 self.raise_login_required('Lecture contents locked
')
173 raise ExtractorError('Unable to find video URL
')
175 title = self._og_search_title(webpage, default=None)
178 '_type
': 'url_transparent
',
180 'ie_key
': WistiaIE.ie_key(),
185 class TeachableCourseIE(TeachableBaseIE):
186 _VALID_URL = r'''(?x)
188 %shttps?://(?P<site_t>[^/]+)|
189 https?://(?:www\.)?(?P<site>%s)
191 /(?:courses|p)/(?:enrolled/)?(?P<id>[^/?#&]+)
192 ''' % TeachableBaseIE._VALID_URL_SUB_TUPLE
194 'url
': 'http
://upskillcourses
.com
/courses
/essential
-web
-developer
-course
/',
196 'id': 'essential
-web
-developer
-course
',
197 'title
': 'The Essential Web Developer
Course (Free
)',
199 'playlist_count
': 192,
201 'url
': 'http
://upskillcourses
.com
/courses
/119763/',
202 'only_matching
': True,
204 'url
': 'http
://upskillcourses
.com
/courses
/enrolled
/119763',
205 'only_matching
': True,
207 'url
': 'https
://academy
.gns3
.com
/courses
/enrolled
/423415',
208 'only_matching
': True,
210 'url
': 'teachable
:https
://learn
.vrdev
.school
/p
/gear
-vr
-developer
-mini
',
211 'only_matching
': True,
213 'url
': 'teachable
:https
://filmsimplified
.com
/p
/davinci
-resolve
-15-crash
-course
',
214 'only_matching
': True,
218 def suitable(cls, url):
219 return False if TeachableIE.suitable(url) else super(
220 TeachableCourseIE, cls).suitable(url)
222 def _real_extract(self, url):
223 mobj = re.match(self._VALID_URL, url)
224 site = mobj.group('site
') or mobj.group('site_t
')
225 course_id = mobj.group('id')
229 prefixed = url.startswith(self._URL_PREFIX)
231 prefix = self._URL_PREFIX
232 url = url[len(prefix):]
234 webpage = self._download_webpage(url, course_id)
236 url_base = 'https
://%s/' % site
240 for mobj in re.finditer(
241 r'(?s
)(?P
<li
><li
[^
>]+class=(["\'])(?:(?!\2).)*?section-item[^>]+>.+?</li>)',
243 li = mobj.group('li')
244 if 'fa-youtube-play' not in li:
246 lecture_url = self._search_regex(
247 r'<a[^>]+href=(["\'])(?P
<url
>(?
:(?
!\
1).)+)\
1', li,
248 'lecture url
', default=None, group='url
')
251 lecture_id = self._search_regex(
252 r'/lectures
/(\d
+)', lecture_url, 'lecture
id', default=None)
253 title = self._html_search_regex(
254 r'<span
[^
>]+class=["\']lecture-name[^>]+>([^<]+)', li,
255 'title', default=None)
256 entry_url = urljoin(url_base, lecture_url)
258 entry_url = self._URL_PREFIX + entry_url
262 ie=TeachableIE.ie_key(), video_id=lecture_id,
263 video_title=clean_html(title)))
265 course_title = self._html_search_regex(
266 (r'(?s)<img[^>]+class=["\']course
-image
[^
>]+>\s
*<h\d
>(.+?
)</h
',
267 r'(?s
)<h\d
[^
>]+class=["\']course-title[^>]+>(.+?)</h'),
268 webpage, 'course title', fatal=False)
270 return self.playlist_result(entries, course_id, course_title)