Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[e621] add keyword 'num' for post order in pool #1195

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gallery_dl/extractor/danbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def metadata(self):
url = "{}/pools/{}.json".format(self.root, self.pool_id)
pool = self.request(url).json()
pool["name"] = pool["name"].replace("_", " ")
del pool["post_ids"]
return {"pool": pool}


Expand Down
14 changes: 13 additions & 1 deletion gallery_dl/extractor/e621.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,32 @@ def request(self, url, **kwargs):

def items(self):
data = self.metadata()
for post in self.posts():
for num, post in enumerate(self.posts(), start=1):
file = post["file"]

if not file["url"]:
ihash = file["md5"]
file["url"] = "https://static1.{}/data/{}/{}/{}.{}".format(
self.root[8:], ihash[0:2], ihash[2:4], ihash, file["ext"])

post["num"] = num
post["filename"] = file["md5"]
post["extension"] = file["ext"]
post.update(data)
yield Message.Directory, post
yield Message.Url, file["url"], post

def posts(self):
posts = super().posts()
data = self.metadata()

if "pool" in data and "post_ids" in data["pool"]:
post_ids = data["pool"]["post_ids"]
post_order = dict([(id, pos) for pos, id in enumerate(post_ids)])
return sorted(posts, key=lambda post: post_order[post["id"]])
else:
return posts


class E621TagExtractor(E621Extractor, danbooru.DanbooruTagExtractor):
"""Extractor for e621 posts from tag searches"""
Expand Down