1
0
Fork 0
mirror of synced 2024-05-19 19:52:41 +12:00

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
No known key found for this signature in database
GPG key ID: EDBD4E9B4DA565B4
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:

View file

@ -10,6 +10,19 @@ from bdfr.resource import Resource
from bdfr.site_downloaders.redgifs import Redgifs
@pytest.mark.parametrize(
("test_url", "expected"),
(
("https://redgifs.com/watch/frighteningvictorioussalamander", "frighteningvictorioussalamander"),
("https://www.redgifs.com/watch/genuineprivateguillemot/", "genuineprivateguillemot"),
("https://www.redgifs.com/watch/marriedcrushingcob?rel=u%3Akokiri.girl%3Bo%3Arecent", "marriedcrushingcob"),
),
)
def test_get_id(test_url: str, expected: str):
result = Redgifs._get_id(test_url)
assert result == expected
@pytest.mark.online
@pytest.mark.parametrize(
("test_url", "expected"),