Skip to content

Commit

Permalink
merge #4667: [redgifs] fix 'niches' extraction (#4666)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Oct 16, 2023
2 parents 2911ed1 + db3363a commit 727c8ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions gallery_dl/extractor/redgifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,17 @@ def items(self):
class RedgifsNichesExtractor(RedgifsExtractor):
"""Extractor for redgifs niches"""
subcategory = "niches"
pattern = r"(?:https?://)?(?:www\.)?redgifs\.com/niches/([^/?#]+)"
pattern = (r"(?:https?://)?(?:www\.)?redgifs\.com/niches/([^/?#]+)/?"
r"(?:\?([^#]+))?$")
example = "https://www.redgifs.com/niches/NAME"

def __init__(self, match):
RedgifsExtractor.__init__(self, match)
self.query = match.group(2)

def gifs(self):
return self.api.niches(self.key)
order = text.parse_query(self.query).get("order")
return self.api.niches(self.key, order or "new")


class RedgifsSearchExtractor(RedgifsExtractor):
Expand Down Expand Up @@ -232,9 +238,10 @@ def collections(self, user):
endpoint = "/v2/users/{}/collections".format(user)
return self._pagination(endpoint, key="collections")

def niches(self, niche):
def niches(self, niche, order):
endpoint = "/v2/niches/{}/gifs".format(niche)
return self._pagination(endpoint)
params = {"count": 30, "order": order}
return self._pagination(endpoint, params)

def search(self, params):
endpoint = "/v2/gifs/search"
Expand Down
8 changes: 4 additions & 4 deletions test/results/redgifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@
},

{
"#url" : "https://www.redgifs.com/niches/boobs",
"#url" : "https://www.redgifs.com/niches/just-boobs",
"#category": ("", "redgifs", "niches"),
"#class" : redgifs.RedgifsNichesExtractor,
"#pattern" : r"https://\w+\.redgifs\.com/[\w-]+\.mp4",
"#pattern" : r"https://\w+\.redgifs\.com/[\w-]+\.(mp4|jpg)",
"#range" : "1-20",
"#count" : 20,
},

{
"#url" : "https://www.redgifs.com/niches/ass",
"#url" : "https://www.redgifs.com/niches/thick-booty",
"#category": ("", "redgifs", "niches"),
"#class" : redgifs.RedgifsNichesExtractor,
"#pattern" : r"https://\w+\.redgifs\.com/[\w-]+\.mp4",
"#pattern" : r"https://\w+\.redgifs\.com/[\w-]+\.(mp4|jpg)",
"#range" : "1-20",
"#count" : 20,
},
Expand Down

0 comments on commit 727c8ee

Please sign in to comment.