Plugin cleanup and tweaks
This commit is contained in:
@@ -1,25 +1,20 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import urllib.request
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import (
|
||||
compat_HTTPError,
|
||||
compat_kwargs,
|
||||
compat_str,
|
||||
compat_urllib_request,
|
||||
compat_urlparse,
|
||||
)
|
||||
from ..compat import compat_HTTPError, compat_str, compat_urlparse
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
determine_ext,
|
||||
extract_attributes,
|
||||
ExtractorError,
|
||||
float_or_none,
|
||||
int_or_none,
|
||||
js_to_json,
|
||||
sanitized_Request,
|
||||
smuggle_url,
|
||||
try_get,
|
||||
unescapeHTML,
|
||||
unsmuggle_url,
|
||||
url_or_none,
|
||||
urlencode_postdata,
|
||||
)
|
||||
@@ -113,7 +108,7 @@ class UdemyIE(InfoExtractor):
|
||||
% (course_id, lecture_id),
|
||||
lecture_id, 'Downloading lecture JSON', query={
|
||||
'fields[lecture]': 'title,description,view_html,asset',
|
||||
'fields[asset]': 'asset_type,stream_url,thumbnail_url,download_urls,stream_urls,captions,data',
|
||||
'fields[asset]': 'asset_type,stream_url,thumbnail_url,download_urls,stream_urls,captions,data,course_is_drmed',
|
||||
})
|
||||
|
||||
def _handle_error(self, response):
|
||||
@@ -132,7 +127,7 @@ class UdemyIE(InfoExtractor):
|
||||
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36'
|
||||
kwargs['headers'] = headers
|
||||
ret = super(UdemyIE, self)._download_webpage_handle(
|
||||
*args, **compat_kwargs(kwargs))
|
||||
*args, **kwargs)
|
||||
if not ret:
|
||||
return ret
|
||||
webpage, _ = ret
|
||||
@@ -151,14 +146,14 @@ class UdemyIE(InfoExtractor):
|
||||
'X-Udemy-Snail-Case': 'true',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
}
|
||||
for cookie in self._downloader.cookiejar:
|
||||
for cookie in self.cookiejar:
|
||||
if cookie.name == 'client_id':
|
||||
headers['X-Udemy-Client-Id'] = cookie.value
|
||||
elif cookie.name == 'access_token':
|
||||
headers['X-Udemy-Bearer-Token'] = cookie.value
|
||||
headers['X-Udemy-Authorization'] = 'Bearer %s' % cookie.value
|
||||
|
||||
if isinstance(url_or_request, compat_urllib_request.Request):
|
||||
if isinstance(url_or_request, urllib.request.Request):
|
||||
for header, value in headers.items():
|
||||
url_or_request.add_header(header, value)
|
||||
else:
|
||||
@@ -168,14 +163,7 @@ class UdemyIE(InfoExtractor):
|
||||
self._handle_error(response)
|
||||
return response
|
||||
|
||||
def _real_initialize(self):
|
||||
self._login()
|
||||
|
||||
def _login(self):
|
||||
username, password = self._get_login_info()
|
||||
if username is None:
|
||||
return
|
||||
|
||||
def _perform_login(self, username, password):
|
||||
login_popup = self._download_webpage(
|
||||
self._LOGIN_URL, None, 'Downloading login popup')
|
||||
|
||||
@@ -213,16 +201,19 @@ class UdemyIE(InfoExtractor):
|
||||
|
||||
def _real_extract(self, url):
|
||||
lecture_id = self._match_id(url)
|
||||
course_id = unsmuggle_url(url, {})[1].get('course_id')
|
||||
|
||||
webpage = self._download_webpage(url, lecture_id)
|
||||
|
||||
course_id, _ = self._extract_course_info(webpage, lecture_id)
|
||||
webpage = None
|
||||
if not course_id:
|
||||
webpage = self._download_webpage(url, lecture_id)
|
||||
course_id, _ = self._extract_course_info(webpage, lecture_id)
|
||||
|
||||
try:
|
||||
lecture = self._download_lecture(course_id, lecture_id)
|
||||
except ExtractorError as e:
|
||||
# Error could possibly mean we are not enrolled in the course
|
||||
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
|
||||
webpage = webpage or self._download_webpage(url, lecture_id)
|
||||
self._enroll_course(url, webpage, course_id)
|
||||
lecture = self._download_lecture(course_id, lecture_id)
|
||||
else:
|
||||
@@ -405,7 +396,8 @@ class UdemyIE(InfoExtractor):
|
||||
if f.get('url'):
|
||||
formats.append(f)
|
||||
|
||||
self._sort_formats(formats)
|
||||
if not formats and asset.get('course_is_drmed'):
|
||||
self.report_drm(video_id)
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
@@ -419,7 +411,7 @@ class UdemyIE(InfoExtractor):
|
||||
}
|
||||
|
||||
|
||||
class UdemyCourseIE(UdemyIE):
|
||||
class UdemyCourseIE(UdemyIE): # XXX: Do not subclass from concrete IE
|
||||
IE_NAME = 'udemy:course'
|
||||
_VALID_URL = r'https?://(?:[^/]+\.)?udemy\.com/(?P<id>[^/?#&]+)'
|
||||
_TESTS = [{
|
||||
@@ -465,7 +457,9 @@ class UdemyCourseIE(UdemyIE):
|
||||
if lecture_id:
|
||||
entry = {
|
||||
'_type': 'url_transparent',
|
||||
'url': 'https://www.udemy.com/%s/learn/v4/t/lecture/%s' % (course_path, entry['id']),
|
||||
'url': smuggle_url(
|
||||
f'https://www.udemy.com/{course_path}/learn/v4/t/lecture/{entry["id"]}',
|
||||
{'course_id': course_id}),
|
||||
'title': entry.get('title'),
|
||||
'ie_key': UdemyIE.ie_key(),
|
||||
}
|
||||
|
Reference in New Issue
Block a user