diff options
| author | 2021-10-05 23:30:05 -0400 | |
|---|---|---|
| committer | 2021-10-05 23:30:05 -0400 | |
| commit | 34ba2951b8c523713425c98addb9256ea05c946f (patch) | |
| tree | 6ec7e96d0c6e6f6e94b6b97ecd8c0a414ceef93d /gallery_dl/extractor/deviantart.py | |
| parent | 3f5483df9075ae526f4c54f4cbe80edeabf6d4cc (diff) | |
New upstream version 1.19.0.upstream/1.19.0
Diffstat (limited to 'gallery_dl/extractor/deviantart.py')
| -rw-r--r-- | gallery_dl/extractor/deviantart.py | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index b4ac742..7dac770 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -46,6 +46,13 @@ class DeviantartExtractor(Extractor): self.group = False self.api = None + unwatch = self.config("auto-unwatch") + if unwatch: + self.unwatch = [] + self.finalize = self._unwatch_premium + else: + self.unwatch = None + if self.quality: self.quality = ",q_{}".format(self.quality) @@ -318,44 +325,48 @@ class DeviantartExtractor(Extractor): except KeyError: pass - # check accessibility - if self.api.refresh_token_key: - dev = self.api.deviation(deviation["deviationid"], False) - has_access = dev["premium_folder_data"]["has_access"] - username = dev["author"]["username"] - folder = dev["premium_folder_data"] - - if not has_access and folder["type"] == "watchers" and \ - self.config("auto-watch"): - if self.api.user_friends_watch(username): - has_access = True - self.log.info( - "Watching %s for premium folder access", username) - else: - self.log.warning( - "Error when trying to watch %s. " - "Try again with a new refresh-token", username) - else: + if not self.api.refresh_token_key: self.log.warning( "Unable to access premium content (no refresh-token)") self._fetch_premium = lambda _: None return None + dev = self.api.deviation(deviation["deviationid"], False) + folder = dev["premium_folder_data"] + username = dev["author"]["username"] + has_access = folder["has_access"] + + if not has_access and folder["type"] == "watchers" and \ + self.config("auto-watch"): + if self.unwatch is not None: + self.unwatch.append(username) + if self.api.user_friends_watch(username): + has_access = True + self.log.info( + "Watching %s for premium folder access", username) + else: + self.log.warning( + "Error when trying to watch %s. " + "Try again with a new refresh-token", username) + if has_access: self.log.info("Fetching premium folder data") else: self.log.warning("Unable to access premium content (type: %s)", folder["type"]) - self._fetch_premium = lambda _: None - return None - # fill cache cache = self._premium_cache for dev in self.api.gallery( username, folder["gallery_id"], public=False): - cache[dev["deviationid"]] = dev + cache[dev["deviationid"]] = dev if has_access else None + return cache[deviation["deviationid"]] + def _unwatch_premium(self): + for username in self.unwatch: + self.log.info("Unwatching %s", username) + self.api.user_friends_unwatch(username) + class DeviantartUserExtractor(DeviantartExtractor): """Extractor for an artist's user profile""" @@ -823,7 +834,7 @@ class DeviantartWatchPostsExtractor(DeviantartExtractor): class DeviantartDeviationExtractor(DeviantartExtractor): """Extractor for single deviations""" subcategory = "deviation" - archive_fmt = "{index}.{extension}" + archive_fmt = "g_{_username}_{index}.{extension}" pattern = BASE_PATTERN + r"/(art|journal)/(?:[^/?#]+-)?(\d+)" test = ( (("https://www.deviantart.com/shimoda7/art/For-the-sake-10073852"), { @@ -1153,13 +1164,15 @@ class DeviantartOAuthAPI(): "mature_content" : self.mature, } return self._call( - endpoint, method="POST", data=data, public=False, fatal=False) + endpoint, method="POST", data=data, public=False, fatal=False, + ).get("success") def user_friends_unwatch(self, username): """Unwatch a user""" endpoint = "user/friends/unwatch/" + username return self._call( - endpoint, method="POST", public=False, fatal=False) + endpoint, method="POST", public=False, fatal=False, + ).get("success") def authenticate(self, refresh_token_key): """Authenticate the application by requesting an access token""" |
