[deviantart] fix JWT replacement (#293, #4548, #4563)

And again, a huge thank you to @Ironchest337
for discovering this.
This commit is contained in:
Mike Fährmann
2023-09-24 14:45:34 +02:00
parent dbd820d7c5
commit 20d1683c47
2 changed files with 6 additions and 5 deletions

View File

@@ -1354,14 +1354,12 @@ extractor.deviantart.jwt
Type Type
``bool`` ``bool``
Default Default
``false`` ``true``
Description Description
Update `JSON Web Tokens <https://jwt.io/>`__ (the ``token`` URL parameter) Update `JSON Web Tokens <https://jwt.io/>`__ (the ``token`` URL parameter)
of otherwise non-downloadable, low-resolution images of otherwise non-downloadable, low-resolution images
to be able to download them in full resolution. to be able to download them in full resolution.
Note: This got patched by DeviantArt on 2023-09-19 and no longer works.
extractor.deviantart.mature extractor.deviantart.mature
--------------------------- ---------------------------

View File

@@ -42,7 +42,7 @@ class DeviantartExtractor(Extractor):
self.offset = 0 self.offset = 0
def _init(self): def _init(self):
self.jwt = self.config("jwt", False) self.jwt = self.config("jwt", True)
self.flat = self.config("flat", True) self.flat = self.config("flat", True)
self.extra = self.config("extra", False) self.extra = self.config("extra", False)
self.original = self.config("original", True) self.original = self.config("original", True)
@@ -355,6 +355,9 @@ class DeviantartExtractor(Extractor):
if not sep: if not sep:
return return
# 'images-wixmp' returns 401 errors, but just 'wixmp' still works
url = url.replace("//images-wixmp", "//wixmp", 1)
# header = b'{"typ":"JWT","alg":"none"}' # header = b'{"typ":"JWT","alg":"none"}'
payload = ( payload = (
b'{"sub":"urn:app:","iss":"urn:app:","obj":[[{"path":"/f/' + b'{"sub":"urn:app:","iss":"urn:app:","obj":[[{"path":"/f/' +
@@ -367,7 +370,7 @@ class DeviantartExtractor(Extractor):
"{}?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.{}.".format( "{}?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.{}.".format(
url, url,
# base64 of 'header' is precomputed as 'eyJ0eX...' # base64 of 'header' is precomputed as 'eyJ0eX...'
# binascii.a2b_base64(header).rstrip(b"=\n").decode(), # binascii.b2a_base64(header).rstrip(b"=\n").decode(),
binascii.b2a_base64(payload).rstrip(b"=\n").decode()) binascii.b2a_base64(payload).rstrip(b"=\n").decode())
) )