aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/oauth.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2025-07-31 01:22:07 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2025-07-31 01:22:07 -0400
commitd9539f96cc7ac112b7d8faad022190fbbc88c745 (patch)
tree471249d60b9202c00d7d82abec8b296fc881292e /gallery_dl/extractor/oauth.py
parent889fc15f272118bf277737b6fac29d3faeffc641 (diff)
parenta6e995c093de8aae2e91a0787281bb34c0b871eb (diff)
Update upstream source from tag 'upstream/1.30.2'
Update to upstream version '1.30.2' with Debian dir f0dcd28a671f8600479182ff128e05ba8904a0d8
Diffstat (limited to 'gallery_dl/extractor/oauth.py')
-rw-r--r--gallery_dl/extractor/oauth.py65
1 files changed, 28 insertions, 37 deletions
diff --git a/gallery_dl/extractor/oauth.py b/gallery_dl/extractor/oauth.py
index 815a214..2d9a061 100644
--- a/gallery_dl/extractor/oauth.py
+++ b/gallery_dl/extractor/oauth.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright 2017-2023 Mike Fährmann
+# Copyright 2017-2025 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -74,8 +74,7 @@ class OAuthBase(Extractor):
"""Open 'url' in browser amd return response parameters"""
url += "?" + urllib.parse.urlencode(params)
- browser = self.config("browser", True)
- if browser:
+ if browser := self.config("browser", True):
try:
import webbrowser
browser = webbrowser.get()
@@ -83,18 +82,17 @@ class OAuthBase(Extractor):
browser = None
if browser and browser.open(url):
- name = getattr(browser, "name", None)
- if name:
+ if name := getattr(browser, "name", None):
self.log.info("Opening URL with %s:", name.capitalize())
else:
self.log.info("Please open this URL in your browser:")
- stdout_write("\n{}\n\n".format(url))
+ stdout_write(f"\n{url}\n\n")
return (recv or self.recv)()
def error(self, msg):
return self.send(
- "Remote server reported an error:\n\n{}\n".format(msg))
+ f"Remote server reported an error:\n\n{msg}\n")
def _oauth1_authorization_flow(
self, default_key, default_secret,
@@ -151,10 +149,7 @@ class OAuthBase(Extractor):
"default" if client_id == default_id else "custom",
instance or self.subcategory, client_id)
- state = "gallery-dl_{}_{}".format(
- self.subcategory,
- oauth.nonce(8),
- )
+ state = f"gallery-dl_{self.subcategory}_{oauth.nonce(8)}"
auth_params = {
"client_id" : client_id,
@@ -170,8 +165,8 @@ class OAuthBase(Extractor):
# check authorization response
if state != params.get("state"):
- self.send("'state' mismatch: expected {}, got {}.\n".format(
- state, params.get("state")))
+ self.send(f"'state' mismatch: expected {state}, "
+ f"got {params.get('state')}.\n")
return
if "error" in params:
return self.error(params)
@@ -190,8 +185,8 @@ class OAuthBase(Extractor):
data["client_id"] = client_id
data["client_secret"] = client_secret
- data = self.request(
- token_url, method="POST", data=data, auth=auth).json()
+ data = self.request_json(
+ token_url, method="POST", data=data, auth=auth)
# check token response
if "error" in data:
@@ -217,27 +212,23 @@ class OAuthBase(Extractor):
("These values have", "these values", "are", "them")
)
- msg = "\nYour {} {}\n\n{}\n\n".format(
- " and ".join("'" + n + "'" for n in names),
- _is,
- "\n".join(values),
- )
+ key = " and ".join(f"'{n}'" for n in names)
+ val = "\n".join(values)
+ msg = f"\nYour {key} {_is}\n\n{val}\n\n"
opt = self.oauth_config(names[0])
if self.cache and (opt is None or opt == "cache"):
msg += _vh + " been cached and will automatically be used.\n"
else:
- msg += "Put " + _va + " into your configuration file as \n"
+ msg += f"Put {_va} into your configuration file as \n"
msg += " and\n".join(
- "'extractor." + self.subcategory + "." + n + "'"
+ f"'extractor.{self.subcategory}.{n}'"
for n in names
)
if self.cache:
- msg += (
- "\nor set\n'extractor.{}.{}' to \"cache\""
- .format(self.subcategory, names[0])
- )
- msg += "\nto use {}.\n".format(_it)
+ msg = (f"{msg}\nor set\n'extractor."
+ f"{self.subcategory}.{names[0]}' to \"cache\"")
+ msg = f"{msg}\nto use {_it}.\n"
return msg
@@ -354,7 +345,7 @@ class OAuthMastodon(OAuthBase):
def __init__(self, match):
OAuthBase.__init__(self, match)
- self.instance = match.group(1)
+ self.instance = match[1]
def items(self):
yield Message.Version, 1
@@ -371,8 +362,8 @@ class OAuthMastodon(OAuthBase):
application["client-secret"],
application["client-id"],
application["client-secret"],
- "https://{}/oauth/authorize".format(self.instance),
- "https://{}/oauth/token".format(self.instance),
+ f"https://{self.instance}/oauth/authorize",
+ f"https://{self.instance}/oauth/token",
instance=self.instance,
key="access_token",
cache=mastodon._access_token_cache,
@@ -382,17 +373,17 @@ class OAuthMastodon(OAuthBase):
def _register(self, instance):
self.log.info("Registering application for '%s'", instance)
- url = "https://{}/api/v1/apps".format(instance)
+ url = f"https://{instance}/api/v1/apps"
data = {
"client_name": "gdl:" + oauth.nonce(8),
"redirect_uris": self.redirect_uri,
"scopes": "read",
}
- data = self.request(url, method="POST", data=data).json()
+ data = self.request_json(url, method="POST", data=data)
if "client_id" not in data or "client_secret" not in data:
- raise exception.StopExtraction(
- "Failed to register new application: '%s'", data)
+ raise exception.AbortExtraction(
+ f"Failed to register new application: '{data}'")
data["client-id"] = data.pop("client_id")
data["client-secret"] = data.pop("client_secret")
@@ -443,11 +434,11 @@ class OAuthPixiv(OAuthBase):
"redirect_uri" : "https://app-api.pixiv.net"
"/web/v1/users/auth/pixiv/callback",
}
- data = self.request(
- url, method="POST", headers=headers, data=data).json()
+ data = self.request_json(
+ url, method="POST", headers=headers, data=data)
if "error" in data:
- stdout_write("\n{}\n".format(data))
+ stdout_write(f"\n{data}\n")
if data["error"] in ("invalid_request", "invalid_grant"):
stdout_write("'code' expired, try again\n\n")
return