[rule34xyz] implement login with username & password (#7736)

This commit is contained in:
Mike Fährmann
2025-06-27 22:35:59 +02:00
parent fde6110d96
commit 5e61fe8668
5 changed files with 28 additions and 2 deletions

View File

@@ -9,7 +9,8 @@
"""Extractors for https://rule34.xyz/"""
from .booru import BooruExtractor
from .. import text
from .. import text, exception
from ..cache import cache
import collections
BASE_PATTERN = r"(?:https?://)?rule34\.xyz"
@@ -111,6 +112,26 @@ class Rule34xyzExtractor(BooruExtractor):
params["Skip"] += self.per_page
params["cursor"] = data["cursor"]
def login(self):
username, password = self._get_auth_info()
if username:
self.session.headers["Authorization"] = \
self._login_impl(username, password)
@cache(maxage=3650*86400, keyarg=1)
def _login_impl(self, username, password):
self.log.info("Logging in as %s", username)
url = f"{self.root}/api/v2/auth/signin"
data = {"email": username, "password": password}
response = self.request_json(
url, method="POST", json=data, fatal=False)
if jwt := response.get("jwt"):
return f"Bearer {jwt}"
raise exception.AuthenticationError(
(msg := response.get("message")) and f'"{msg}"')
class Rule34xyzPostExtractor(Rule34xyzExtractor):
subcategory = "post"