diff options
Diffstat (limited to 'gallery_dl/extractor/deviantart.py')
| -rw-r--r-- | gallery_dl/extractor/deviantart.py | 75 |
1 files changed, 66 insertions, 9 deletions
diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index ab32a00..eeee74a 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -58,9 +58,12 @@ class DeviantartExtractor(Extractor): def items(self): if self.user: - self.group = not self.api.user_profile(self.user) + profile = self.api.user_profile(self.user) + self.group = not profile if self.group: self.subcategory = "group-" + self.subcategory + else: + self.user = profile["user"]["username"] yield Message.Version, 1 for deviation in self.deviations(): @@ -260,11 +263,53 @@ class DeviantartExtractor(Extractor): content.update(download) +class DeviantartUserExtractor(Extractor): + """Extractor for an artist's user profile""" + category = "deviantart" + subcategory = "user" + pattern = BASE_PATTERN + r"/?$" + test = ( + ("https://www.deviantart.com/shimoda7", { + "options": (("include", "gsjf"),), + "pattern": r"/shimoda7/(gallery(/scraps)?|posts|favourites)", + "count": 4, + }), + ("https://shimoda7.deviantart.com/"), + ) + + def __init__(self, match): + Extractor.__init__(self, match) + self.user = match.group(1) or match.group(2) + + incl = self.config("include") or "g" + if isinstance(incl, list): + incl = "".join(item[0] for item in incl if item) + self.include = incl.lower() + + def items(self): + base = "https://www.deviantart.com/{}/".format(self.user) + incl = self.include + data = {} + + if "g" in incl: + data["_extractor"] = DeviantartGalleryExtractor + yield Message.Queue, base + "gallery", data + if "s" in incl: + data["_extractor"] = DeviantartScrapsExtractor + yield Message.Queue, base + "gallery/scraps", data + if "j" in incl: + data["_extractor"] = DeviantartJournalExtractor + yield Message.Queue, base + "posts", data + if "f" in incl: + data["_extractor"] = DeviantartFavoriteExtractor + yield Message.Queue, base + "favourites", data + + class DeviantartGalleryExtractor(DeviantartExtractor): """Extractor for all deviations from an artist's gallery""" subcategory = "gallery" archive_fmt = "g_{username}_{index}.{extension}" - pattern = BASE_PATTERN + r"(?:/(?:gallery/?(?:\?catpath=/)?)?)?$" + pattern = BASE_PATTERN + r"/gallery(?:/all|/?\?catpath=)?/?$" test = ( ("https://www.deviantart.com/shimoda7/gallery/", { "pattern": r"https://(www.deviantart.com/download/\d+/" @@ -315,12 +360,12 @@ class DeviantartGalleryExtractor(DeviantartExtractor): }, }), # group - ("https://www.deviantart.com/yakuzafc", { + ("https://www.deviantart.com/yakuzafc/gallery", { "pattern": r"https://www.deviantart.com/yakuzafc/gallery/0/", "count": ">= 15", }), # 'folders' option (#276) - ("https://www.deviantart.com/justatest235723", { + ("https://www.deviantart.com/justatest235723/gallery", { "count": 3, "options": (("metadata", 1), ("folders", 1), ("original", 0)), "keyword": { @@ -334,10 +379,12 @@ class DeviantartGalleryExtractor(DeviantartExtractor): ("https://www.deviantart.com/shimoda8/gallery/", { "exception": exception.NotFoundError, }), - # old-style URLs + + ("https://www.deviantart.com/shimoda7/gallery"), + ("https://www.deviantart.com/shimoda7/gallery/all"), ("https://www.deviantart.com/shimoda7/gallery/?catpath=/"), ("https://shimoda7.deviantart.com/gallery/"), - ("https://yakuzafc.deviantart.com/"), + ("https://shimoda7.deviantart.com/gallery/all/"), ("https://shimoda7.deviantart.com/gallery/?catpath=/"), ) @@ -794,6 +841,14 @@ class DeviantartScrapsExtractor(DeviantartExtractorV2): ) def deviations(self): + # copy self.session + session = self.session.__class__() + for attr in session.__attrs__: + setattr(session, attr, getattr(self.session, attr, None)) + + # reset cookies in the original session object + self.session.cookies = session.cookies.__class__() + url = self.root + "/_napi/da-user-profile/api/gallery/contents" params = { "username" : self.user, @@ -806,7 +861,8 @@ class DeviantartScrapsExtractor(DeviantartExtractorV2): } while True: - data = self.request(url, params=params, headers=headers).json() + data = self.request( + url, session=session, params=params, headers=headers).json() for obj in data["results"]: yield obj["deviation"] @@ -974,11 +1030,12 @@ class DeviantartAPI(): auth = (self.client_id, self.client_secret) response = self.extractor.request( - url, method="POST", data=data, auth=auth) + url, method="POST", data=data, auth=auth, fatal=False) data = response.json() if response.status_code != 200: - raise exception.AuthenticationError('"{} ({})"'.format( + self.log.debug("Server response: %s", data) + raise exception.AuthenticationError('"{}" ({})'.format( data.get("error_description"), data.get("error"))) if refresh_token: _refresh_token_cache.update(refresh_token, data["refresh_token"]) |
