fix: Catch correct exceptions to extract original image link

This commit is contained in:
Marty Oehme 2025-06-09 16:12:04 +02:00
parent ac024989a6
commit 601b42acdc
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -18,12 +18,13 @@ class Original: # BadJoke: Sting
m = re.match(r'<img src="(?P<img>.+?)"', s) m = re.match(r'<img src="(?P<img>.+?)"', s)
try: try:
img = m.group("img") img = m.group("img")
except (IndexError, NameError): except (IndexError, AttributeError):
return ("", s) return ("", s)
if img: if img:
rest = re.sub(r"<img src=.+?>", "", s) rest = re.sub(r"<img src=.+?>", "", s)
return (img, rest) return (img, rest)
return ("", s)
def __post_init__(self): def __post_init__(self):
self.id = hashlib.sha256(self.link.encode()).hexdigest() self.id = hashlib.sha256(self.link.encode()).hexdigest()