Skip to content

Commit

Permalink
[deviantart] add 'tag' extractor (closes #1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 28, 2021
1 parent 4e9f8fe commit 6ce16c6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Consider all sites to be NSFW unless otherwise known.
<tr>
<td>DeviantArt</td>
<td>https://www.deviantart.com/</td>
<td>Collections, Deviations, Favorites, Folders, Galleries, Journals, Popular Images, Scraps, Sta.sh, User Profiles, Watches</td>
<td>Collections, Deviations, Favorites, Folders, Galleries, Journals, Popular Images, Scraps, Sta.sh, Tag Searches, User Profiles, Watches</td>
<td><a href="https://github.com/mikf/gallery-dl#oauth">OAuth</a></td>
</tr>
<tr>
Expand Down
42 changes: 41 additions & 1 deletion gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,30 @@ def prepare(self, deviation):
deviation["popular"] = self.popular


class DeviantartTagExtractor(DeviantartExtractor):
"""Extractor for deviations from tag searches"""
subcategory = "tag"
directory_fmt = ("{category}", "Tags", "{search_tags}")
archive_fmt = "T_{search_tags}_{index}.{extension}"
pattern = r"(?:https?://)?www\.deviantart\.com/tag/([^/?#]+)"
test = ("https://www.deviantart.com/tag/nature", {
"options": (("original", False),),
"range": "1-30",
"count": 30,
})

def __init__(self, match):
DeviantartExtractor.__init__(self, match)
self.tag = text.unquote(match.group(1))

def deviations(self):
return self.api.browse_tags(self.tag, self.offset)

def prepare(self, deviation):
DeviantartExtractor.prepare(self, deviation)
deviation["search_tags"] = self.tag


class DeviantartWatchExtractor(DeviantartExtractor):
"""Extractor for Deviations from watched users"""
subcategory = "watch"
Expand Down Expand Up @@ -1004,6 +1028,17 @@ def browse_popular(self, query=None, timerange=None, offset=0):
}
return self._pagination(endpoint, params)

def browse_tags(self, tag, offset=0):
""" Browse a tag """
endpoint = "browse/tags"
params = {
"tag" : tag,
"offset" : offset,
"limit" : 50,
"mature_content": self.mature,
}
return self._pagination(endpoint, params)

def browse_user_journals(self, username, offset=0):
"""Yield all journal entries of a specific user"""
endpoint = "browse/user/journals"
Expand Down Expand Up @@ -1209,7 +1244,12 @@ def _pagination(self, endpoint, params,

if not data["has_more"]:
return
params["offset"] = data["next_offset"]
if "next_cursor" in data:
params["offset"] = None
params["cursor"] = data["next_cursor"]
else:
params["offset"] = data["next_offset"]
params["cursor"] = None

def _pagination_folders(self, endpoint, params):
result = []
Expand Down

0 comments on commit 6ce16c6

Please sign in to comment.