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/"""
|
"""Extractors for https://www.civitai.com/"""
|
||||||
|
|
||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from .. import text, util
|
from .. import text, util, exception
|
||||||
import itertools
|
import itertools
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -355,21 +355,33 @@ class CivitaiUserImagesExtractor(CivitaiExtractor):
|
|||||||
pattern = USER_PATTERN + r"/images/?(?:\?([^#]+))?"
|
pattern = USER_PATTERN + r"/images/?(?:\?([^#]+))?"
|
||||||
example = "https://civitai.com/user/USER/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):
|
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":
|
def images_reactions(self):
|
||||||
params["authed"] = True
|
if "Authorization" not in self.api.headers and \
|
||||||
params["useIndex"] = False
|
not self.cookies.get(
|
||||||
if "reactions" in params:
|
"__Secure-civitai-token", domain=".civitai.com"):
|
||||||
if isinstance(params["reactions"], str):
|
raise exception.AuthorizationError("api-key or cookies required")
|
||||||
params["reactions"] = (params["reactions"],)
|
|
||||||
else:
|
params = self.params
|
||||||
params["reactions"] = (
|
params["authed"] = True
|
||||||
"Like", "Dislike", "Heart", "Laugh", "Cry")
|
params["useIndex"] = False
|
||||||
|
if "reactions" in params:
|
||||||
|
if isinstance(params["reactions"], str):
|
||||||
|
params["reactions"] = (params["reactions"],)
|
||||||
else:
|
else:
|
||||||
params["username"] = text.unquote(self.groups[0])
|
params["reactions"] = (
|
||||||
|
"Like", "Dislike", "Heart", "Laugh", "Cry")
|
||||||
return self.api.images(params)
|
return self.api.images(params)
|
||||||
|
|
||||||
|
|
||||||
@ -450,14 +462,14 @@ class CivitaiRestAPI():
|
|||||||
|
|
||||||
|
|
||||||
class CivitaiTrpcAPI():
|
class CivitaiTrpcAPI():
|
||||||
"""Interface for the Civitai TRPC API"""
|
"""Interface for the Civitai tRPC API"""
|
||||||
|
|
||||||
def __init__(self, extractor):
|
def __init__(self, extractor):
|
||||||
self.extractor = extractor
|
self.extractor = extractor
|
||||||
self.root = extractor.root + "/api/trpc/"
|
self.root = extractor.root + "/api/trpc/"
|
||||||
self.headers = {
|
self.headers = {
|
||||||
"content-type" : "application/json",
|
"content-type" : "application/json",
|
||||||
"x-client-version": "5.0.146",
|
"x-client-version": "5.0.185",
|
||||||
"x-client-date" : "",
|
"x-client-date" : "",
|
||||||
"x-client" : "web",
|
"x-client" : "web",
|
||||||
"x-fingerprint" : "undefined",
|
"x-fingerprint" : "undefined",
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
from gallery_dl.extractor import civitai
|
from gallery_dl.extractor import civitai
|
||||||
|
from gallery_dl import exception
|
||||||
|
|
||||||
|
|
||||||
__tests__ = (
|
__tests__ = (
|
||||||
@ -177,14 +178,23 @@ __tests__ = (
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
||||||
"#class": civitai.CivitaiUserImagesExtractor,
|
"#category": ("", "civitai", "reactions"),
|
||||||
"#auth" : True,
|
"#class" : civitai.CivitaiUserImagesExtractor,
|
||||||
"#urls" : (
|
"#auth" : True,
|
||||||
|
"#urls" : (
|
||||||
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/dd29c97a-1e95-4186-8df5-632736cbae79/original=true/00012-2489035818.png",
|
"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/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",
|
"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