mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 04:02:32 +01:00
[civitai] ensure image files have an 'id' (#6251)
This commit is contained in:
parent
53ae5e3fd8
commit
987f6c36c0
@ -93,7 +93,7 @@ class CivitaiModelExtractor(CivitaiExtractor):
|
|||||||
directory_fmt = ("{category}", "{user[username]}",
|
directory_fmt = ("{category}", "{user[username]}",
|
||||||
"{model[id]}{model[name]:? //}",
|
"{model[id]}{model[name]:? //}",
|
||||||
"{version[id]}{version[name]:? //}")
|
"{version[id]}{version[name]:? //}")
|
||||||
filename_fmt = "{filename}.{extension}"
|
filename_fmt = "{file[id]}.{extension}"
|
||||||
archive_fmt = "{file[hash]}"
|
archive_fmt = "{file[hash]}"
|
||||||
pattern = BASE_PATTERN + r"/models/(\d+)(?:/?\?modelVersionId=(\d+))?"
|
pattern = BASE_PATTERN + r"/models/(\d+)(?:/?\?modelVersionId=(\d+))?"
|
||||||
example = "https://civitai.com/models/12345/TITLE"
|
example = "https://civitai.com/models/12345/TITLE"
|
||||||
@ -183,23 +183,22 @@ class CivitaiModelExtractor(CivitaiExtractor):
|
|||||||
}
|
}
|
||||||
images = self.api.images(params, defaults=False)
|
images = self.api.images(params, defaults=False)
|
||||||
|
|
||||||
return [
|
return self._image_results(images)
|
||||||
text.nameext_from_url(file["url"], {
|
|
||||||
"num" : num,
|
|
||||||
"file": file,
|
|
||||||
"url" : self._url(file),
|
|
||||||
})
|
|
||||||
for num, file in enumerate(images, 1)
|
|
||||||
]
|
|
||||||
|
|
||||||
def _extract_files_gallery(self, model, version, user):
|
def _extract_files_gallery(self, model, version, user):
|
||||||
images = self.api.images_gallery(model, version, user)
|
images = self.api.images_gallery(model, version, user)
|
||||||
|
return self._image_results(images)
|
||||||
|
|
||||||
|
def _image_results(self, images):
|
||||||
for num, file in enumerate(images, 1):
|
for num, file in enumerate(images, 1):
|
||||||
yield text.nameext_from_url(file["url"], {
|
data = text.nameext_from_url(file["url"], {
|
||||||
"num" : num,
|
"num" : num,
|
||||||
"file": file,
|
"file": file,
|
||||||
"url" : self._url(file),
|
"url" : self._url(file),
|
||||||
})
|
})
|
||||||
|
if "id" not in file and data["filename"].isdecimal():
|
||||||
|
file["id"] = text.parse_int(data["filename"])
|
||||||
|
yield data
|
||||||
|
|
||||||
def _validate_file_model(self, response):
|
def _validate_file_model(self, response):
|
||||||
if response.headers.get("Content-Type", "").startswith("text/html"):
|
if response.headers.get("Content-Type", "").startswith("text/html"):
|
||||||
|
@ -81,22 +81,26 @@ __tests__ = (
|
|||||||
"image" : None,
|
"image" : None,
|
||||||
"username": "bolero537"
|
"username": "bolero537"
|
||||||
},
|
},
|
||||||
"file" : dict,
|
"file" : {
|
||||||
"model" : dict,
|
"id": {26887862, 26887856, 26887852},
|
||||||
|
},
|
||||||
|
"model" : {
|
||||||
|
"id": 703211,
|
||||||
|
},
|
||||||
"num" : range(1, 3),
|
"num" : range(1, 3),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"#url" : "https://civitai.com/images/26962948",
|
"#url" : "https://civitai.com/images/26962948",
|
||||||
"#class": civitai.CivitaiImageExtractor,
|
"#class": civitai.CivitaiImageExtractor,
|
||||||
"#options" : {"image-flags": "w"},
|
"#options" : {"quality": "w"},
|
||||||
"#urls" : "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/69bf3279-df2c-4ec8-b795-479e9cd3db1b/w/69bf3279-df2c-4ec8-b795-479e9cd3db1b.jpeg",
|
"#urls" : "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/69bf3279-df2c-4ec8-b795-479e9cd3db1b/w/69bf3279-df2c-4ec8-b795-479e9cd3db1b.jpeg",
|
||||||
"#sha1_content": "a9a9d08f5fcdbc1e1eec7f203717f9df97b7a671",
|
"#sha1_content": "a9a9d08f5fcdbc1e1eec7f203717f9df97b7a671",
|
||||||
|
|
||||||
"browsingLevel": 1,
|
"browsingLevel": 1,
|
||||||
"createdAt": "2024-08-31T01:11:47.021Z",
|
"createdAt": "2024-08-31T01:11:47.021Z",
|
||||||
"date" : "dt:2024-08-31 01:11:47",
|
"date" : "dt:2024-08-31 01:11:47",
|
||||||
"extension": "jpeg",
|
"extension": "jpg",
|
||||||
"filename" : "69bf3279-df2c-4ec8-b795-479e9cd3db1b",
|
"filename" : "69bf3279-df2c-4ec8-b795-479e9cd3db1b",
|
||||||
"hash" : "ULN0-w?b4nRjxGM{-;t7M_t7NGae~qRjMyt7",
|
"hash" : "ULN0-w?b4nRjxGM{-;t7M_t7NGae~qRjMyt7",
|
||||||
"height" : 1536,
|
"height" : 1536,
|
||||||
|
Loading…
Reference in New Issue
Block a user