Skip to content

Commit

Permalink
[deviantart] ensure consistent username capitalization (#455)
Browse files Browse the repository at this point in the history
The 'username' field was capitalized in a very inconsistent manner:
Either all lowercase, or as given by the input URL, or with the
"original" capitalization, depending on the extractor used among
other things.

Now usernames use their original capitalization for all extractors.
('UserName' instead of 'username' or 'uSeRnAmE')
  • Loading branch information
mikf committed Nov 18, 2019
1 parent b1f0609 commit 9fdc5e7
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class DeviantartExtractor(Extractor):
"""Base class for deviantart extractors using the OAuth API"""
category = "deviantart"
directory_fmt = ("{category}", "{author[username]!l}")
directory_fmt = ("{category}", "{username}")
filename_fmt = "{category}_{index}_{title}.{extension}"
root = "https://www.deviantart.com"

Expand Down Expand Up @@ -62,6 +62,7 @@ def items(self):
self.group = not profile
if self.group:
self.subcategory = "group-" + self.subcategory
self.user = self.user.lower()
else:
self.user = profile["user"]["username"]

Expand Down Expand Up @@ -398,7 +399,7 @@ def deviations(self):
class DeviantartFolderExtractor(DeviantartExtractor):
"""Extractor for deviations inside an artist's gallery folder"""
subcategory = "folder"
directory_fmt = ("{category}", "{folder[owner]}", "{folder[title]}")
directory_fmt = ("{category}", "{username}", "{folder[title]}")
archive_fmt = "F_{folder[uuid]}_{index}.{extension}"
pattern = BASE_PATTERN + r"/gallery/(\d+)/([^/?&#]+)"
test = (
Expand All @@ -418,14 +419,19 @@ class DeviantartFolderExtractor(DeviantartExtractor):

def __init__(self, match):
DeviantartExtractor.__init__(self, match)
self.fname = match.group(4)
self.folder = {"owner": self.user, "index": match.group(3)}
self.folder = None
self.folder_id = match.group(3)
self.folder_name = match.group(4)

def deviations(self):
folders = self.api.gallery_folders(self.user)
folder = self._find_folder(folders, self.fname)
self.folder["title"] = folder["name"]
self.folder["uuid"] = folder["folderid"]
folder = self._find_folder(folders, self.folder_name)
self.folder = {
"title": folder["name"],
"uuid" : folder["folderid"],
"index": self.folder_id,
"owner": self.user,
}
return self.api.gallery(self.user, folder["folderid"], self.offset)

def prepare(self, deviation):
Expand Down Expand Up @@ -472,6 +478,7 @@ def deviations(self):

if deviation_id:
deviation = self.api.deviation(deviation_id)
deviation["username"] = deviation["author"]["username"]
pos = page.find("dev-page-download", pos)
if pos >= 0:
deviation["_download"] = {
Expand Down Expand Up @@ -530,8 +537,8 @@ def deviations(self):
class DeviantartCollectionExtractor(DeviantartExtractor):
"""Extractor for a single favorite collection"""
subcategory = "collection"
directory_fmt = ("{category}", "{collection[owner]}",
"Favourites", "{collection[title]}")
directory_fmt = ("{category}", "{username}", "Favourites",
"{collection[title]}")
archive_fmt = "C_{collection[uuid]}_{index}.{extension}"
pattern = BASE_PATTERN + r"/favourites/(\d+)/([^/?&#]+)"
test = (
Expand All @@ -546,14 +553,19 @@ class DeviantartCollectionExtractor(DeviantartExtractor):

def __init__(self, match):
DeviantartExtractor.__init__(self, match)
_, _, cid, self.cname = match.groups()
self.collection = {"owner": self.user, "index": cid}
self.collection = None
self.collection_id = match.group(3)
self.collection_name = match.group(4)

def deviations(self):
folders = self.api.collections_folders(self.user)
folder = self._find_folder(folders, self.cname)
self.collection["title"] = folder["name"]
self.collection["uuid"] = folder["folderid"]
folder = self._find_folder(folders, self.collection_name)
self.collection = {
"title": folder["name"],
"uuid" : folder["folderid"],
"index": self.collection_id,
"owner": self.user,
}
return self.api.collections(self.user, folder["folderid"], self.offset)

def prepare(self, deviation):
Expand Down Expand Up @@ -668,7 +680,7 @@ def _extract(self, data):

# prepare deviation metadata
deviation["description"] = extended.get("description", "")
deviation["username"] = self.user.lower()
deviation["username"] = deviation["author"]["username"]
deviation["stats"] = extended["stats"]
deviation["stats"]["comments"] = data["comments"]["total"]
deviation["index"] = deviation["deviationId"]
Expand Down

0 comments on commit 9fdc5e7

Please sign in to comment.