From 38e081a7414467ebc08a33d90679fc87fb95d7b2 Mon Sep 17 00:00:00 2001 From: Tomuxs Date: Sat, 2 Aug 2025 15:42:08 +0200 Subject: [PATCH] Move list of known extensions to py34.url --- py34/post.py | 4 ++-- py34/url.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/py34/post.py b/py34/post.py index a9de11e..93a344a 100644 --- a/py34/post.py +++ b/py34/post.py @@ -1,5 +1,5 @@ from .scraper import scraper -from .url import ImageURL, ThumbnailURL +from .url import ImageURL, ThumbnailURL, IMAGE_FORMATS from io import BytesIO from PIL import Image from PIL.ImageFile import ImageFile @@ -44,7 +44,7 @@ class Post: def get_image_data(self) -> bytes: if self._image_data is not None: return self._image_data - for ext in ["jpeg", "png", "gif", "mp4", "webm", "jpg"]: + for ext in IMAGE_FORMATS: try: self._image_data = scraper.get(ImageURL(self.image_dir, self.image_id, ext), retry=False) self._image_format = ext diff --git a/py34/url.py b/py34/url.py index 3e1f7e5..40acea7 100644 --- a/py34/url.py +++ b/py34/url.py @@ -2,6 +2,9 @@ from urllib.parse import urlparse from os.path import splitext +IMAGE_FORMATS = ["jpeg", "png", "gif", "mp4", "webm", "jpg"] + + class ImageURL: def __init__(self, image_dir: int, image_id: str, image_format: str): self.dir: int = image_dir