From 93355ada0886e4973b5abc19ab15666fd49dcf5c Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:34:14 -0500 Subject: [PATCH] Imgur thumbnail coverage Coverage for links posted to thumbnail variations. --- bdfr/site_downloaders/imgur.py | 7 +++++-- tests/site_downloaders/test_imgur.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bdfr/site_downloaders/imgur.py b/bdfr/site_downloaders/imgur.py index 4af62b13..77db49c2 100644 --- a/bdfr/site_downloaders/imgur.py +++ b/bdfr/site_downloaders/imgur.py @@ -44,10 +44,13 @@ def _get_data(link: str) -> dict: try: if re.search(r".*/(.*?)(gallery/|a/)", link): imgur_id = re.match(r".*/(?:gallery/|a/)(.*?)(?:/.*)?$", link).group(1) - link = f"https://imgur.com/a/{imgur_id}" else: imgur_id = re.match(r".*/(.*?)(_d)?(\..{0,})?$", link).group(1) - link = f"https://imgur.com/{imgur_id}" + gallery = "a/" if re.search(r".*/(.*?)(gallery/|a/)", link) else "" + if len(imgur_id) > 7: + if imgur_id.endswith(("s", "b", "t", "m", "l", "h")): + imgur_id = imgur_id[:7] + link = f"https://imgur.com/{gallery}{imgur_id}" except AttributeError: raise SiteDownloaderError(f"Could not extract Imgur ID from {link}") diff --git a/tests/site_downloaders/test_imgur.py b/tests/site_downloaders/test_imgur.py index 9f8e6a7b..2e74a256 100644 --- a/tests/site_downloaders/test_imgur.py +++ b/tests/site_downloaders/test_imgur.py @@ -137,6 +137,7 @@ def test_imgur_extension_validation_bad(test_extension: str): ("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",)), + ("http://i.imgur.com/s9uXxlqb.jpg", ("338de3c23ee21af056b3a7c154e2478f",)), ("https://i.imgur.com/2TtN68l_d.webp", ("6569ab9ad9fa68d93f6b408f112dd741",)), ("https://imgur.com/a/1qzfWtY/gifv", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)), ("https://imgur.com/a/1qzfWtY/mp4", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)),