Use NoThumbnailException from thumbnail task

This commit is contained in:
tcely 2025-05-02 16:20:48 -04:00 committed by GitHub
parent 3a0c4c8fb1
commit add6454c33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,6 +8,7 @@ import os
import json import json
import math import math
import random import random
import requests
import time import time
import uuid import uuid
from io import BytesIO from io import BytesIO
@ -29,7 +30,8 @@ from background_task.exceptions import InvalidTaskError
from background_task.models import Task, CompletedTask from background_task.models import Task, CompletedTask
from common.logger import log from common.logger import log
from common.errors import ( NoFormatException, NoMediaException, from common.errors import ( NoFormatException, NoMediaException,
NoMetadataException, DownloadFailedException, ) NoMetadataException, NoThumbnailException,
DownloadFailedException, )
from common.utils import ( django_queryset_generator as qs_gen, from common.utils import ( django_queryset_generator as qs_gen,
remove_enclosed, ) remove_enclosed, )
from .choices import Val, TaskQueue from .choices import Val, TaskQueue
@ -548,7 +550,10 @@ def download_media_thumbnail(media_id, url):
return return
width = getattr(settings, 'MEDIA_THUMBNAIL_WIDTH', 430) width = getattr(settings, 'MEDIA_THUMBNAIL_WIDTH', 430)
height = getattr(settings, 'MEDIA_THUMBNAIL_HEIGHT', 240) height = getattr(settings, 'MEDIA_THUMBNAIL_HEIGHT', 240)
try:
i = get_remote_image(url) i = get_remote_image(url)
except requests.HTTPError as e:
raise NoThumbnailException(url) from e
if (i.width > width) and (i.height > height): if (i.width > width) and (i.height > height):
log.info(f'Resizing {i.width}x{i.height} thumbnail to ' log.info(f'Resizing {i.width}x{i.height} thumbnail to '
f'{width}x{height}: {url}') f'{width}x{height}: {url}')