From db048b2115392102fb162a52694a2617bb6adec5 Mon Sep 17 00:00:00 2001 From: ABelliqueux Date: Fri, 25 Nov 2022 14:36:09 +0100 Subject: [PATCH] Serve svg tpl when thumbnail not found --- app.py | 19 +++++++++++++------ locales/en/LC_MESSAGES/template.pot | 22 +++++++++++++--------- locales/fr/LC_MESSAGES/template.mo | Bin 824 -> 874 bytes locales/fr/LC_MESSAGES/template.pot | 3 +++ locales/gen_mo.sh | 3 ++- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index a867c4c..e319c05 100755 --- a/app.py +++ b/app.py @@ -3,6 +3,7 @@ # abelliqueux from flask import Flask, flash, request, redirect, url_for, send_file from flask_httpauth import HTTPBasicAuth +from io import BytesIO import gettext import os import subprocess @@ -167,7 +168,7 @@ def list_media_files(folder): def generate_thumbnails(): media_files = list_media_files(upload_folder) for media in media_files: - subprocess.call(['ffmpeg', '-i', upload_folder + "/" + media, '-q:v', '30', '-s' , '160x120' , '-vf' , 'boxblur=2' , '-ss', '00:00:01.000', '-vframes', '1', thumbnails_folder + "/" + media + ".jpg", "-y"]) + subprocess.call(['ffmpeg', '-i', upload_folder + "/" + media, '-q:v', '30', '-s', '160x120', '-vf', 'boxblur=2', '-ss', '00:00:01.000', '-vframes', '1', thumbnails_folder + "/" + media + ".jpg", "-y"]) @app.route("/") @@ -235,14 +236,20 @@ def upload_file(over_write=1): return "OK" - @app.route("/thumb/") @auth.login_required def get_thumbnail(media): - if media and os.path.exists(thumbnails_folder + os.sep + media): - return send_file(thumbnails_folder + os.sep + media + ".jpg", mimetype='image/jpg') - - + if media: + media_full_path = thumbnails_folder + os.sep + media + ".jpg" + if os.path.exists(media_full_path): + return send_file(media_full_path, mimetype='image/jpg') + else: + # Return a svg file as bytes, so that we can use gettext on its content + svg = '{}'.format(_("MEDIA NOT FOUND")) + buf = BytesIO(bytes(svg, "UTF-8")) + return send_file(buf, mimetype="image/svg+xml") + + if __name__ == '__main__': generate_thumbnails() # Turn ACT and POW leds off on start diff --git a/locales/en/LC_MESSAGES/template.pot b/locales/en/LC_MESSAGES/template.pot index 63d7414..74a93be 100644 --- a/locales/en/LC_MESSAGES/template.pot +++ b/locales/en/LC_MESSAGES/template.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2022-11-03 12:59+0100\n" +"POT-Creation-Date: 2022-11-25 14:13+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -15,35 +15,39 @@ msgstr "" "Generated-By: pygettext.py 1.5\n" -#: ../app.py:25 +#: ../app.py:29 msgid "Found configuration file in {}" msgstr "" -#: ../app.py:104 +#: ../app.py:178 msgid "Nothing to see here !" msgstr "" -#: ../app.py:115 +#: ../app.py:192 msgid "Blinkin" msgstr "" -#: ../app.py:122 +#: ../app.py:200 msgid "Rebooting..." msgstr "" -#: ../app.py:129 +#: ../app.py:208 msgid "Shutting down..." msgstr "" -#: ../app.py:139 +#: ../app.py:221 msgid "No file part: {}" msgstr "" -#: ../app.py:144 +#: ../app.py:226 msgid "No selected file" msgstr "" -#: ../app.py:148 +#: ../app.py:233 msgid "File saved in {}" msgstr "" +#: ../app.py:250 +msgid "MEDIA NOT FOUND" +msgstr "" + diff --git a/locales/fr/LC_MESSAGES/template.mo b/locales/fr/LC_MESSAGES/template.mo index bb1e3acc7ae2fe41732836745b547de1313a2020..7125bd6e850d7791e46721e52e0fa3b5bd0e27a2 100644 GIT binary patch delta 270 zcmdnN_KL0ko)F7a1|Z-9Vi_RL0b*Vt-UGxS@BxU~f%qd33jpy?AeIASE=C3heju$0 zq(S1AP}&Pfivs!4K$-_g7edABfV2=0_X9B-P<#;+1A{aJLlDDCAVUKva1=-j0_k@^ zS{_I}AkGJ3HlTPD69a=ZknRN18Vn3h3`>Cwd7!{KAPsWBJ0L9x zq`8?H82Ev-ERf~`(z-wzXa?9ZK#G9{L;wNj#EZhLAd@*JzI51Z$+(qq5_1*+TdEb6 diff --git a/locales/fr/LC_MESSAGES/template.pot b/locales/fr/LC_MESSAGES/template.pot index 44f1f00..a795af7 100644 --- a/locales/fr/LC_MESSAGES/template.pot +++ b/locales/fr/LC_MESSAGES/template.pot @@ -47,3 +47,6 @@ msgstr "Aucun fichier sélectionné." msgid "File saved in {}" msgstr "Fichier enregistré dans {}" +#: ../app.py:250 +msgid "MEDIA NOT FOUND" +msgstr "MEDIA INTROUVABLE" diff --git a/locales/gen_mo.sh b/locales/gen_mo.sh index 565b2fa..c1fea79 100755 --- a/locales/gen_mo.sh +++ b/locales/gen_mo.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -# pygettext ../../../app.py -o template.pot +cd "$(dirname "$0")" +#pygettext -p en/LC_MESSAGES/ -o template.pot ../app.py for locale in */LC_MESSAGES/template.pot; do /usr/bin/msgfmt -o ${locale%.*}.mo $locale done