Redgifs updates

Update Redgifs regex for further edge case.

Add test for checking ID.
This commit is contained in:
Soulsuck24
2022-12-24 20:52:45 -05:00
parent 816b7e2726
commit fe9cc7f29f
2 changed files with 20 additions and 2 deletions

View File

@@ -23,13 +23,18 @@ class Redgifs(BaseDownloader):
return [Resource(self.post, m, Resource.retry_download(m), None) for m in media_urls]
@staticmethod
def _get_link(url: str) -> set[str]:
def _get_id(url: str) -> str:
try:
if url.endswith("/"):
url = url.removesuffix("/")
redgif_id = re.match(r".*/(.*?)(\..{0,})?$", url).group(1)
redgif_id = re.match(r".*/(.*?)(?:\?.*|\..{0,})?$", url).group(1)
except AttributeError:
raise SiteDownloaderError(f"Could not extract Redgifs ID from {url}")
return redgif_id
@staticmethod
def _get_link(url: str) -> set[str]:
redgif_id = Redgifs._get_id(url)
auth_token = json.loads(Redgifs.retrieve_url("https://api.redgifs.com/v2/auth/temporary").text)["token"]
if not auth_token: