diff --git a/docs/configuration.rst b/docs/configuration.rst index 2464745b..dbc1d1ef 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1578,6 +1578,30 @@ Description ``gallery``. +extractor.civitai.nsfw +---------------------- +Type + * ``bool`` + * ``string`` (``"api": "rest"``) + * ``integer`` (``"api": "trpc"``) +Default + ``true`` +Description + Download images rated NSFW. + + * For ``"api": "rest"``, this can be one of + ``"None"``, ``"Soft"``, ``"Mature"``, ``"X"`` + to set the highest returned mature content flag. + + * For ``"api": "trpc"``, this can be an ``integer`` + whose bits select the returned mature content flags. + + For example, ``12`` (``4|8``) would return only + ``Mature`` and ``X`` rated images, + while ``3`` (``1|2``) would return only + ``None`` and ``Soft`` rated images, + + extractor.civitai.quality ------------------------- Type diff --git a/gallery_dl/extractor/civitai.py b/gallery_dl/extractor/civitai.py index d434cca5..3e657d66 100644 --- a/gallery_dl/extractor/civitai.py +++ b/gallery_dl/extractor/civitai.py @@ -308,23 +308,29 @@ class CivitaiRestAPI(): extractor.log.debug("Using api_key authentication") self.headers["Authorization"] = "Bearer " + api_key + nsfw = extractor.config("nsfw") + if nsfw is None or nsfw is True: + nsfw = "X" + elif not nsfw: + nsfw = "Safe" + self.nsfw = nsfw + def image(self, image_id): - endpoint = "/v1/images" - params = {"imageId": image_id} - return self._pagination(endpoint, params) + return self.images({ + "imageId": image_id, + }) def images(self, params): endpoint = "/v1/images" + if "nsfw" not in params: + params["nsfw"] = self.nsfw return self._pagination(endpoint, params) def images_gallery(self, model, version, user): - endpoint = "/v1/images" - params = { + return self.images({ "modelId" : model["id"], "modelVersionId": version["id"], - "nsfw" : "X", - } - return self._pagination(endpoint, params) + }) def model(self, model_id): endpoint = "/v1/models/{}".format(model_id) @@ -372,12 +378,18 @@ class CivitaiTrpcAPI(): "x-client" : "web", "x-fingerprint" : "undefined", } - api_key = extractor.config("api-key") if api_key: extractor.log.debug("Using api_key authentication") self.headers["Authorization"] = "Bearer " + api_key + nsfw = extractor.config("nsfw") + if nsfw is None or nsfw is True: + nsfw = 31 + elif not nsfw: + nsfw = 1 + self.nsfw = nsfw + def image(self, image_id): endpoint = "image.get" params = {"id": int(image_id)} @@ -394,7 +406,7 @@ class CivitaiTrpcAPI(): "types" : ["image"], "withMeta" : False, # Metadata Only "fromPlatform" : False, # Made On-Site - "browsingLevel": 31, + "browsingLevel": self.nsfw, "include" : ["cosmetics"], } params_.update(params) @@ -412,7 +424,7 @@ class CivitaiTrpcAPI(): "modelId" : model["id"], "hidden" : False, "limit" : 50, - "browsingLevel" : 31, + "browsingLevel" : self.nsfw, } for post in self._pagination(endpoint, params): @@ -442,7 +454,7 @@ class CivitaiTrpcAPI(): "earlyAccess" : False, "fromPlatform" : False, "supportsGeneration": False, - "browsingLevel": 31, + "browsingLevel": self.nsfw, } params_.update(params) else: