diff options
| author | 2021-10-05 23:30:05 -0400 | |
|---|---|---|
| committer | 2021-10-05 23:30:05 -0400 | |
| commit | 34ba2951b8c523713425c98addb9256ea05c946f (patch) | |
| tree | 6ec7e96d0c6e6f6e94b6b97ecd8c0a414ceef93d /gallery_dl/extractor/kemonoparty.py | |
| parent | 3f5483df9075ae526f4c54f4cbe80edeabf6d4cc (diff) | |
New upstream version 1.19.0.upstream/1.19.0
Diffstat (limited to 'gallery_dl/extractor/kemonoparty.py')
| -rw-r--r-- | gallery_dl/extractor/kemonoparty.py | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/gallery_dl/extractor/kemonoparty.py b/gallery_dl/extractor/kemonoparty.py index a911d35..c5f5ae7 100644 --- a/gallery_dl/extractor/kemonoparty.py +++ b/gallery_dl/extractor/kemonoparty.py @@ -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 @@ -70,11 +71,32 @@ class KemonopartyExtractor(Extractor): post["type"] = file["type"] url = file["path"] if url[0] == "/": - url = self.root + url + url = self.root + "/data" + url + elif url.startswith("https://kemono.party"): + url = self.root + "/data" + url[20:] 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""" @@ -119,7 +141,7 @@ class KemonopartyPostExtractor(KemonopartyExtractor): pattern = BASE_PATTERN + r"/post/([^/?#]+)" test = ( ("https://kemono.party/fanbox/user/6993449/post/506575", { - "pattern": r"https://kemono\.party/files/fanbox" + "pattern": r"https://kemono\.party/data/files/fanbox" r"/6993449/506575/P058kDFYus7DbqAkGlfWTlOr\.jpeg", "keyword": { "added": "Wed, 06 May 2020 20:28:02 GMT", @@ -142,12 +164,12 @@ class KemonopartyPostExtractor(KemonopartyExtractor): }), # inline image (#1286) ("https://kemono.party/fanbox/user/7356311/post/802343", { - "pattern": r"https://kemono\.party/inline/fanbox" + "pattern": r"https://kemono\.party/data/inline/fanbox" r"/uaozO4Yga6ydkGIJFAQDixfE\.jpeg", }), # kemono.party -> data.kemono.party ("https://kemono.party/gumroad/user/trylsc/post/IURjT", { - "pattern": r"https://kemono\.party/(file|attachment)s" + "pattern": r"https://kemono\.party/data/(file|attachment)s" r"/gumroad/trylsc/IURjT/", }), # username (#1548, #1652) @@ -173,3 +195,25 @@ class KemonopartyPostExtractor(KemonopartyExtractor): def posts(self): posts = self.request(self.api_url).json() return (posts[0],) if len(posts) > 1 else posts + + +class KemonopartyFavoriteExtractor(KemonopartyExtractor): + """Extractor for kemono.party favorites""" + subcategory = "favorite" + pattern = r"(?:https?://)?kemono\.party/favorites" + test = ("https://kemono.party/favorites", { + "pattern": KemonopartyUserExtractor.pattern, + "url": "f4b5b796979bcba824af84206578c79101c7f0e1", + "count": 3, + }) + + def items(self): + self._prepare_ddosguard_cookies() + self.login() + + users = self.request(self.root + "/api/favorites").json() + for user in users: + user["_extractor"] = KemonopartyUserExtractor + url = "{}/{}/user/{}".format( + self.root, user["service"], user["id"]) + yield Message.Queue, url, user |
