[deviantart] support "All" favorites and add "mature" option
- since there is apparently no actual way to get the "All" favorites listing via API, corresponding URLs (.../favourites/?catpath=/) will be handled by yielding all deviations from all favorite collections of that user - the "mature" config key works on a per extractor basis (like "username" or "password"). values can be the strings "true" or "false", or the booleans true or false. - (#14)
This commit is contained in:
@@ -113,12 +113,16 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
|
|||||||
directory_fmt = ["{category}", "{subcategory}",
|
directory_fmt = ["{category}", "{subcategory}",
|
||||||
"{collection[owner]} - {collection[title]}"]
|
"{collection[owner]} - {collection[title]}"]
|
||||||
pattern = [r"(?:https?://)?([^\.]+)\.deviantart\.com/favourites"
|
pattern = [r"(?:https?://)?([^\.]+)\.deviantart\.com/favourites"
|
||||||
r"(?:/(\d+)/([^/?]+))?"]
|
r"(?:/((\d+)/([^/?]+)|\?catpath=/))?"]
|
||||||
test = [
|
test = [
|
||||||
("http://rosuuri.deviantart.com/favourites/58951174/Useful", {
|
("http://rosuuri.deviantart.com/favourites/58951174/Useful", {
|
||||||
"url": "9e8d971c80db099b95d1c785399e2bc6eb96cd07",
|
"url": "9e8d971c80db099b95d1c785399e2bc6eb96cd07",
|
||||||
"keyword": "808f6c5e411c984b35c911dbf61b648627acda93",
|
"keyword": "808f6c5e411c984b35c911dbf61b648627acda93",
|
||||||
}),
|
}),
|
||||||
|
("http://gendo0032.deviantart.com/favourites/?catpath=/", {
|
||||||
|
"url": "6f3dc026a8391b29cc67aec880b3a0d705787572",
|
||||||
|
"keyword": "646c3d156b0cc7a0739c2170c524570733cc24ff",
|
||||||
|
}),
|
||||||
("http://h3813067.deviantart.com/favourites/", {
|
("http://h3813067.deviantart.com/favourites/", {
|
||||||
"url": "71345ce3bef5b19bd2a56d7b96e6b5ddba747c2e",
|
"url": "71345ce3bef5b19bd2a56d7b96e6b5ddba747c2e",
|
||||||
"keyword": "51e88d400c3fb69ae0b5a618ef21a282697185fe",
|
"keyword": "51e88d400c3fb69ae0b5a618ef21a282697185fe",
|
||||||
@@ -128,9 +132,13 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
|
|||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
DeviantartExtractor.__init__(self)
|
DeviantartExtractor.__init__(self)
|
||||||
self.user, self.favid, self.favname = match.groups()
|
self.user, path, self.favid, self.favname = match.groups()
|
||||||
if not self.favname:
|
if not self.favname:
|
||||||
self.favname = "Featured"
|
if path == "?catpath=/":
|
||||||
|
self.favname = "All"
|
||||||
|
self.deviations = self._deviations_all
|
||||||
|
else:
|
||||||
|
self.favname = "Featured"
|
||||||
self.collection = {
|
self.collection = {
|
||||||
"owner": self.user,
|
"owner": self.user,
|
||||||
"title": self.favname,
|
"title": self.favname,
|
||||||
@@ -155,6 +163,14 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
|
|||||||
self.user, folder["folderid"], self.offset)
|
self.user, folder["folderid"], self.offset)
|
||||||
raise exception.NotFoundError("collection")
|
raise exception.NotFoundError("collection")
|
||||||
|
|
||||||
|
def _deviations_all(self):
|
||||||
|
import itertools
|
||||||
|
return itertools.chain.from_iterable([
|
||||||
|
self.api.collections_folderid(
|
||||||
|
self.user, folder["folderid"], self.offset)
|
||||||
|
for folder in self.api.collections_folders(self.user)
|
||||||
|
])
|
||||||
|
|
||||||
def prepare(self, deviation):
|
def prepare(self, deviation):
|
||||||
DeviantartExtractor.prepare(deviation)
|
DeviantartExtractor.prepare(deviation)
|
||||||
deviation["collection"] = self.collection
|
deviation["collection"] = self.collection
|
||||||
@@ -170,6 +186,9 @@ class DeviantartAPI():
|
|||||||
self.client_id = client_id
|
self.client_id = client_id
|
||||||
self.client_secret = client_secret
|
self.client_secret = client_secret
|
||||||
self.delay = 0
|
self.delay = 0
|
||||||
|
self.mature = extractor.config("mature", True)
|
||||||
|
if not isinstance(self.mature, str):
|
||||||
|
self.mature = "true" if self.mature else "false"
|
||||||
|
|
||||||
def deviation(self, deviation_id):
|
def deviation(self, deviation_id):
|
||||||
"""Query and return info about a single Deviation"""
|
"""Query and return info about a single Deviation"""
|
||||||
@@ -180,21 +199,21 @@ class DeviantartAPI():
|
|||||||
"""Yield all Deviation-objects of a specific user"""
|
"""Yield all Deviation-objects of a specific user"""
|
||||||
endpoint = "gallery/all"
|
endpoint = "gallery/all"
|
||||||
params = {"username": username, "offset": offset, "limit": 10,
|
params = {"username": username, "offset": offset, "limit": 10,
|
||||||
"mature_content": "true"}
|
"mature_content": self.mature}
|
||||||
return self._pagination(endpoint, params)
|
return self._pagination(endpoint, params)
|
||||||
|
|
||||||
def collections_folders(self, username, offset=0):
|
def collections_folders(self, username, offset=0):
|
||||||
"""Yield all collection folders of a specific user"""
|
"""Yield all collection folders of a specific user"""
|
||||||
endpoint = "collections/folders"
|
endpoint = "collections/folders"
|
||||||
params = {"username": username, "offset": offset, "limit": 10,
|
params = {"username": username, "offset": offset, "limit": 10,
|
||||||
"mature_content": "true"}
|
"mature_content": self.mature}
|
||||||
return self._pagination(endpoint, params)
|
return self._pagination(endpoint, params)
|
||||||
|
|
||||||
def collections_folderid(self, username, folder_id, offset=0):
|
def collections_folderid(self, username, folder_id, offset=0):
|
||||||
"""Yield all Deviation-objects contained in a collection folder"""
|
"""Yield all Deviation-objects contained in a collection folder"""
|
||||||
endpoint = "collections/" + folder_id
|
endpoint = "collections/" + folder_id
|
||||||
params = {"username": username, "offset": offset, "limit": 10,
|
params = {"username": username, "offset": offset, "limit": 10,
|
||||||
"mature_content": "true"}
|
"mature_content": self.mature}
|
||||||
return self._pagination(endpoint, params)
|
return self._pagination(endpoint, params)
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user