Skip to content

Commit

Permalink
[kemonoparty] add 'revision_index' metadata field (#4727)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Oct 26, 2023
1 parent 3bbaa87 commit d0effca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 14 additions & 4 deletions gallery_dl/extractor/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,14 @@ def _discord_channels(self, server):

@memcache(keyarg=1)
def _post_revisions(self, url):
return self.request(url + "/revisions").json()
revs = self.request(url + "/revisions").json()

idx = len(revs)
for rev in revs:
rev["revision_index"] = idx
idx -= 1

return revs


def _validate(response):
Expand Down Expand Up @@ -253,13 +260,15 @@ def posts(self):
if revisions:
for post in posts:
post["revision_id"] = 0
yield post
post_url = "{}/post/{}".format(self.api_url, post["id"])
try:
revs = self._post_revisions(post_url)
except exception.HttpError:
pass
post["revision_index"] = 1
yield post
else:
post["revision_index"] = len(revs) + 1
yield post
yield from revs
else:
yield from posts
Expand Down Expand Up @@ -292,8 +301,9 @@ def posts(self):
try:
revs = self._post_revisions(self.api_url)
except exception.HttpError:
pass
post["revision_index"] = 1
else:
post["revision_index"] = len(revs) + 1
return itertools.chain((post,), revs)
return (post,)

Expand Down
8 changes: 5 additions & 3 deletions test/results/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@
},

{
"#url" : "https://kemono.party/patreon/user/3161935/post/68231671/revision/134996",
"#url" : "https://kemono.su/patreon/user/3161935/post/68231671/revision/142470",
"#comment" : "revisions (#4498)",
"#category": ("", "kemonoparty", "patreon"),
"#class" : kemonoparty.KemonopartyPostExtractor,
"#urls" : "https://kemono.party/data/88/52/88521f71822dfa2f42df3beba319ea4fceda2a2d6dc59da0276a75238f743f86.jpg",
"#urls" : "https://kemono.su/data/88/52/88521f71822dfa2f42df3beba319ea4fceda2a2d6dc59da0276a75238f743f86.jpg",

"revision_id": 134996,
"revision_id": 142470,
"revision_index": 2,
},

{
Expand All @@ -188,6 +189,7 @@
"#archive" : False,

"revision_id": range(134996, 3052965),
"revision_index": range(1, 9),
},


Expand Down

0 comments on commit d0effca

Please sign in to comment.