From 8d6101112b5e98b2834ea4b9f9c5f89c26bcd710 Mon Sep 17 00:00:00 2001 From: Soulsuck24 <79275800+Soulsuck24@users.noreply.github.com> Date: Sat, 29 Apr 2023 14:08:08 -0400 Subject: [PATCH 1/2] Redgif coverage better coverage for thumbs subdomains and direct links to images. --- bdfr/site_downloaders/download_factory.py | 2 +- bdfr/site_downloaders/redgifs.py | 3 +-- tests/site_downloaders/test_redgifs.py | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bdfr/site_downloaders/download_factory.py b/bdfr/site_downloaders/download_factory.py index b348561..c3b51a8 100644 --- a/bdfr/site_downloaders/download_factory.py +++ b/bdfr/site_downloaders/download_factory.py @@ -27,7 +27,7 @@ class DownloadFactory: sanitised_url = DownloadFactory.sanitise_url(url).lower() if re.match(r"(i\.|m\.|o\.)?imgur", sanitised_url): return Imgur - elif re.match(r"(i\.|thumbs\d\.|v\d\.)?(redgifs|gifdeliverynetwork)", sanitised_url): + elif re.match(r"(i\.|thumbs\d{1,2}\.|v\d\.)?(redgifs|gifdeliverynetwork)", sanitised_url): return Redgifs elif re.match(r"(thumbs\.|giant\.)?gfycat\.", sanitised_url): return Gfycat diff --git a/bdfr/site_downloaders/redgifs.py b/bdfr/site_downloaders/redgifs.py index d8410a1..272fd90 100644 --- a/bdfr/site_downloaders/redgifs.py +++ b/bdfr/site_downloaders/redgifs.py @@ -33,8 +33,7 @@ class Redgifs(BaseDownloader): if url.endswith("/"): url = url.removesuffix("/") redgif_id = re.match(r".*/(.*?)(?:#.*|\?.*|\..{0,})?$", url).group(1).lower() - if redgif_id.endswith("-mobile"): - redgif_id = redgif_id.removesuffix("-mobile") + redgif_id = re.sub(r"(-.*)$", "", redgif_id) except AttributeError: raise SiteDownloaderError(f"Could not extract Redgifs ID from {url}") return redgif_id diff --git a/tests/site_downloaders/test_redgifs.py b/tests/site_downloaders/test_redgifs.py index 038e8f0..86478f0 100644 --- a/tests/site_downloaders/test_redgifs.py +++ b/tests/site_downloaders/test_redgifs.py @@ -25,6 +25,7 @@ def test_auth_cache(): ("https://thumbs4.redgifs.com/DismalIgnorantDrongo.mp4", "dismalignorantdrongo"), ("https://thumbs4.redgifs.com/DismalIgnorantDrongo-mobile.mp4", "dismalignorantdrongo"), ("https://v3.redgifs.com/watch/newilliteratemeerkat#rel=user%3Atastynova", "newilliteratemeerkat"), + ("https://thumbs46.redgifs.com/BabyishCharmingAidi-medium.jpg", "babyishcharmingaidi"), ), ) def test_get_id(test_url: str, expected: str): @@ -81,6 +82,7 @@ def test_get_link(test_url: str, expected: set[str]): "44fb28f72ec9a5cca63fa4369ab4f672", }, ), + ("https://thumbs46.redgifs.com/BabyishCharmingAidi-medium.jpg", {"bf14b9f3d5b630cb5fd271661226f1af"}), ), ) def test_download_resource(test_url: str, expected_hashes: set[str]): From 13980fb6ac0a77a86c44a9ce03b0c4d7f3fe59e1 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Wed, 17 May 2023 10:54:52 +1000 Subject: [PATCH 2/2] Remove failing test case --- tests/site_downloaders/test_imgur.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/site_downloaders/test_imgur.py b/tests/site_downloaders/test_imgur.py index 8881c31..cf5a996 100644 --- a/tests/site_downloaders/test_imgur.py +++ b/tests/site_downloaders/test_imgur.py @@ -48,7 +48,6 @@ from bdfr.site_downloaders.imgur import Imgur ("https://imgur.com/a/1qzfWtY/gifv", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)), ("https://imgur.com/a/1qzfWtY/mp4", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)), ("https://imgur.com/a/1qzfWtY/spqr", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)), - ("https://i.imgur.com/expO7Rc.gifv", ("e309f98158fc98072eb2ae68f947f421",)), ("https://i.imgur.com/a/aqpiMuL.gif", ("5b2a9a5218bf43dc26ba41389410c981",)), ), )