[rule34xyz] add 'format' option (#1078)

This commit is contained in:
Mike Fährmann
2024-11-05 15:27:24 +01:00
parent 51b16d078b
commit 9afbe91f82
3 changed files with 51 additions and 6 deletions

View File

@@ -29,17 +29,31 @@ class Rule34xyzExtractor(BooruExtractor):
3: "artist",
}
def _init(self):
formats = self.config("format")
if formats:
if isinstance(formats, str):
formats = formats.split(",")
self.formats = formats
else:
self.formats = ("10", "40", "41", "2")
def _file_url(self, post):
post["files"] = files = {
str(link["type"]): link["url"]
for link in post.pop("imageLinks")
}
post["file_url"] = url = (
files.get("10") or # mov
files.get("40") or # mov720
files.get("41") or # mov480
files["2"] # pic
)
for fmt in self.formats:
if fmt in files:
break
else:
fmt = "2"
self.log.warning("%s: Requested format not available", post["id"])
post["file_url"] = url = files[fmt]
post["format_id"] = fmt
post["format"] = url.rsplit(".", 2)[1]
return url
def _prepare(self, post):