Redgifs updates
Update Redgifs regex for further edge case. Add test for checking ID.
This commit is contained in:
parent
816b7e2726
commit
fe9cc7f29f
|
@ -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:
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in a new issue