Skip to content

Commit

Permalink
Imgur thumbnail coverage
Browse files Browse the repository at this point in the history
Coverage for links posted to thumbnail variations.
  • Loading branch information
OMEGARAZER committed Jan 9, 2023
1 parent 0f94c98 commit 93355ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bdfr/site_downloaders/imgur.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
1 change: 1 addition & 0 deletions tests/site_downloaders/test_imgur.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)),
Expand Down

0 comments on commit 93355ad

Please sign in to comment.