[civitai] support "My Reactions" results for videos (#7608)
This commit is contained in:
@@ -175,6 +175,19 @@ class CivitaiExtractor(Extractor):
|
||||
file["generation"] = self._extract_meta_generation(file)
|
||||
yield data
|
||||
|
||||
def _image_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" not in params:
|
||||
params["reactions"] = ("Like", "Dislike", "Heart", "Laugh", "Cry")
|
||||
return self.api.images(params)
|
||||
|
||||
def _parse_query(self, value):
|
||||
return text.parse_query_list(
|
||||
value, {"tags", "reactions", "baseModels", "tools", "techniques",
|
||||
@@ -452,29 +465,17 @@ class CivitaiUserImagesExtractor(CivitaiExtractor):
|
||||
example = "https://civitai.com/user/USER/images"
|
||||
|
||||
def __init__(self, match):
|
||||
self.params = self._parse_query(match.group(2))
|
||||
user, query = match.groups()
|
||||
self.params = self._parse_query(query)
|
||||
if self.params.get("section") == "reactions":
|
||||
self.subcategory = "reactions"
|
||||
self.images = self.images_reactions
|
||||
self.subcategory = "reactions-images"
|
||||
self.images = self._image_reactions
|
||||
else:
|
||||
self.params["username"] = text.unquote(user)
|
||||
CivitaiExtractor.__init__(self, match)
|
||||
|
||||
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" not in params:
|
||||
params["reactions"] = ("Like", "Dislike", "Heart", "Laugh", "Cry")
|
||||
return self.api.images(params)
|
||||
return self.api.images(self.params)
|
||||
|
||||
|
||||
class CivitaiUserVideosExtractor(CivitaiExtractor):
|
||||
@@ -483,14 +484,19 @@ class CivitaiUserVideosExtractor(CivitaiExtractor):
|
||||
pattern = USER_PATTERN + r"/videos/?(?:\?([^#]+))?"
|
||||
example = "https://civitai.com/user/USER/videos"
|
||||
|
||||
def images(self):
|
||||
def __init__(self, match):
|
||||
user, query = match.groups()
|
||||
self.params = self._parse_query(query)
|
||||
self.params["types"] = ["video"]
|
||||
if self.params.get("section") == "reactions":
|
||||
self.subcategory = "reactions-videos"
|
||||
self.images = self._image_reactions
|
||||
else:
|
||||
self.params["username"] = text.unquote(user)
|
||||
CivitaiExtractor.__init__(self, match)
|
||||
self._image_ext = "mp4"
|
||||
|
||||
user, query = self.groups
|
||||
params = self._parse_query(query)
|
||||
params["types"] = ["video"]
|
||||
params["username"] = text.unquote(user)
|
||||
return self.api.images(params)
|
||||
images = CivitaiUserImagesExtractor.images
|
||||
|
||||
|
||||
class CivitaiRestAPI():
|
||||
|
||||
@@ -428,7 +428,7 @@ __tests__ = (
|
||||
|
||||
{
|
||||
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
||||
"#category": ("", "civitai", "reactions"),
|
||||
"#category": ("", "civitai", "reactions-images"),
|
||||
"#class" : civitai.CivitaiUserImagesExtractor,
|
||||
"#auth" : True,
|
||||
"#urls" : (
|
||||
@@ -440,7 +440,7 @@ __tests__ = (
|
||||
|
||||
{
|
||||
"#url" : "https://civitai.com/user/USER/images?section=reactions",
|
||||
"#category": ("", "civitai", "reactions"),
|
||||
"#category": ("", "civitai", "reactions-images"),
|
||||
"#class" : civitai.CivitaiUserImagesExtractor,
|
||||
"#auth" : False,
|
||||
"#exception": exception.AuthorizationError,
|
||||
@@ -454,4 +454,24 @@ __tests__ = (
|
||||
"#count" : 50,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://civitai.com/user/USER/videos?section=reactions",
|
||||
"#category": ("", "civitai", "reactions-videos"),
|
||||
"#class" : civitai.CivitaiUserVideosExtractor,
|
||||
"#auth" : True,
|
||||
"#urls" : (
|
||||
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/6a09ec54-6de4-4af1-b11d-2d0d8a66d651/quality=100/copy_C6C532CE-EC47-4A52-9138-AEF1D7756F16.Mp4",
|
||||
"https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/74cd3e71-7833-4e32-9724-b8d1702693be/quality=100/1_THANKSGIVING_CLAYMATION_TOPAZ.mp4",
|
||||
),
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://civitai.com/user/USER/videos?section=reactions",
|
||||
"#category": ("", "civitai", "reactions-videos"),
|
||||
"#class" : civitai.CivitaiUserVideosExtractor,
|
||||
"#auth" : False,
|
||||
"#exception": exception.AuthorizationError,
|
||||
},
|
||||
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user