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,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",
|
||||
|
@ -5,6 +5,7 @@
|
||||
# published by the Free Software Foundation.
|
||||
|
||||
from gallery_dl.extractor import civitai
|
||||
from gallery_dl import exception
|
||||
|
||||
|
||||
__tests__ = (
|
||||
@ -178,6 +179,7 @@ __tests__ = (
|
||||
|
||||
{
|
||||
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
||||
"#category": ("", "civitai", "reactions"),
|
||||
"#class" : civitai.CivitaiUserImagesExtractor,
|
||||
"#auth" : True,
|
||||
"#urls" : (
|
||||
@ -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,
|
||||
},
|
||||
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user