From e293711802c010e2720f8df00fde34d0af5f6ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 26 Nov 2014 21:00:18 +0600 Subject: [PATCH] [udemy] Set session cookies to API requests (Closes #4124, closes #4219, closes #4308) --- youtube_dl/extractor/udemy.py | 67 +++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/youtube_dl/extractor/udemy.py b/youtube_dl/extractor/udemy.py index 1a7d01c67..cf7bd0ae5 100644 --- a/youtube_dl/extractor/udemy.py +++ b/youtube_dl/extractor/udemy.py @@ -45,6 +45,19 @@ class UdemyIE(InfoExtractor): self._handle_error(response) return response + def _download_json_cookies(self, url, video_id, note): + headers = { + 'X-Udemy-Snail-Case': 'true', + 'X-Requested-With': 'XMLHttpRequest', + } + for cookie in self._downloader.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 + request = compat_urllib_request.Request(url, headers=headers) + return self._download_json(request, video_id, note) + def _real_initialize(self): self._login() @@ -62,7 +75,9 @@ class UdemyIE(InfoExtractor): if login_popup == '
': return - csrf = self._html_search_regex(r'