Skip to content

Commit

Permalink
[deviantart] don't call 'extend()' on folders (fixes #271)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 20, 2019
1 parent bb32a2d commit f837ea9
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
archive_fmt = "f_{username}_{index}.{extension}"
pattern = BASE_PATTERN + r"/favourites/?(?:\?catpath=/)?$"
test = (
("https://www.deviantart.com/h3813067/favourites/", {
"options": (("metadata", True), ("flat", False)), # issue #271
"count": 1,
}),
("https://www.deviantart.com/h3813067/favourites/", {
"content": "6a7c74dc823ebbd457bdd9b3c2838a6ee728091e",
}),
Expand Down Expand Up @@ -642,7 +646,7 @@ def collections_folders(self, username, offset=0):
endpoint = "collections/folders"
params = {"username": username, "offset": offset, "limit": 50,
"mature_content": self.mature}
return self._pagination_list(endpoint, params)
return self._pagination_folders(endpoint, params)

def deviation(self, deviation_id):
"""Query and return info about a single Deviation"""
Expand Down Expand Up @@ -691,7 +695,7 @@ def gallery_folders(self, username, offset=0):
endpoint = "gallery/folders"
params = {"username": username, "offset": offset, "limit": 50,
"mature_content": self.mature}
return self._pagination_list(endpoint, params)
return self._pagination_folders(endpoint, params)

@memcache(keyarg=1)
def user_profile(self, username):
Expand Down Expand Up @@ -763,7 +767,7 @@ def _call(self, endpoint, params=None, expect_error=False, public=True):
self.log.error(msg)
return data

def _pagination(self, endpoint, params):
def _pagination(self, endpoint, params, extend=True):
public = True
while True:
data = self._call(endpoint, params, public=public)
Expand All @@ -775,23 +779,26 @@ def _pagination(self, endpoint, params):
self.log.debug("Switching to private access token")
public = False
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"]:
return
params["offset"] = data["next_offset"]

def _pagination_list(self, endpoint, params):
def _pagination_folders(self, endpoint, params):
result = []
result.extend(self._pagination(endpoint, params))
result.extend(self._pagination(endpoint, params, False))
return result

def _extend(self, deviations):
"""Add extended metadata to a list of deviation objects"""
if self.metadata:
for deviation, metadata in zip(
deviations, self.deviation_metadata(deviations)):
deviation.update(metadata)
deviation["tags"] = [t["tag_name"] for t in deviation["tags"]]
for deviation, metadata in zip(
deviations, self.deviation_metadata(deviations)):
deviation.update(metadata)
deviation["tags"] = [t["tag_name"] for t in deviation["tags"]]
return deviations


Expand Down

0 comments on commit f837ea9

Please sign in to comment.