Use different method to check successful login, make the code compatible with python3
This commit is contained in:
parent
f02a97581b
commit
c000009f50
@ -54,10 +54,13 @@ class FrontEndMasterBaseIE(InfoExtractor):
|
|||||||
headers={'Content-Type': 'application/x-www-form-urlencoded'}
|
headers={'Content-Type': 'application/x-www-form-urlencoded'}
|
||||||
)
|
)
|
||||||
|
|
||||||
logout_link = self._search_regex('(Logout .*)',
|
error = self._search_regex(
|
||||||
response, 'logout-link')
|
r'<div[^>]+class=["\']Message MessageAlert["\'][^>]*>([^<]+)</div>',
|
||||||
if not logout_link:
|
response, 'error message', default=None)
|
||||||
raise ExtractorError('Unable to login', expected=True)
|
|
||||||
|
if error:
|
||||||
|
raise ExtractorError('Unable to login: check username and password',
|
||||||
|
expected=True)
|
||||||
|
|
||||||
def _match_course_id(self, url):
|
def _match_course_id(self, url):
|
||||||
if '_VALID_URL_RE' not in self.__dict__:
|
if '_VALID_URL_RE' not in self.__dict__:
|
||||||
@ -81,9 +84,13 @@ class FrontEndMasterBaseIE(InfoExtractor):
|
|||||||
current_section = None
|
current_section = None
|
||||||
current_section_number = 0
|
current_section_number = 0
|
||||||
for elem in lesson_elements:
|
for elem in lesson_elements:
|
||||||
if isinstance(elem, unicode):
|
if not isinstance(elem, int):
|
||||||
|
elem_name = elem
|
||||||
|
if not isinstance(elem_name, str):
|
||||||
|
# convert unicode to str
|
||||||
|
elem_name = elem.encode('utf-8')
|
||||||
(current_section, current_section_number) = \
|
(current_section, current_section_number) = \
|
||||||
(elem.encode('utf-8'), current_section_number + 1)
|
(elem_name, current_section_number + 1)
|
||||||
else:
|
else:
|
||||||
if current_section:
|
if current_section:
|
||||||
sections[elem] = (current_section, current_section_number)
|
sections[elem] = (current_section, current_section_number)
|
||||||
@ -120,7 +127,8 @@ class FrontEndMasterIE(FrontEndMasterBaseIE):
|
|||||||
lesson_section_elements = course_json_content.get('lessonElements')
|
lesson_section_elements = course_json_content.get('lessonElements')
|
||||||
lesson_data = course_json_content.get('lessonData')[lesson_hash]
|
lesson_data = course_json_content.get('lessonData')[lesson_hash]
|
||||||
lesson_source_base = lesson_data.get('sourceBase')
|
lesson_source_base = lesson_data.get('sourceBase')
|
||||||
course_sections_pairing = self._pair_section_with_video_elemen_index(lesson_section_elements)
|
course_sections_pairing = self._pair_section_with_video_elemen_index(
|
||||||
|
lesson_section_elements)
|
||||||
|
|
||||||
lesson_title = lesson_data.get('title')
|
lesson_title = lesson_data.get('title')
|
||||||
lesson_description = lesson_data.get('description')
|
lesson_description = lesson_data.get('description')
|
||||||
@ -130,7 +138,6 @@ class FrontEndMasterIE(FrontEndMasterBaseIE):
|
|||||||
lesson_section = course_sections_pairing.get(lesson_index)[0]
|
lesson_section = course_sections_pairing.get(lesson_index)[0]
|
||||||
lesson_section_number = course_sections_pairing.get(lesson_index)[1]
|
lesson_section_number = course_sections_pairing.get(lesson_index)[1]
|
||||||
|
|
||||||
|
|
||||||
QUALITIES_PREFERENCE = ('low', 'medium', 'high')
|
QUALITIES_PREFERENCE = ('low', 'medium', 'high')
|
||||||
quality_key = qualities(QUALITIES_PREFERENCE)
|
quality_key = qualities(QUALITIES_PREFERENCE)
|
||||||
QUALITIES = {
|
QUALITIES = {
|
||||||
@ -139,7 +146,8 @@ class FrontEndMasterIE(FrontEndMasterBaseIE):
|
|||||||
'high': {'width': 1920, 'height': 1080}
|
'high': {'width': 1920, 'height': 1080}
|
||||||
}
|
}
|
||||||
|
|
||||||
AllowedQuality = collections.namedtuple('AllowedQuality', ['ext', 'qualities'])
|
AllowedQuality = collections.namedtuple('AllowedQuality',
|
||||||
|
['ext', 'qualities'])
|
||||||
ALLOWED_QUALITIES = [
|
ALLOWED_QUALITIES = [
|
||||||
AllowedQuality('webm', ['low', 'medium', 'high']),
|
AllowedQuality('webm', ['low', 'medium', 'high']),
|
||||||
AllowedQuality('mp4', ['low', 'medium', 'high'])
|
AllowedQuality('mp4', ['low', 'medium', 'high'])
|
||||||
@ -169,9 +177,11 @@ class FrontEndMasterIE(FrontEndMasterBaseIE):
|
|||||||
req_quality = '-'.join(req_quality.split('-')[:2])
|
req_quality = '-'.join(req_quality.split('-')[:2])
|
||||||
for allowed_quality in ALLOWED_QUALITIES:
|
for allowed_quality in ALLOWED_QUALITIES:
|
||||||
if req_ext == allowed_quality.ext and req_quality in allowed_quality.qualities:
|
if req_ext == allowed_quality.ext and req_quality in allowed_quality.qualities:
|
||||||
return (AllowedQuality(req_ext, (req_quality, )), )
|
return (AllowedQuality(req_ext, (req_quality,)),)
|
||||||
req_ext = 'webm' if self._downloader.params.get('prefer_free_formats') else 'mp4'
|
req_ext = 'webm' if self._downloader.params.get(
|
||||||
return (AllowedQuality(req_ext, ('high', )), )
|
'prefer_free_formats') else 'mp4'
|
||||||
|
return (AllowedQuality(req_ext, ('high',)),)
|
||||||
|
|
||||||
allowed_qualities = guess_allowed_qualities()
|
allowed_qualities = guess_allowed_qualities()
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
@ -182,8 +192,9 @@ class FrontEndMasterIE(FrontEndMasterBaseIE):
|
|||||||
'r': f['height'],
|
'r': f['height'],
|
||||||
'f': ext
|
'f': ext
|
||||||
}
|
}
|
||||||
video_response = self._download_json(video_request_url % lesson_source_base, video_id,
|
video_response = self._download_json(
|
||||||
query=video_request_params, headers=video_request_headers)
|
video_request_url % lesson_source_base, video_id,
|
||||||
|
query=video_request_params, headers=video_request_headers)
|
||||||
|
|
||||||
# To avoid the possibility of problems with multiple sequential calls to ViewClip API and start
|
# To avoid the possibility of problems with multiple sequential calls to ViewClip API and start
|
||||||
# to return 429 HTTP errors after some time (see the problem Pluralsight has on
|
# to return 429 HTTP errors after some time (see the problem Pluralsight has on
|
||||||
@ -261,7 +272,8 @@ class FrontEndMasterCourseIE(FrontEndMasterBaseIE):
|
|||||||
entries = []
|
entries = []
|
||||||
for video in videos_data:
|
for video in videos_data:
|
||||||
video_slug = video.get('slug')
|
video_slug = video.get('slug')
|
||||||
clip_url = "%s/%s/%s" % (self._VIDEO_BASE, course_display_id, video_slug)
|
clip_url = "%s/%s/%s" % (
|
||||||
|
self._VIDEO_BASE, course_display_id, video_slug)
|
||||||
entries.append({
|
entries.append({
|
||||||
'_type': 'url_transparent',
|
'_type': 'url_transparent',
|
||||||
'url': clip_url,
|
'url': clip_url,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user