Merge pull request #731 from Soulsuck24/development

This commit is contained in:
Serene
2022-12-26 14:51:53 +10:00
committed by GitHub
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"),