diff --git a/docs/configuration.rst b/docs/configuration.rst index 67f63c5b..f21d2033 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3859,6 +3859,21 @@ Description restrict it to only one possible format. +extractor.rule34xyz.format +--------------------------- +Type + * ``string`` + * ``list`` of ``strings`` +Default + ``["10", "40", "41", "2"]`` +Example + ``"33,34,4"`` +Description + Selects the file format to extract. + + When more than one format is given, the first available one is selected. + + extractor.sankaku.id-format --------------------------- Type diff --git a/gallery_dl/extractor/rule34xyz.py b/gallery_dl/extractor/rule34xyz.py index 450d2262..f1e75188 100644 --- a/gallery_dl/extractor/rule34xyz.py +++ b/gallery_dl/extractor/rule34xyz.py @@ -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): diff --git a/test/results/rule34xyz.py b/test/results/rule34xyz.py index 8400e651..8a07c5dc 100644 --- a/test/results/rule34xyz.py +++ b/test/results/rule34xyz.py @@ -44,6 +44,8 @@ __tests__ = ( "extension" : "jpg", "file_url" : "https://rule34xyz.b-cdn.net/posts/3613/3613851/3613851.pic.jpg", "filename" : "3613851.pic", + "format" : "pic", + "format_id" : "2", "id" : 3613851, "likes" : range(3, 100), "posted" : "2023-03-29T06:01:07.900161", @@ -121,6 +123,20 @@ __tests__ = ( "#class" : rule34xyz.Rule34xyzPostExtractor, "#urls" : "https://rule34xyz.b-cdn.net/posts/3571/3571567/3571567.mov720.mp4", "#sha1_content": "c0a5e7e887774f91527f00e6142c435a3c482c1f", + + "format" : "mov720", + "format_id" : "40", +}, + +{ + "#url" : "https://rule34.xyz/post/3571567", + "#comment": "'format' option", + "#class" : rule34xyz.Rule34xyzPostExtractor, + "#options": {"format": "10,33"}, + "#urls" : "https://rule34xyz.b-cdn.net/posts/3571/3571567/3571567.pic256avif.avif", + + "format" : "pic256avif", + "format_id" : "33", }, )