diff --git a/bdfr/site_downloaders/imgur.py b/bdfr/site_downloaders/imgur.py index 4af62b1..294209d 100644 --- a/bdfr/site_downloaders/imgur.py +++ b/bdfr/site_downloaders/imgur.py @@ -44,10 +44,15 @@ class Imgur(BaseDownloader): 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}" + imgur_id = re.match(r".*/(.*?)(?:_d)?(?:\..{0,})?$", link).group(1) + 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] + else: + raise SiteDownloaderError(f"Imgur ID error in link {link}") + 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 9f8e6a7..2e74a25 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",)),