1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 12:12:34 +01:00

[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
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 51 additions and 6 deletions

View File

@ -3859,6 +3859,21 @@ Description
restrict it to only one possible format. 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 extractor.sankaku.id-format
--------------------------- ---------------------------
Type Type

View File

@ -29,17 +29,31 @@ class Rule34xyzExtractor(BooruExtractor):
3: "artist", 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): def _file_url(self, post):
post["files"] = files = { post["files"] = files = {
str(link["type"]): link["url"] str(link["type"]): link["url"]
for link in post.pop("imageLinks") for link in post.pop("imageLinks")
} }
post["file_url"] = url = (
files.get("10") or # mov for fmt in self.formats:
files.get("40") or # mov720 if fmt in files:
files.get("41") or # mov480 break
files["2"] # pic 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 return url
def _prepare(self, post): def _prepare(self, post):

View File

@ -44,6 +44,8 @@ __tests__ = (
"extension" : "jpg", "extension" : "jpg",
"file_url" : "https://rule34xyz.b-cdn.net/posts/3613/3613851/3613851.pic.jpg", "file_url" : "https://rule34xyz.b-cdn.net/posts/3613/3613851/3613851.pic.jpg",
"filename" : "3613851.pic", "filename" : "3613851.pic",
"format" : "pic",
"format_id" : "2",
"id" : 3613851, "id" : 3613851,
"likes" : range(3, 100), "likes" : range(3, 100),
"posted" : "2023-03-29T06:01:07.900161", "posted" : "2023-03-29T06:01:07.900161",
@ -121,6 +123,20 @@ __tests__ = (
"#class" : rule34xyz.Rule34xyzPostExtractor, "#class" : rule34xyz.Rule34xyzPostExtractor,
"#urls" : "https://rule34xyz.b-cdn.net/posts/3571/3571567/3571567.mov720.mp4", "#urls" : "https://rule34xyz.b-cdn.net/posts/3571/3571567/3571567.mov720.mp4",
"#sha1_content": "c0a5e7e887774f91527f00e6142c435a3c482c1f", "#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",
}, },
) )