[rule34xyz] implement login with username & password (#7736)
This commit is contained in:
@@ -472,6 +472,7 @@ Description
|
||||
* ``newgrounds``
|
||||
* ``nijie`` (R)
|
||||
* ``pillowfort``
|
||||
* ``rule34xyz``
|
||||
* ``sankaku``
|
||||
* ``schalenetwork``
|
||||
* ``scrolller``
|
||||
|
||||
@@ -577,6 +577,9 @@
|
||||
},
|
||||
"rule34xyz":
|
||||
{
|
||||
"username": "",
|
||||
"password": "",
|
||||
|
||||
"format": ["10", "40", "41", "2"]
|
||||
},
|
||||
"sankaku":
|
||||
|
||||
@@ -845,7 +845,7 @@ Consider all listed sites to potentially be NSFW.
|
||||
<td>Rule 34 XYZ</td>
|
||||
<td>https://rule34.xyz/</td>
|
||||
<td>Playlists, Posts, Tag Searches</td>
|
||||
<td></td>
|
||||
<td>Supported</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Saint</td>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -484,6 +484,7 @@ AUTH_MAP = {
|
||||
"pixiv" : _OAUTH,
|
||||
"ponybooru" : "API Key",
|
||||
"reddit" : _OAUTH,
|
||||
"rule34xyz" : "Supported",
|
||||
"sankaku" : "Supported",
|
||||
"scrolller" : "Supported",
|
||||
"seiga" : "Supported",
|
||||
|
||||
Reference in New Issue
Block a user