mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-05 07:53:18 +00:00
[packtpub] Fix authentication(closes #13240)
This commit is contained in:
parent
6b7ce85cdc
commit
c56ad5c975
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
@ -14,7 +15,6 @@
|
||||||
strip_or_none,
|
strip_or_none,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
urljoin,
|
urljoin,
|
||||||
urlencode_postdata,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,22 +45,15 @@ def _real_initialize(self):
|
||||||
(username, password) = self._get_login_info()
|
(username, password) = self._get_login_info()
|
||||||
if username is None:
|
if username is None:
|
||||||
return
|
return
|
||||||
webpage = self._download_webpage(self._PACKT_BASE, None)
|
|
||||||
login_form = self._form_hidden_inputs(
|
|
||||||
'packt-user-login-form', webpage)
|
|
||||||
login_form.update({
|
|
||||||
'email': username,
|
|
||||||
'password': password,
|
|
||||||
})
|
|
||||||
self._download_webpage(
|
|
||||||
self._PACKT_BASE, None, 'Logging in as %s' % username,
|
|
||||||
data=urlencode_postdata(login_form))
|
|
||||||
try:
|
try:
|
||||||
self._TOKEN = self._download_json(
|
self._TOKEN = self._download_json(
|
||||||
'%s/users/tokens/sessions' % self._MAPT_REST, None,
|
self._MAPT_REST + '/users/tokens', None,
|
||||||
'Downloading Authorization Token')['data']['token']
|
'Downloading Authorization Token', data=json.dumps({
|
||||||
|
'email': username,
|
||||||
|
'password': password,
|
||||||
|
}).encode())['data']['access']
|
||||||
except ExtractorError as e:
|
except ExtractorError as e:
|
||||||
if isinstance(e.cause, compat_HTTPError) and e.cause.code in (401, 404):
|
if isinstance(e.cause, compat_HTTPError) and e.cause.code in (400, 401, 404):
|
||||||
message = self._parse_json(e.cause.read().decode(), None)['message']
|
message = self._parse_json(e.cause.read().decode(), None)['message']
|
||||||
raise ExtractorError(message, expected=True)
|
raise ExtractorError(message, expected=True)
|
||||||
raise
|
raise
|
||||||
|
@ -83,7 +76,7 @@ def _real_extract(self, url):
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
if self._TOKEN:
|
if self._TOKEN:
|
||||||
headers['Authorization'] = self._TOKEN
|
headers['Authorization'] = 'Bearer ' + self._TOKEN
|
||||||
video = self._download_json(
|
video = self._download_json(
|
||||||
'%s/users/me/products/%s/chapters/%s/sections/%s'
|
'%s/users/me/products/%s/chapters/%s/sections/%s'
|
||||||
% (self._MAPT_REST, course_id, chapter_id, video_id), video_id,
|
% (self._MAPT_REST, course_id, chapter_id, video_id), video_id,
|
||||||
|
|
Loading…
Reference in a new issue