1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-21 18:22:30 +01:00

[civitai] update "My Reactions" handling (#6263)

- use "reactions" subcategory
- raise exception when no api-key or cookies are present
This commit is contained in:
Mike Fährmann 2024-10-20 14:56:56 +02:00
parent 10c56a561d
commit cff3d37551
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 41 additions and 19 deletions

View File

@ -9,7 +9,7 @@
"""Extractors for https://www.civitai.com/"""
from .common import Extractor, Message
from .. import text, util
from .. import text, util, exception
import itertools
import time
@ -355,10 +355,25 @@ class CivitaiUserImagesExtractor(CivitaiExtractor):
pattern = USER_PATTERN + r"/images/?(?:\?([^#]+))?"
example = "https://civitai.com/user/USER/images"
def images(self):
params = text.parse_query_list(self.groups[1])
def __init__(self, match):
self.params = text.parse_query_list(match.group(2))
if self.params.get("section") == "reactions":
self.subcategory = "reactions"
self.images = self.images_reactions
CivitaiExtractor.__init__(self, match)
if params.get("section") == "reactions":
def images(self):
params = self.params
params["username"] = text.unquote(self.groups[0])
return self.api.images(params)
def images_reactions(self):
if "Authorization" not in self.api.headers and \
not self.cookies.get(
"__Secure-civitai-token", domain=".civitai.com"):
raise exception.AuthorizationError("api-key or cookies required")
params = self.params
params["authed"] = True
params["useIndex"] = False
if "reactions" in params:
@ -367,9 +382,6 @@ class CivitaiUserImagesExtractor(CivitaiExtractor):
else:
params["reactions"] = (
"Like", "Dislike", "Heart", "Laugh", "Cry")
else:
params["username"] = text.unquote(self.groups[0])
return self.api.images(params)
@ -450,14 +462,14 @@ class CivitaiRestAPI():
class CivitaiTrpcAPI():
"""Interface for the Civitai TRPC API"""
"""Interface for the Civitai tRPC API"""
def __init__(self, extractor):
self.extractor = extractor
self.root = extractor.root + "/api/trpc/"
self.headers = {
"content-type" : "application/json",
"x-client-version": "5.0.146",
"x-client-version": "5.0.185",
"x-client-date" : "",
"x-client" : "web",
"x-fingerprint" : "undefined",

View File

@ -5,6 +5,7 @@
# published by the Free Software Foundation.
from gallery_dl.extractor import civitai
from gallery_dl import exception
__tests__ = (
@ -178,7 +179,8 @@ __tests__ = (
{
"#url" : "https://civitai.com/user/USER/images?section=reactions",
"#class": civitai.CivitaiUserImagesExtractor,
"#category": ("", "civitai", "reactions"),
"#class" : civitai.CivitaiUserImagesExtractor,
"#auth" : True,
"#urls" : (
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/dd29c97a-1e95-4186-8df5-632736cbae79/original=true/00012-2489035818.png",
@ -187,4 +189,12 @@ __tests__ = (
),
},
{
"#url" : "https://civitai.com/user/USER/images?section=reactions",
"#category": ("", "civitai", "reactions"),
"#class" : civitai.CivitaiUserImagesExtractor,
"#auth" : False,
"#exception": exception.AuthorizationError,
},
)