diff options
Diffstat (limited to 'gallery_dl/extractor/oauth.py')
| -rw-r--r-- | gallery_dl/extractor/oauth.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/gallery_dl/extractor/oauth.py b/gallery_dl/extractor/oauth.py index 9270f33..ec46ca3 100644 --- a/gallery_dl/extractor/oauth.py +++ b/gallery_dl/extractor/oauth.py @@ -9,13 +9,12 @@ """Utility classes to setup OAuth and link accounts to gallery-dl""" from .common import Extractor, Message -from . import deviantart, flickr, mastodon, pixiv, reddit, smugmug, tumblr 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" @@ -76,7 +75,8 @@ class OAuthBase(Extractor): browser = webbrowser.get() if browser and browser.open(url): - self.log.info("Opening URL in %s:", browser.name.capitalize()) + name = getattr(browser, "name", "Browser") + self.log.info("Opening URL in %s:", name.capitalize()) else: self.log.info("Please open this URL in your browser:") @@ -242,6 +242,7 @@ class OAuthFlickr(OAuthBase): def items(self): yield Message.Version, 1 + from . import flickr self._oauth1_authorization_flow( flickr.FlickrAPI.API_KEY, @@ -258,6 +259,7 @@ class OAuthSmugmug(OAuthBase): def items(self): yield Message.Version, 1 + from . import smugmug self._oauth1_authorization_flow( smugmug.SmugmugAPI.API_KEY, @@ -274,6 +276,7 @@ class OAuthTumblr(OAuthBase): def items(self): yield Message.Version, 1 + from . import tumblr self._oauth1_authorization_flow( tumblr.TumblrAPI.API_KEY, @@ -294,6 +297,7 @@ class OAuthDeviantart(OAuthBase): def items(self): yield Message.Version, 1 + from . import deviantart self._oauth2_authorization_code_grant( self.oauth_config("client-id"), @@ -313,6 +317,7 @@ class OAuthReddit(OAuthBase): def items(self): yield Message.Version, 1 + from . import reddit self.session.headers["User-Agent"] = reddit.RedditAPI.USER_AGENT self._oauth2_authorization_code_grant( @@ -337,6 +342,7 @@ class OAuthMastodon(OAuthBase): def items(self): yield Message.Version, 1 + from . import mastodon for application in mastodon.INSTANCES.values(): if self.instance == application["root"].partition("://")[2]: @@ -389,11 +395,12 @@ class OAuthPixiv(OAuthBase): def items(self): yield Message.Version, 1 + from . import pixiv 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 = { |
