@@ -896,6 +896,28 @@ Description
|
|||||||
See `Filters <https://derpibooru.org/filters>`_ for details.
|
See `Filters <https://derpibooru.org/filters>`_ for details.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.deviantart.auto-watch
|
||||||
|
-------------------------------
|
||||||
|
Type
|
||||||
|
``bool``
|
||||||
|
Default
|
||||||
|
``false``
|
||||||
|
Description
|
||||||
|
Automatically watch users when encountering "Watchers-Only Deviations"
|
||||||
|
(requires a `refresh-token <extractor.deviantart.refresh-token_>`_).
|
||||||
|
|
||||||
|
|
||||||
|
extractor.deviantart.auto-unwatch
|
||||||
|
---------------------------------
|
||||||
|
Type
|
||||||
|
``bool``
|
||||||
|
Default
|
||||||
|
``false``
|
||||||
|
Description
|
||||||
|
After watching a user through `auto-watch <extractor.deviantart.auto-watch_>`_,
|
||||||
|
unwatch that user at the end of the current extractor run.
|
||||||
|
|
||||||
|
|
||||||
extractor.deviantart.comments
|
extractor.deviantart.comments
|
||||||
-----------------------------
|
-----------------------------
|
||||||
Type
|
Type
|
||||||
@@ -1053,17 +1075,6 @@ Description
|
|||||||
or whenever your `cache file <cache.file_>`__ is deleted or cleared.
|
or whenever your `cache file <cache.file_>`__ is deleted or cleared.
|
||||||
|
|
||||||
|
|
||||||
extractor.deviantart.auto-watch
|
|
||||||
-------------------------------
|
|
||||||
Type
|
|
||||||
``bool``
|
|
||||||
Default
|
|
||||||
``false``
|
|
||||||
Description
|
|
||||||
Automatically watch users when encountering "Watchers-Only Deviations"
|
|
||||||
(requires a `refresh-token <extractor.deviantart.refresh-token_>`_).
|
|
||||||
|
|
||||||
|
|
||||||
extractor.deviantart.wait-min
|
extractor.deviantart.wait-min
|
||||||
-----------------------------
|
-----------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -46,6 +46,13 @@ class DeviantartExtractor(Extractor):
|
|||||||
self.group = False
|
self.group = False
|
||||||
self.api = None
|
self.api = None
|
||||||
|
|
||||||
|
unwatch = self.config("auto-unwatch")
|
||||||
|
if unwatch:
|
||||||
|
self.unwatch = []
|
||||||
|
self.finalize = self._unwatch_premium
|
||||||
|
else:
|
||||||
|
self.unwatch = None
|
||||||
|
|
||||||
if self.quality:
|
if self.quality:
|
||||||
self.quality = ",q_{}".format(self.quality)
|
self.quality = ",q_{}".format(self.quality)
|
||||||
|
|
||||||
@@ -318,44 +325,48 @@ class DeviantartExtractor(Extractor):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# check accessibility
|
if not self.api.refresh_token_key:
|
||||||
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:
|
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"Unable to access premium content (no refresh-token)")
|
"Unable to access premium content (no refresh-token)")
|
||||||
self._fetch_premium = lambda _: None
|
self._fetch_premium = lambda _: None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if has_access:
|
dev = self.api.deviation(deviation["deviationid"], False)
|
||||||
self.log.info("Fetching premium folder data")
|
folder = dev["premium_folder_data"]
|
||||||
else:
|
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 not has_access:
|
||||||
self.log.warning("Unable to access premium content (type: %s)",
|
self.log.warning("Unable to access premium content (type: %s)",
|
||||||
folder["type"])
|
folder["type"])
|
||||||
self._fetch_premium = lambda _: None
|
self._fetch_premium = lambda _: None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# fill cache
|
self.log.info("Fetching premium folder data")
|
||||||
cache = self._premium_cache
|
cache = self._premium_cache
|
||||||
for dev in self.api.gallery(
|
for dev in self.api.gallery(
|
||||||
username, folder["gallery_id"], public=False):
|
username, folder["gallery_id"], public=False):
|
||||||
cache[dev["deviationid"]] = dev
|
cache[dev["deviationid"]] = dev
|
||||||
return cache[deviation["deviationid"]]
|
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):
|
class DeviantartUserExtractor(DeviantartExtractor):
|
||||||
"""Extractor for an artist's user profile"""
|
"""Extractor for an artist's user profile"""
|
||||||
@@ -1153,13 +1164,15 @@ class DeviantartOAuthAPI():
|
|||||||
"mature_content" : self.mature,
|
"mature_content" : self.mature,
|
||||||
}
|
}
|
||||||
return self._call(
|
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):
|
def user_friends_unwatch(self, username):
|
||||||
"""Unwatch a user"""
|
"""Unwatch a user"""
|
||||||
endpoint = "user/friends/unwatch/" + username
|
endpoint = "user/friends/unwatch/" + username
|
||||||
return self._call(
|
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):
|
def authenticate(self, refresh_token_key):
|
||||||
"""Authenticate the application by requesting an access token"""
|
"""Authenticate the application by requesting an access token"""
|
||||||
|
|||||||
Reference in New Issue
Block a user