mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-12-23 06:57:54 +01:00
[udemy] Detect non free courses (Closes #8138)
This commit is contained in:
parent
40f796288a
commit
17b2d7ca77
@ -11,6 +11,7 @@ from ..utils import (
|
|||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
sanitized_Request,
|
sanitized_Request,
|
||||||
|
unescapeHTML,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -19,8 +20,6 @@ class UdemyIE(InfoExtractor):
|
|||||||
_VALID_URL = r'https?://www\.udemy\.com/(?:[^#]+#/lecture/|lecture/view/?\?lectureId=)(?P<id>\d+)'
|
_VALID_URL = r'https?://www\.udemy\.com/(?:[^#]+#/lecture/|lecture/view/?\?lectureId=)(?P<id>\d+)'
|
||||||
_LOGIN_URL = 'https://www.udemy.com/join/login-popup/?displayType=ajax&showSkipButton=1'
|
_LOGIN_URL = 'https://www.udemy.com/join/login-popup/?displayType=ajax&showSkipButton=1'
|
||||||
_ORIGIN_URL = 'https://www.udemy.com'
|
_ORIGIN_URL = 'https://www.udemy.com'
|
||||||
_SUCCESSFULLY_ENROLLED = '>You have enrolled in this course!<'
|
|
||||||
_ALREADY_ENROLLED = '>You are already taking this course.<'
|
|
||||||
_NETRC_MACHINE = 'udemy'
|
_NETRC_MACHINE = 'udemy'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
@ -37,15 +36,21 @@ class UdemyIE(InfoExtractor):
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
def _enroll_course(self, webpage, course_id):
|
def _enroll_course(self, webpage, course_id):
|
||||||
enroll_url = self._search_regex(
|
checkout_url = unescapeHTML(self._search_regex(
|
||||||
|
r'href=(["\'])(?P<url>https?://(?:www\.)?udemy\.com/payment/checkout/.+?)\1',
|
||||||
|
webpage, 'checkout url', group='url', default=None))
|
||||||
|
if checkout_url:
|
||||||
|
raise ExtractorError(
|
||||||
|
'Course %s is not free. You have to pay for it before you can download.'
|
||||||
|
'Use this URL to confirm purchase: %s' % (course_id, checkout_url), expected=True)
|
||||||
|
|
||||||
|
enroll_url = unescapeHTML(self._search_regex(
|
||||||
r'href=(["\'])(?P<url>https?://(?:www\.)?udemy\.com/course/subscribe/.+?)\1',
|
r'href=(["\'])(?P<url>https?://(?:www\.)?udemy\.com/course/subscribe/.+?)\1',
|
||||||
webpage, 'enroll url', group='url',
|
webpage, 'enroll url', group='url', default=None))
|
||||||
default='https://www.udemy.com/course/subscribe/?courseId=%s' % course_id)
|
if enroll_url:
|
||||||
webpage = self._download_webpage(enroll_url, course_id, 'Enrolling in the course')
|
webpage = self._download_webpage(enroll_url, course_id, 'Enrolling in the course')
|
||||||
if self._SUCCESSFULLY_ENROLLED in webpage:
|
if '>You have enrolled in' in webpage:
|
||||||
self.to_screen('%s: Successfully enrolled in' % course_id)
|
self.to_screen('%s: Successfully enrolled in the course' % course_id)
|
||||||
elif self._ALREADY_ENROLLED in webpage:
|
|
||||||
self.to_screen('%s: Already enrolled in' % course_id)
|
|
||||||
|
|
||||||
def _download_lecture(self, course_id, lecture_id):
|
def _download_lecture(self, course_id, lecture_id):
|
||||||
return self._download_json(
|
return self._download_json(
|
||||||
|
Loading…
Reference in New Issue
Block a user