diff --git a/gallery_dl/extractor/oauth.py b/gallery_dl/extractor/oauth.py index 48cef94d..55407947 100644 --- a/gallery_dl/extractor/oauth.py +++ b/gallery_dl/extractor/oauth.py @@ -14,8 +14,8 @@ from .. import text, oauth, util, config, exception from ..output import stdout_write from ..cache import cache import urllib.parse +import binascii import hashlib -import base64 REDIRECT_URI_LOCALHOST = "http://localhost:6414/" REDIRECT_URI_HTTPS = "https://mikf.github.io/gallery-dl/oauth-redirect.html" @@ -392,9 +392,9 @@ class OAuthPixiv(OAuthBase): yield Message.Version, 1 code_verifier = util.generate_token(32) - digest = hashlib.sha256(code_verifier.encode("ascii")).digest() - code_challenge = base64.urlsafe_b64encode( - digest).rstrip(b"=").decode("ascii") + digest = hashlib.sha256(code_verifier.encode()).digest() + code_challenge = binascii.b2a_base64( + digest)[:-2].decode().replace("+", "-").replace("/", "_") url = "https://app-api.pixiv.net/web/v1/login" params = { diff --git a/gallery_dl/extractor/photobucket.py b/gallery_dl/extractor/photobucket.py index 375b5e3c..6234e6a9 100644 --- a/gallery_dl/extractor/photobucket.py +++ b/gallery_dl/extractor/photobucket.py @@ -10,7 +10,7 @@ from .common import Extractor, Message from .. import text, exception -import base64 +import binascii import json @@ -168,7 +168,7 @@ class PhotobucketImageExtractor(Extractor): image["titleOrFilename"] = image["title"] or name image["tags"] = image.pop("clarifaiTagList", []) - mtype, _, mid = base64.b64decode(image["id"]).partition(b":") + mtype, _, mid = binascii.a2b_base64(image["id"]).partition(b":") image["pictureId"] = mid.decode() if mtype == b"mediaId" else "" yield Message.Directory, image diff --git a/gallery_dl/oauth.py b/gallery_dl/oauth.py index e9dfff02..ac38c4dc 100644 --- a/gallery_dl/oauth.py +++ b/gallery_dl/oauth.py @@ -10,10 +10,10 @@ import hmac import time -import base64 import random import string import hashlib +import binascii import urllib.parse import requests @@ -100,7 +100,7 @@ class OAuth1Client(requests.auth.AuthBase): key = concat(self.consumer_secret, self.token_secret or "").encode() signature = hmac.new(key, message, hashlib.sha1).digest() - return quote(base64.b64encode(signature).decode()) + return quote(binascii.b2a_base64(signature)[:-1].decode()) class OAuth1API():