diff options
Diffstat (limited to 'gallery_dl/extractor/redgifs.py')
| -rw-r--r-- | gallery_dl/extractor/redgifs.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/gallery_dl/extractor/redgifs.py b/gallery_dl/extractor/redgifs.py index 506f6ac..612faac 100644 --- a/gallery_dl/extractor/redgifs.py +++ b/gallery_dl/extractor/redgifs.py @@ -163,24 +163,27 @@ class RedgifsSearchExtractor(RedgifsExtractor): subcategory = "search" directory_fmt = ("{category}", "Search", "{search}") pattern = (r"(?:https?://)?(?:\w+\.)?redgifs\.com" - r"/(?:gifs/([^/?#]+)|browse)(?:/?\?([^#]+))?") + r"/(?:gifs/([^/?#]+)|search(?:/gifs)?()|browse)" + r"(?:/?\?([^#]+))?") example = "https://www.redgifs.com/gifs/TAG" - def __init__(self, match): - RedgifsExtractor.__init__(self, match) - self.search, self.query = match.groups() - def metadata(self): - self.params = text.parse_query(self.query) - if self.search: - self.params["tags"] = text.unquote(self.search) + tag, self.search, query = self.groups - return {"search": (self.params.get("tags") or - self.params.get("order") or + self.params = params = text.parse_query(query) + if tag is not None: + params["tags"] = text.unquote(tag) + + return {"search": (params.get("query") or + params.get("tags") or + params.get("order") or "trending")} def gifs(self): - return self.api.search(self.params) + if self.search is None: + return self.api.gifs_search(self.params) + else: + return self.api.search_gifs(self.params) class RedgifsImageExtractor(RedgifsExtractor): @@ -205,9 +208,9 @@ class RedgifsAPI(): def __init__(self, extractor): self.extractor = extractor self.headers = { - "authorization" : None, - "content-type" : "application/json", - "x-customheader": extractor.root + "/", + "Accept" : "application/json, text/plain, */*", + "Referer" : extractor.root + "/", + "Authorization" : None, "Origin" : extractor.root, } @@ -242,14 +245,18 @@ class RedgifsAPI(): params = {"count": 30, "order": order} return self._pagination(endpoint, params) - def search(self, params): + def gifs_search(self, params): endpoint = "/v2/gifs/search" params["search_text"] = params.pop("tags", None) return self._pagination(endpoint, params) + def search_gifs(self, params): + endpoint = "/v2/search/gifs" + return self._pagination(endpoint, params) + def _call(self, endpoint, params=None): url = self.API_ROOT + endpoint - self.headers["authorization"] = self._auth() + self.headers["Authorization"] = self._auth() return self.extractor.request( url, params=params, headers=self.headers).json() @@ -270,6 +277,6 @@ class RedgifsAPI(): def _auth(self): # https://github.com/Redgifs/api/wiki/Temporary-tokens url = self.API_ROOT + "/v2/auth/temporary" - self.headers["authorization"] = None + self.headers["Authorization"] = None return "Bearer " + self.extractor.request( url, headers=self.headers).json()["token"] |
