diff options
| author | 2023-03-13 02:07:49 -0400 | |
|---|---|---|
| committer | 2023-03-13 02:07:49 -0400 | |
| commit | 10987f08f8b6c510ba64f4b42d95ba67eec6e5b0 (patch) | |
| tree | 1af82cad9ac859a70cafc976a980280b939cfcc7 /gallery_dl/extractor/oauth.py | |
| parent | 919f8ba16a7b82ba1099bd25b2c61c7881a05aa2 (diff) | |
New upstream version 1.25.0.upstream/1.25.0
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 = { |
