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:
parent
10c56a561d
commit
cff3d37551
@ -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,21 +355,33 @@ class CivitaiUserImagesExtractor(CivitaiExtractor):
|
||||
pattern = USER_PATTERN + r"/images/?(?:\?([^#]+))?"
|
||||
example = "https://civitai.com/user/USER/images"
|
||||
|
||||
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)
|
||||
|
||||
def images(self):
|
||||
params = text.parse_query_list(self.groups[1])
|
||||
params = self.params
|
||||
params["username"] = text.unquote(self.groups[0])
|
||||
return self.api.images(params)
|
||||
|
||||
if params.get("section") == "reactions":
|
||||
params["authed"] = True
|
||||
params["useIndex"] = False
|
||||
if "reactions" in params:
|
||||
if isinstance(params["reactions"], str):
|
||||
params["reactions"] = (params["reactions"],)
|
||||
else:
|
||||
params["reactions"] = (
|
||||
"Like", "Dislike", "Heart", "Laugh", "Cry")
|
||||
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:
|
||||
if isinstance(params["reactions"], str):
|
||||
params["reactions"] = (params["reactions"],)
|
||||
else:
|
||||
params["username"] = text.unquote(self.groups[0])
|
||||
|
||||
params["reactions"] = (
|
||||
"Like", "Dislike", "Heart", "Laugh", "Cry")
|
||||
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",
|
||||
|
@ -5,6 +5,7 @@
|
||||
# published by the Free Software Foundation.
|
||||
|
||||
from gallery_dl.extractor import civitai
|
||||
from gallery_dl import exception
|
||||
|
||||
|
||||
__tests__ = (
|
||||
@ -177,14 +178,23 @@ __tests__ = (
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
||||
"#class": civitai.CivitaiUserImagesExtractor,
|
||||
"#auth" : True,
|
||||
"#urls" : (
|
||||
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
||||
"#category": ("", "civitai", "reactions"),
|
||||
"#class" : civitai.CivitaiUserImagesExtractor,
|
||||
"#auth" : True,
|
||||
"#urls" : (
|
||||
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/dd29c97a-1e95-4186-8df5-632736cbae79/original=true/00012-2489035818.png",
|
||||
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/5c4efa68-bb58-47c5-a716-98cd0f51f047/original=true/00013-4238863814.png",
|
||||
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/69bf3279-df2c-4ec8-b795-479e9cd3db1b/original=true/00014-3150861441.png",
|
||||
),
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
||||
"#category": ("", "civitai", "reactions"),
|
||||
"#class" : civitai.CivitaiUserImagesExtractor,
|
||||
"#auth" : False,
|
||||
"#exception": exception.AuthorizationError,
|
||||
},
|
||||
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user