From 2662a66acac2df089c6315dc275fb8c978555e9a Mon Sep 17 00:00:00 2001 From: j Date: Wed, 12 Sep 2018 15:56:10 +0200 Subject: [PATCH] fall back to siteposter --- pandora/item/models.py | 2 +- pandora/item/views.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 7ee4efa8..8249cd6e 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1455,7 +1455,7 @@ class Item(models.Model): self.clear_poster_cache(self.poster.path) self.poster.delete() - if not self.poster: + if not self.poster or not os.path.exists(self.poster.path): poster = self.make_siteposter() url = self.prefered_poster_url() if url: diff --git a/pandora/item/views.py b/pandora/item/views.py index 966744eb..3600086e 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -827,6 +827,20 @@ def poster_frame(request, id, position): raise Http404 +def image_path_to_response(image, size=None): + if size: + size = int(size) + path = image.replace('.jpg', '.%d.jpg' % size) + if not os.path.exists(path): + image_size = max(Image.open(image).size) + if size > image_size: + path = image + else: + extract.resize_image(image, path, size=size) + else: + path = image + return HttpFileResponse(path, content_type='image/jpeg') + def image_to_response(image, size=None): if size: size = int(size) @@ -883,8 +897,12 @@ def poster(request, id, size=None): icon=item.icon.name, cache=item.json() ) + siteposter = item.path('siteposter.jpg') + siteposter = os.path.abspath(os.path.join(settings.MEDIA_ROOT, siteposter)) if item.poster and os.path.exists(item.poster.path): return image_to_response(item.poster, size) + elif os.path.exists(siteposter): + return image_path_to_response(siteposter, size) else: return temp_poster()