Serve svg tpl when thumbnail not found

This commit is contained in:
ABelliqueux 2022-11-25 14:36:09 +01:00
parent f9191892cf
commit db048b2115
5 changed files with 31 additions and 16 deletions

19
app.py
View File

@ -3,6 +3,7 @@
# abelliqueux <contact@arthus.net>
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/<media>")
@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 = '<svg width="320" height="240" viewBox="0 0 84.6 63.5" version="1.1" id="not_found" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"><path id="not_found_x" style="fill:#f00;" d="M 3.076298,0.04960937 H 0.04960937 V 1.5394409 L 40.0389,31.278194 0.04960937,61.017464 v 2.432927 H 1.8076416 L 42.553475,33.148364 83.299825,63.450391 h 1.317232 V 60.691386 L 45.067533,31.278194 84.617057,1.8655192 V 0.04960937 H 82.031169 L 42.553475,29.408541 Z" /><text xml:space="preserve" style="font-size:8px;stroke:#000;stroke-width:2px;" x="50%" y="50%" id="not_found_txt"><tspan id="not_found_span" style="text-align:center;text-anchor:middle;stroke:none;">{}</tspan></text></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

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

Binary file not shown.

View File

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

View File

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