Skip to content

Commit

Permalink
[kemonoparty] add 'count' metadata field (#2952)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Sep 23, 2022
1 parent 89610a4 commit 09a5cc6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions gallery_dl/extractor/kemonoparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def items(self):
comments = self.config("comments")
username = dms = None

# prevent files to be sent with gzip compression
# prevent files from being sent with gzip compression
headers = {"Accept-Encoding": "identity"}

if self.config("metadata"):
Expand All @@ -63,6 +63,7 @@ def items(self):

for post in posts:

post["_http_headers"] = headers
post["date"] = text.parse_datetime(
post["published"] or post["added"],
"%a, %d %b %Y %H:%M:%S %Z")
Expand All @@ -74,27 +75,32 @@ def items(self):
if dms is True:
dms = self._extract_dms(post)
post["dms"] = dms
yield Message.Directory, post

files = []
hashes = set()
post["num"] = 0

for file in itertools.chain.from_iterable(
g(post) for g in generators):
url = file["path"]

match = find_hash(url)
if match:
post["hash"] = hash = match.group(1)
file["hash"] = hash = match.group(1)
if hash in hashes and not duplicates:
self.log.debug("Skipping %s (duplicate)", url)
continue
hashes.add(hash)
else:
post["hash"] = ""
file["hash"] = ""

post["type"] = file["type"]
post["num"] += 1
post["_http_headers"] = headers
files.append(file)

post["count"] = len(files)
yield Message.Directory, post

for post["num"], file in enumerate(files, 1):
post.update(file)
url = file["path"]

text.nameext_from_url(file.get("name", url), post)
if not post["extension"]:
Expand Down Expand Up @@ -236,6 +242,7 @@ class KemonopartyPostExtractor(KemonopartyExtractor):
"keyword": {
"added": "Wed, 06 May 2020 20:28:02 GMT",
"content": str,
"count": 1,
"date": "dt:2019-08-11 02:09:04",
"edited": None,
"embed": dict,
Expand Down Expand Up @@ -374,6 +381,7 @@ def items(self):
post["channel_name"] = self.channel_name
post["date"] = text.parse_datetime(
post["published"], "%a, %d %b %Y %H:%M:%S %Z")
post["count"] = len(files)
yield Message.Directory, post

for post["num"], file in enumerate(files, 1):
Expand Down

0 comments on commit 09a5cc6

Please sign in to comment.