From 6ce16c6d319229069aec8ddeb0bb712b459de35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 28 Aug 2021 23:42:10 +0200 Subject: [PATCH] [deviantart] add 'tag' extractor (closes #1803) --- docs/supportedsites.md | 2 +- gallery_dl/extractor/deviantart.py | 42 +++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 94736fbc..1e9b106c 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -124,7 +124,7 @@ Consider all sites to be NSFW unless otherwise known. DeviantArt https://www.deviantart.com/ - Collections, Deviations, Favorites, Folders, Galleries, Journals, Popular Images, Scraps, Sta.sh, User Profiles, Watches + Collections, Deviations, Favorites, Folders, Galleries, Journals, Popular Images, Scraps, Sta.sh, Tag Searches, User Profiles, Watches OAuth diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index 18fa35d3..59d58e17 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -762,6 +762,30 @@ class DeviantartPopularExtractor(DeviantartExtractor): 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" @@ -1004,6 +1028,17 @@ class DeviantartOAuthAPI(): } 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" @@ -1209,7 +1244,12 @@ class DeviantartOAuthAPI(): 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 = []