Move list of known extensions to py34.url

This commit is contained in:
2025-08-02 15:42:08 +02:00
parent 1653e8db7c
commit 38e081a741
2 changed files with 5 additions and 2 deletions

View File

@ -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

View File

@ -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