Skip to content

Commit

Permalink
[kemonoparty] add 'favorites' option (#2826) (#2831)
Browse files Browse the repository at this point in the history
* [kemonoparty] add 'favorites' option (#2826)

* [kemonoparty] add regex for the url parameter and fallback on the config
option

* [kemonoparty] simplify
  • Loading branch information
enduser420 authored Aug 18, 2022
1 parent a799fae commit 574e38a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
12 changes: 12 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,18 @@ Description
Extract a user's direct messages as ``dms`` metadata.


extractor.kemonoparty.favorites
---------------------------
Type
``string``
Default
``artist``
Description
Determines the type of favorites to be downloaded.

Available types are ``artist``, and ``post``.


extractor.kemonoparty.files
---------------------------
Type
Expand Down
48 changes: 36 additions & 12 deletions gallery_dl/extractor/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,44 @@ def items(self):
class KemonopartyFavoriteExtractor(KemonopartyExtractor):
"""Extractor for kemono.party favorites"""
subcategory = "favorite"
pattern = BASE_PATTERN + r"/favorites"
test = ("https://kemono.party/favorites", {
"pattern": KemonopartyUserExtractor.pattern,
"url": "f4b5b796979bcba824af84206578c79101c7f0e1",
"count": 3,
})
pattern = BASE_PATTERN + r"/favorites(?:/?\?([^#]+))?"
test = (
("https://kemono.party/favorites", {
"pattern": KemonopartyUserExtractor.pattern,
"url": "f4b5b796979bcba824af84206578c79101c7f0e1",
"count": 3,
}),
("https://kemono.party/favorites?type=post", {
"pattern": KemonopartyPostExtractor.pattern,
"url": "ecfccf5f0d50b8d14caa7bbdcf071de5c1e5b90f",
"count": 3,
}),
)

def __init__(self, match):
KemonopartyExtractor.__init__(self, match)
self.favorites = (text.parse_query(match.group(2)).get("type") or
self.config("favorites") or
"artist")

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
if self.favorites == "artist":
users = self.request(
self.root + "/api/v1/account/favorites?type=artist").json()
for user in users:
user["_extractor"] = KemonopartyUserExtractor
url = "{}/{}/user/{}".format(
self.root, user["service"], user["id"])
yield Message.Queue, url, user

elif self.favorites == "post":
posts = self.request(
self.root + "/api/v1/account/favorites?type=post").json()
for post in posts:
post["_extractor"] = KemonopartyPostExtractor
url = "{}/{}/user/{}/post/{}".format(
self.root, post["service"], post["user"], post["id"])
yield Message.Queue, url, post

0 comments on commit 574e38a

Please sign in to comment.