1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from .wistia import WistiaIE
16 class TeachableBaseIE(InfoExtractor):
17 _NETRC_MACHINE = 'teachable'
18 _URL_PREFIX = 'teachable:'
21 # Only notable ones here
22 'upskillcourses.com': 'upskill',
23 'academy.gns3.com': 'gns3',
24 'academyhacker.com': 'academyhacker',
25 'stackskills.com': 'stackskills',
26 'market.saleshacker.com': 'saleshacker',
27 'learnability.org': 'learnability',
28 'edurila.com': 'edurila',
29 'courses.workitdaily.com': 'workitdaily',
32 _VALID_URL_SUB_TUPLE = (_URL_PREFIX, '|'.join(re.escape(site) for site in _SITES.keys()))
34 def _real_initialize(self):
35 self._logged_in = False
37 def _login(self, site):
41 username, password = self._get_login_info(
42 netrc_machine=self._SITES.get(site, site))
46 login_page, urlh = self._download_webpage_handle(
47 'https://%s/sign_in' % site, None,
48 'Downloading %s login page' % site)
50 def is_logged(webpage):
51 return any(re.search(p, webpage) for p in (
52 r'class=["\']user-signout',
53 r'<a[^>]+\bhref=["\']/sign_out',
56 if is_logged(login_page):
57 self._logged_in = True
60 login_url = urlh.geturl()
62 login_form = self._hidden_inputs(login_page)
65 'user[email]': username,
66 'user[password]': password,
69 post_url = self._search_regex(
70 r'<form[^>]+action=(["\'])(?P<url>(?:(?!\1).)+)\1', login_page,
71 'post url', default=login_url, group='url')
73 if not post_url.startswith('http'):
74 post_url = urljoin(login_url, post_url)
76 response = self._download_webpage(
77 post_url, None, 'Logging in to %s' % site,
78 data=urlencode_postdata(login_form),
80 'Content-Type': 'application/x-www-form-urlencoded',
84 if '>I accept the new Privacy Policy<' in response:
86 'Unable to login: %s asks you to accept new Privacy Policy. '
87 'Go to https://%s/ and accept.' % (site, site), expected=True)
90 if is_logged(response):
91 self._logged_in = True
94 message = get_element_by_class('alert', response)
95 if message is not None:
97 'Unable to login: %s' % clean_html(message), expected=True)
99 raise ExtractorError('Unable to log in')
102 class TeachableIE(TeachableBaseIE):
103 _VALID_URL = r'''(?x)
105 %shttps?://(?P<site_t>[^/]+)|
106 https?://(?:www\.)?(?P<site>%s)
108 /courses/[^/]+/lectures/(?P<id>\d+)
109 ''' % TeachableBaseIE._VALID_URL_SUB_TUPLE
112 'url': 'http://upskillcourses.com/courses/essential-web-developer-course/lectures/1747100',
116 'title': 'Welcome to the Course!',
117 'description': 'md5:65edb0affa582974de4625b9cdea1107',
119 'timestamp': 1479846621,
120 'upload_date': '20161122',
123 'skip_download': True,
126 'url': 'http://upskillcourses.com/courses/119763/lectures/1747100',
127 'only_matching': True,
129 'url': 'https://academy.gns3.com/courses/423415/lectures/6885939',
130 'only_matching': True,
132 'url': 'teachable:https://upskillcourses.com/courses/essential-web-developer-course/lectures/1747100',
133 'only_matching': True,
137 def _is_teachable(webpage):
138 return 'teachableTracker.linker:autoLink' in webpage and re.search(
139 r'<link[^>]+href=["\']https?://process\.fs\.teachablecdn\.com',
143 def _extract_url(webpage, source_url):
144 if not TeachableIE._is_teachable(webpage):
146 if re.match(r'https?://[^/]+/(?:courses|p)', source_url):
147 return '%s%s' % (TeachableBaseIE._URL_PREFIX, source_url)
149 def _real_extract(self, url):
150 mobj = re.match(self._VALID_URL, url)
151 site = mobj.group('site') or mobj.group('site_t')
152 video_id = mobj.group('id')
156 prefixed = url.startswith(self._URL_PREFIX)
158 url = url[len(self._URL_PREFIX):]
160 webpage = self._download_webpage(url, video_id)
162 wistia_urls = WistiaIE._extract_urls(webpage)
164 if any(re.search(p, webpage) for p in (
165 r'class=["\']lecture-contents-locked',
166 r'>\s*Lecture contents locked',
167 r'id=["\']lecture-locked',
168 # https://academy.tailoredtutors.co.uk/courses/108779/lectures/1955313
169 r'class=["\'](?:inner-)?lesson-locked',
170 r'>LESSON LOCKED<')):
171 self.raise_login_required('Lecture contents locked')
172 raise ExtractorError('Unable to find video URL')
174 title = self._og_search_title(webpage, default=None)
177 '_type': 'url_transparent',
179 'ie_key': WistiaIE.ie_key(),
181 } for wistia_url in wistia_urls]
183 return self.playlist_result(entries, video_id, title)
186 class TeachableCourseIE(TeachableBaseIE):
187 _VALID_URL = r'''(?x)
189 %shttps?://(?P<site_t>[^/]+)|
190 https?://(?:www\.)?(?P<site>%s)
192 /(?:courses|p)/(?:enrolled/)?(?P<id>[^/?#&]+)
193 ''' % TeachableBaseIE._VALID_URL_SUB_TUPLE
195 'url': 'http://upskillcourses.com/courses/essential-web-developer-course/',
197 'id': 'essential-web-developer-course',
198 'title': 'The Essential Web Developer Course (Free)',
200 'playlist_count': 192,
202 'url': 'http://upskillcourses.com/courses/119763/',
203 'only_matching': True,
205 'url': 'http://upskillcourses.com/courses/enrolled/119763',
206 'only_matching': True,
208 'url': 'https://academy.gns3.com/courses/enrolled/423415',
209 'only_matching': True,
211 'url': 'teachable:https://learn.vrdev.school/p/gear-vr-developer-mini',
212 'only_matching': True,
214 'url': 'teachable:https://filmsimplified.com/p/davinci-resolve-15-crash-course',
215 'only_matching': True,
219 def suitable(cls, url):
220 return False if TeachableIE.suitable(url) else super(
221 TeachableCourseIE, cls).suitable(url)
223 def _real_extract(self, url):
224 mobj = re.match(self._VALID_URL, url)
225 site = mobj.group('site') or mobj.group('site_t')
226 course_id = mobj.group('id')
230 prefixed = url.startswith(self._URL_PREFIX)
232 prefix = self._URL_PREFIX
233 url = url[len(prefix):]
235 webpage = self._download_webpage(url, course_id)
237 url_base = 'https://%s/' % site
241 for mobj in re.finditer(
242 r'(?s)(?P<li><li[^>]+class=(["\'])(?:(?!\2).)*?section-item[^>]+>.+?</li>)',
244 li = mobj.group('li')
245 if 'fa-youtube-play' not in li:
247 lecture_url = self._search_regex(
248 r'<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1', li,
249 'lecture url', default=None, group='url')
252 lecture_id = self._search_regex(
253 r'/lectures/(\d+)', lecture_url, 'lecture id', default=None)
254 title = self._html_search_regex(
255 r'<span[^>]+class=["\']lecture-name[^>]+>([^<]+)', li,
256 'title', default=None)
257 entry_url = urljoin(url_base, lecture_url)
259 entry_url = self._URL_PREFIX + entry_url
263 ie=TeachableIE.ie_key(), video_id=lecture_id,
264 video_title=clean_html(title)))
266 course_title = self._html_search_regex(
267 (r'(?s)<img[^>]+class=["\']course-image[^>]+>\s*<h\d>(.+?)</h',
268 r'(?s)<h\d[^>]+class=["\']course-title[^>]+>(.+?)</h'),
269 webpage, 'course title', fatal=False)
271 return self.playlist_result(entries, course_id, course_title)