Skip to content

Commit

Permalink
[kemonoparty] add 'announcements' option (#5262)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 26, 2024
1 parent 72ac2c7 commit 9cce461
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,16 @@ Description
Extract a user's direct messages as ``dms`` metadata.


extractor.kemonoparty.announcements
-----------------------------------
Type
``bool``
Default
``false``
Description
Extract a user's announcements as ``announcements`` metadata.


extractor.kemonoparty.favorites
-------------------------------
Type
Expand Down
30 changes: 18 additions & 12 deletions gallery_dl/extractor/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def items(self):
generators = self._build_file_generators(self.config("files"))
duplicates = self.config("duplicates")
comments = self.config("comments")
username = dms = None
username = dms = announcements = None

# prevent files from being sent with gzip compression
headers = {"Accept-Encoding": "identity"}
Expand All @@ -68,6 +68,8 @@ def items(self):
'<meta name="artist_name" content="', '"')[0])
if self.config("dms"):
dms = True
if self.config("announcements"):
announcements = True

posts = self.posts()
max_posts = self.config("max-posts")
Expand All @@ -88,8 +90,12 @@ def items(self):
post["comments"] = self._extract_comments(post)
if dms is not None:
if dms is True:
dms = self._extract_dms(post)
dms = self._extract_cards(post, "dms")
post["dms"] = dms
if announcements is not None:
if announcements is True:
announcements = self._extract_cards(post, "announcements")
post["announcements"] = announcements

files = []
hashes = set()
Expand Down Expand Up @@ -200,21 +206,21 @@ def _extract_comments(self, post):
})
return comments

def _extract_dms(self, post):
url = "{}/{}/user/{}/dms".format(
self.root, post["service"], post["user"])
def _extract_cards(self, post, type):
url = "{}/{}/user/{}/{}".format(
self.root, post["service"], post["user"], type)
page = self.request(url).text

dms = []
for dm in text.extract_iter(page, "<article", "</article>"):
footer = text.extr(dm, "<footer", "</footer>")
dms.append({
cards = []
for card in text.extract_iter(page, "<article", "</article>"):
footer = text.extr(card, "<footer", "</footer>")
cards.append({
"body": text.unescape(text.extr(
dm, "<pre>", "</pre></",
card, "<pre>", "</pre></",
).strip()),
"date": text.extr(footer, 'Published: ', '\n'),
"date": text.extr(footer, ': ', '\n'),
})
return dms
return cards

def _parse_datetime(self, date_string):
if len(date_string) > 19:
Expand Down
13 changes: 13 additions & 0 deletions test/results/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@
}],
},

{
"#url" : "https://kemono.su/patreon/user/3161935/post/68231671",
"#comment" : "announcements",
"#category": ("", "kemonoparty", "patreon"),
"#class" : kemonoparty.KemonopartyPostExtractor,
"#options" : {"announcements": True},

"announcements": [{
"body": "<div><strong>Thank you so much for the support!</strong><strong><br></strong>This Patreon is more of a tip jar for supporting what I make. I have to clarify that there are <strong>no exclusive Patreon animations</strong> because all are released for the public. You will get earlier access to WIPs. Direct downloads to my works are also available for $5 and $10 Tiers.</div>",
"date": "2023-02",
}],
},

{
"#url" : "https://kemono.su/patreon/user/19623797/post/29035449",
"#comment" : "invalid file (#3510)",
Expand Down

0 comments on commit 9cce461

Please sign in to comment.