[kemonoparty] implement login with username & password (#1824)

This commit is contained in:
Mike Fährmann
2021-09-09 01:02:59 +02:00
parent 0e33746fe0
commit 4ec11af6a4
4 changed files with 31 additions and 4 deletions

View File

@@ -368,6 +368,7 @@ Description
* ``imgbb``
* ``inkbunny``
* ``instagram``
* ``kemonoparty``
* ``mangadex``
* ``mangoxo``
* ``pillowfort``

View File

@@ -383,7 +383,7 @@ Consider all sites to be NSFW unless otherwise known.
<td>Kemonoparty</td>
<td>https://kemono.party/</td>
<td>Favorites, Posts, User Profiles</td>
<td></td>
<td>Supported</td>
</tr>
<tr>
<td>Khinsider</td>

View File

@@ -9,7 +9,8 @@
"""Extractors for https://kemono.party/"""
from .common import Extractor, Message
from .. import text
from .. import text, exception
from ..cache import cache
import itertools
import re
@@ -75,6 +76,25 @@ class KemonopartyExtractor(Extractor):
text.nameext_from_url(file["name"], post)
yield Message.Url, url, post
def login(self):
username, password = self._get_auth_info()
if username:
self._update_cookies(self._login_impl(username, password))
@cache(maxage=28*24*3600, keyarg=1)
def _login_impl(self, username, password):
self.log.info("Logging in as %s", username)
url = self.root + "/account/login"
data = {"username": username, "password": password}
response = self.request(url, method="POST", data=data)
if response.url.endswith("/account/login") and \
"Username or password is incorrect" in response.text:
raise exception.AuthenticationError()
return {c.name: c.value for c in response.history[0].cookies}
class KemonopartyUserExtractor(KemonopartyExtractor):
"""Extractor for all posts from a kemono.party user listing"""
@@ -179,12 +199,17 @@ class KemonopartyFavoriteExtractor(KemonopartyExtractor):
"""Extractor for kemono.party favorites"""
subcategory = "favorite"
pattern = r"(?:https?://)?kemono\.party/favorites"
test = ("https://kemono.party/favorites",)
test = ("https://kemono.party/favorites", {
"pattern": KemonopartyUserExtractor.pattern,
"url": "f4b5b796979bcba824af84206578c79101c7f0e1",
"count": 3,
})
def items(self):
self._prepare_ddosguard_cookies()
users = self.request(self.root + "/api/favorites").json()
self.login()
users = self.request(self.root + "/api/favorites").json()
for user in users:
user["_extractor"] = KemonopartyUserExtractor
url = "{}/{}/user/{}".format(

View File

@@ -219,6 +219,7 @@ AUTH_MAP = {
"imgbb" : "Supported",
"inkbunny" : "Supported",
"instagram" : "Supported",
"kemonoparty" : "Supported",
"mangadex" : "Supported",
"mangoxo" : "Supported",
"mastodon.social": _OAUTH,