X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Fudemy.py;h=e743c0262c90aa351e94ded3754f938b64b87175;hb=78717fc32802cb1e0f240cfbdf02207c6356ff2b;hp=4667ed83b71f4aec5f081741834e2c9cca010e82;hpb=ff21a8e0ee43d4ce0b75cd938f9bdfab664dd579;p=youtube-dl diff --git a/youtube_dl/extractor/udemy.py b/youtube_dl/extractor/udemy.py index 4667ed83b..e743c0262 100644 --- a/youtube_dl/extractor/udemy.py +++ b/youtube_dl/extractor/udemy.py @@ -9,13 +9,16 @@ from ..compat import ( ) from ..utils import ( ExtractorError, + int_or_none, + sanitized_Request, ) class UdemyIE(InfoExtractor): IE_NAME = 'udemy' _VALID_URL = r'https?://www\.udemy\.com/(?:[^#]+#/lecture/|lecture/view/?\?lectureId=)(?P\d+)' - _LOGIN_URL = 'https://www.udemy.com/join/login-submit/' + _LOGIN_URL = 'https://www.udemy.com/join/login-popup/?displayType=ajax&showSkipButton=1' + _ORIGIN_URL = 'https://www.udemy.com' _NETRC_MACHINE = 'udemy' _TESTS = [{ @@ -57,7 +60,7 @@ class UdemyIE(InfoExtractor): for header, value in headers.items(): url_or_request.add_header(header, value) else: - url_or_request = compat_urllib_request.Request(url_or_request, headers=headers) + url_or_request = sanitized_Request(url_or_request, headers=headers) response = super(UdemyIE, self)._download_json(url_or_request, video_id, note) self._handle_error(response) @@ -69,34 +72,39 @@ class UdemyIE(InfoExtractor): def _login(self): (username, password) = self._get_login_info() if username is None: - raise ExtractorError( - 'Udemy account is required, use --username and --password options to provide account credentials.', - expected=True) + return login_popup = self._download_webpage( - 'https://www.udemy.com/join/login-popup?displayType=ajax&showSkipButton=1', None, - 'Downloading login popup') + self._LOGIN_URL, None, 'Downloading login popup') - if login_popup == '
': + def is_logged(webpage): + return any(p in webpage for p in ['href="https://www.udemy.com/user/logout/', '>Logout<']) + + # already logged in + if is_logged(login_popup): return - csrf = self._html_search_regex( - r']+class="form-errors[^"]*">(.+?)', + response, 'error message', default=None) + if error: + raise ExtractorError('Unable to login: %s' % error, expected=True) raise ExtractorError('Unable to log in') def _real_extract(self, url): @@ -120,26 +128,47 @@ class UdemyIE(InfoExtractor): video_id = asset['id'] thumbnail = asset.get('thumbnailUrl') or asset.get('thumbnail_url') - duration = asset['data']['duration'] + duration = int_or_none(asset.get('data', {}).get('duration')) download_url = asset.get('downloadUrl') or asset.get('download_url') video = download_url.get('Video') or download_url.get('video') video_480p = download_url.get('Video480p') or download_url.get('video_480p') - formats = [ - { - 'url': video_480p[0], - 'format_id': '360p', - }, - { - 'url': video[0], - 'format_id': '720p', - }, - ] + formats = [{ + 'url': video_480p[0], + 'format_id': 'download-360p', + }, { + 'url': video[0], + 'format_id': 'download-720p', + }] + + # Some videos also contain formats in asset['data']['outputs'] (e.g. + # https://www.udemy.com/ios9-swift/learn/#/lecture/3383208) + outputs = asset.get('data', {}).get('outputs') + if isinstance(outputs, dict): + for format_id, f in outputs.items(): + video_url = f.get('url') + if video_url: + formats.append({ + 'url': video_url, + 'format_id': '%sp' % (f.get('labe1l') or format_id), + 'width': int_or_none(f.get('width')), + 'height': int_or_none(f.get('height')), + 'vbr': int_or_none(f.get('video_bitrate_in_kbps')), + 'vcodec': f.get('video_codec'), + 'fps': int_or_none(f.get('frame_rate')), + 'abr': int_or_none(f.get('audio_bitrate_in_kbps')), + 'acodec': f.get('audio_codec'), + 'asr': int_or_none(f.get('audio_sample_rate')), + 'tbr': int_or_none(f.get('total_bitrate_in_kbps')), + 'filesize': int_or_none(f.get('file_size_in_bytes')), + }) + + self._sort_formats(formats) title = lecture['title'] - description = lecture['description'] + description = lecture.get('description') return { 'id': video_id,