From 02b6e669417876feb6b6d349568e1d8dfca1e004 Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Wed, 28 Sep 2022 00:55:10 -0400 Subject: [PATCH 1/2] Imgur edge case coverage Covers edge case of additional arguments on extension. Also removed duplicate or redundant tests. --- bdfr/site_downloaders/imgur.py | 2 +- tests/site_downloaders/test_download_factory.py | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/bdfr/site_downloaders/imgur.py b/bdfr/site_downloaders/imgur.py index f895785..0688b10 100644 --- a/bdfr/site_downloaders/imgur.py +++ b/bdfr/site_downloaders/imgur.py @@ -78,7 +78,7 @@ class Imgur(BaseDownloader): @staticmethod def _validate_extension(extension_suffix: str) -> str: - extension_suffix = extension_suffix.strip('?1') + extension_suffix = re.sub(r'\?.*', '', extension_suffix) possible_extensions = ('.jpg', '.png', '.mp4', '.gif') selection = [ext for ext in possible_extensions if ext == extension_suffix] if len(selection) == 1: diff --git a/tests/site_downloaders/test_download_factory.py b/tests/site_downloaders/test_download_factory.py index d3fec6f..bcfc704 100644 --- a/tests/site_downloaders/test_download_factory.py +++ b/tests/site_downloaders/test_download_factory.py @@ -24,14 +24,11 @@ from bdfr.site_downloaders.youtube import Youtube @pytest.mark.parametrize(('test_submission_url', 'expected_class'), ( ('https://www.reddit.com/r/TwoXChromosomes/comments/lu29zn/i_refuse_to_live_my_life' '_in_anything_but_comfort/', SelfPost), - ('https://i.imgur.com/bZx1SJQ.jpg', Imgur), ('https://i.redd.it/affyv0axd5k61.png', Direct), - ('https://imgur.com/3ls94yv.jpeg', Imgur), - ('https://i.imgur.com/BuzvZwb.gifv', Imgur), + ('https://i.imgur.com/bZx1SJQ.jpg', Imgur), ('https://imgur.com/BuzvZwb.gifv', Imgur), - ('https://i.imgur.com/6fNdLst.gif', Imgur), ('https://imgur.com/a/MkxAzeg', Imgur), - ('https://i.imgur.com/OGeVuAe.giff', Imgur), + ('https://m.imgur.com/a/py3RW0j', Imgur), ('https://www.reddit.com/gallery/lu93m7', Gallery), ('https://gfycat.com/concretecheerfulfinwhale', Gfycat), ('https://www.erome.com/a/NWGw0F09', Erome), @@ -40,16 +37,13 @@ from bdfr.site_downloaders.youtube import Youtube ('https://www.gifdeliverynetwork.com/repulsivefinishedandalusianhorse', Redgifs), ('https://youtu.be/DevfjHOhuFc', Youtube), ('https://m.youtube.com/watch?v=kr-FeojxzUM', Youtube), - ('https://i.imgur.com/3SKrQfK.jpg?1', Imgur), ('https://dynasty-scans.com/system/images_images/000/017/819/original/80215103_p0.png?1612232781', Direct), - ('https://m.imgur.com/a/py3RW0j', Imgur), ('https://v.redd.it/9z1dnk3xr5k61', VReddit), ('https://streamable.com/dt46y', YtdlpFallback), ('https://vimeo.com/channels/31259/53576664', YtdlpFallback), ('http://video.pbs.org/viralplayer/2365173446/', YtdlpFallback), ('https://www.pornhub.com/view_video.php?viewkey=ph5a2ee0461a8d0', PornHub), ('https://www.patreon.com/posts/minecart-track-59346560', Gallery), - ('https://v.redd.it/9z1dnk3xr5k61', VReddit) )) def test_factory_lever_good(test_submission_url: str, expected_class: BaseDownloader, reddit_instance: praw.Reddit): result = DownloadFactory.pull_lever(test_submission_url) From b536a486b63ce02e6ff441204c5880d58d357aba Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Wed, 28 Sep 2022 13:21:05 -0400 Subject: [PATCH 2/2] Imgur argument tests Add tests for links that have arguments added to the extension field in retrieved image_dict --- tests/site_downloaders/test_imgur.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/site_downloaders/test_imgur.py b/tests/site_downloaders/test_imgur.py index 359bdc3..00419ba 100644 --- a/tests/site_downloaders/test_imgur.py +++ b/tests/site_downloaders/test_imgur.py @@ -152,11 +152,23 @@ def test_imgur_extension_validation_bad(test_extension: str): ), ( 'https://i.imgur.com/OGeVuAe.giff', - ('77389679084d381336f168538793f218',) + ('77389679084d381336f168538793f218',), ), ( 'https://i.imgur.com/OGeVuAe.gift', - ('77389679084d381336f168538793f218',) + ('77389679084d381336f168538793f218',), + ), + ( + 'https://i.imgur.com/3SKrQfK.jpg?1', + ('aa299e181b268578979cad176d1bd1d0',), + ), + ( + 'https://i.imgur.com/cbivYRW.jpg?3', + ('7ec6ceef5380cb163a1d498c359c51fd',), + ), + ( + 'http://i.imgur.com/s9uXxlq.jpg?5.jpg', + ('338de3c23ee21af056b3a7c154e2478f',), ), )) def test_find_resources(test_url: str, expected_hashes: list[str]):