Imgur thumbnail coverage

Coverage for links posted to thumbnail variations.
This commit is contained in:
OMEGARAZER 2023-01-09 15:34:14 -05:00
parent 0f94c98733
commit 8e60a12517
No known key found for this signature in database
GPG Key ID: D89925310D306E35
2 changed files with 9 additions and 3 deletions

View File

@ -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}")

View File

@ -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",)),