[deviantart] don't call 'extend()' on folders (fixes #271)

This commit is contained in:
Mike Fährmann
2019-05-20 15:53:01 +02:00
parent bb32a2d490
commit f837ea98cb

View File

@@ -415,6 +415,10 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
archive_fmt = "f_{username}_{index}.{extension}" archive_fmt = "f_{username}_{index}.{extension}"
pattern = BASE_PATTERN + r"/favourites/?(?:\?catpath=/)?$" pattern = BASE_PATTERN + r"/favourites/?(?:\?catpath=/)?$"
test = ( test = (
("https://www.deviantart.com/h3813067/favourites/", {
"options": (("metadata", True), ("flat", False)), # issue #271
"count": 1,
}),
("https://www.deviantart.com/h3813067/favourites/", { ("https://www.deviantart.com/h3813067/favourites/", {
"content": "6a7c74dc823ebbd457bdd9b3c2838a6ee728091e", "content": "6a7c74dc823ebbd457bdd9b3c2838a6ee728091e",
}), }),
@@ -642,7 +646,7 @@ class DeviantartAPI():
endpoint = "collections/folders" endpoint = "collections/folders"
params = {"username": username, "offset": offset, "limit": 50, params = {"username": username, "offset": offset, "limit": 50,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination_list(endpoint, params) return self._pagination_folders(endpoint, params)
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"""
@@ -691,7 +695,7 @@ class DeviantartAPI():
endpoint = "gallery/folders" endpoint = "gallery/folders"
params = {"username": username, "offset": offset, "limit": 50, params = {"username": username, "offset": offset, "limit": 50,
"mature_content": self.mature} "mature_content": self.mature}
return self._pagination_list(endpoint, params) return self._pagination_folders(endpoint, params)
@memcache(keyarg=1) @memcache(keyarg=1)
def user_profile(self, username): def user_profile(self, username):
@@ -763,7 +767,7 @@ class DeviantartAPI():
self.log.error(msg) self.log.error(msg)
return data return data
def _pagination(self, endpoint, params): def _pagination(self, endpoint, params, extend=True):
public = True public = True
while True: while True:
data = self._call(endpoint, params, public=public) data = self._call(endpoint, params, public=public)
@@ -775,23 +779,26 @@ class DeviantartAPI():
self.log.debug("Switching to private access token") self.log.debug("Switching to private access token")
public = False public = False
continue continue
yield from self._extend(data["results"])
if extend and self.metadata:
self._extend(data["results"])
yield from data["results"]
if not data["has_more"]: if not data["has_more"]:
return return
params["offset"] = data["next_offset"] params["offset"] = data["next_offset"]
def _pagination_list(self, endpoint, params): def _pagination_folders(self, endpoint, params):
result = [] result = []
result.extend(self._pagination(endpoint, params)) result.extend(self._pagination(endpoint, params, False))
return result return result
def _extend(self, deviations): def _extend(self, deviations):
"""Add extended metadata to a list of deviation objects""" """Add extended metadata to a list of deviation objects"""
if self.metadata: for deviation, metadata in zip(
for deviation, metadata in zip( deviations, self.deviation_metadata(deviations)):
deviations, self.deviation_metadata(deviations)): deviation.update(metadata)
deviation.update(metadata) deviation["tags"] = [t["tag_name"] for t in deviation["tags"]]
deviation["tags"] = [t["tag_name"] for t in deviation["tags"]]
return deviations return deviations