Skip to content

Commit

Permalink
[deviantart] allow distinction between users and groups (#26)
Browse files Browse the repository at this point in the history
This is done by prepending "group-" to an extractor's subcategory
if the URL belongs to a group ("folder" becomes "group-folder" and
so on). This changes the configuration-path being used and is also
reflected in the output of '--list-keywords'.
  • Loading branch information
mikf committed Aug 22, 2017
1 parent e61a3a5 commit 3b21e07
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ class DeviantartExtractor(Extractor):
def __init__(self, match=None):
Extractor.__init__(self)
self.api = DeviantartAPI(self)
self.user = match.group(1) if match else ""
self.offset = 0

if match:
self.user = match.group(1)
self.group = not self.api.user_profile(self.user)
if self.group:
self.subcategory = "group-" + self.subcategory
else:
self.user = None
self.group = False

def skip(self, num):
self.offset += num
return num
Expand Down Expand Up @@ -150,11 +158,8 @@ def _find_folder(folders, name):
raise exception.NotFoundError("folder")

def _folder_urls(self, folders, category):
urlfmt = "https://{}.deviantart.com/{}/0/{}"
return [
urlfmt.format(self.user, category, folder["name"])
for folder in folders
]
url = "https://{}.deviantart.com/{}/0/".format(self.user, category)
return [url + folder["name"] for folder in folders]


class DeviantartGalleryExtractor(DeviantartExtractor):
Expand All @@ -174,7 +179,7 @@ class DeviantartGalleryExtractor(DeviantartExtractor):
]

def deviations(self):
if self.flat and self.api.user_profile(self.user):
if self.flat and not self.group:
return self.api.gallery_all(self.user, self.offset)
else:
folders = self.api.gallery_folders(self.user)
Expand All @@ -194,12 +199,12 @@ class DeviantartFolderExtractor(DeviantartExtractor):
}),
("http://majestic-da.deviantart.com/gallery/63419606/CHIBI-KAWAII", {
"url": "1df6f4312f124b0ad9f2a905c8f9e94e89c84370",
"keyword": "2cd937a33f1f9bf0d9d8807b89a25de22338edb2",
"keyword": "b651f5d540aaaf7974fa7e181e4cc54151a65e9e",
}),
]

def __init__(self, match):
DeviantartExtractor.__init__(self)
DeviantartExtractor.__init__(self, match)
self.user, fid, self.fname = match.groups()
self.folder = {"owner": self.user, "index": fid}

Expand Down Expand Up @@ -290,7 +295,7 @@ class DeviantartCollectionExtractor(DeviantartExtractor):
})]

def __init__(self, match):
DeviantartExtractor.__init__(self)
DeviantartExtractor.__init__(self, match)
self.user, cid, self.cname = match.groups()
self.collection = {"owner": self.user, "index": cid}

Expand Down Expand Up @@ -391,6 +396,7 @@ def gallery_folders(self, username, offset=0):
"mature_content": self.mature}
return self._pagination_list(endpoint, params)

@memcache(keyarg=1)
def user_profile(self, username):
"""Get user profile information"""
endpoint = "user/profile/" + username
Expand Down

0 comments on commit 3b21e07

Please sign in to comment.