Edge case coverage

Cover edge cases that shouldn't ever happen but probably will sometime.

Also included Imgur changes to cover similar situations of malformed/redirected links.
This commit is contained in:
SoulSuck24
2022-09-18 13:24:42 -04:00
parent 95749584ec
commit 2f2b5b749c
3 changed files with 7 additions and 8 deletions

View File

@@ -41,10 +41,11 @@ class Imgur(BaseDownloader):
@staticmethod
def _get_data(link: str) -> dict:
link = link.rstrip('?')
if re.match(r'(?i).*\.gif.+$', link):
link = link.replace('i.imgur', 'imgur')
link = re.sub('(?i)\\.gif.+$', '', link)
try:
imgur_id = re.match(r'.*/(.*?)(\..{0,})?$', link).group(1)
link = f'https://imgur.com/a/{imgur_id}'
except AttributeError:
raise SiteDownloaderError(f'Could not extract Imgur ID from {link}')
res = Imgur.retrieve_url(link, cookies={'over18': '1', 'postpagebeta': '0'})