Account for new gallery url

Coverage for gallery urls
This commit is contained in:
OMEGARAZER 2023-01-09 12:48:24 -05:00
parent 7e93101617
commit 0f94c98733
No known key found for this signature in database
GPG Key ID: D89925310D306E35
2 changed files with 21 additions and 51 deletions

View File

@ -42,9 +42,12 @@ class Imgur(BaseDownloader):
@staticmethod
def _get_data(link: str) -> dict:
try:
imgur_id = re.match(r".*/(.*?)(_d)?(\..{0,})?$", link).group(1)
gallery = "a/" if re.search(r".*/(.*?)(gallery/|a/)", link) else ""
link = f"https://imgur.com/{gallery}{imgur_id}"
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}"
except AttributeError:
raise SiteDownloaderError(f"Could not extract Imgur ID from {link}")

View File

@ -109,10 +109,7 @@ def test_imgur_extension_validation_bad(test_extension: str):
("test_url", "expected_hashes"),
(
("https://imgur.com/a/xWZsDDP", ("f551d6e6b0fef2ce909767338612e31b",)),
(
"https://imgur.com/gallery/IjJJdlC",
("740b006cf9ec9d6f734b6e8f5130bdab",),
),
("https://imgur.com/gallery/IjJJdlC", ("740b006cf9ec9d6f734b6e8f5130bdab",)),
(
"https://imgur.com/a/dcc84Gt",
(
@ -130,50 +127,20 @@ def test_imgur_extension_validation_bad(test_extension: str):
"fb6c913d721c0bbb96aa65d7f560d385",
),
),
(
"https://i.imgur.com/lFJai6i.gifv",
("01a6e79a30bec0e644e5da12365d5071",),
),
(
"https://i.imgur.com/ywSyILa.gifv?",
("56d4afc32d2966017c38d98568709b45",),
),
(
"https://imgur.com/ubYwpbk.GIFV",
("d4a774aac1667783f9ed3a1bd02fac0c",),
),
(
"https://i.imgur.com/j1CNCZY.gifv",
("58e7e6d972058c18b7ecde910ca147e3",),
),
(
"https://i.imgur.com/uTvtQsw.gifv",
("46c86533aa60fc0e09f2a758513e3ac2",),
),
(
"https://i.imgur.com/OGeVuAe.giff",
("77389679084d381336f168538793f218",),
),
(
"https://i.imgur.com/OGeVuAe.gift",
("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",),
),
(
"https://i.imgur.com/2TtN68l_d.webp",
("6569ab9ad9fa68d93f6b408f112dd741",),
),
("https://i.imgur.com/lFJai6i.gifv", ("01a6e79a30bec0e644e5da12365d5071",)),
("https://i.imgur.com/ywSyILa.gifv?", ("56d4afc32d2966017c38d98568709b45",)),
("https://imgur.com/ubYwpbk.GIFV", ("d4a774aac1667783f9ed3a1bd02fac0c",)),
("https://i.imgur.com/j1CNCZY.gifv", ("58e7e6d972058c18b7ecde910ca147e3",)),
("https://i.imgur.com/uTvtQsw.gifv", ("46c86533aa60fc0e09f2a758513e3ac2",)),
("https://i.imgur.com/OGeVuAe.giff", ("77389679084d381336f168538793f218",)),
("https://i.imgur.com/OGeVuAe.gift", ("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",)),
("https://i.imgur.com/2TtN68l_d.webp", ("6569ab9ad9fa68d93f6b408f112dd741",)),
("https://imgur.com/a/1qzfWtY/gifv", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)),
("https://imgur.com/a/1qzfWtY/mp4", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)),
("https://imgur.com/a/1qzfWtY/spqr", ("65fbc7ba5c3ed0e3af47c4feef4d3735",)),
),
)
def test_find_resources(test_url: str, expected_hashes: list[str]):