From 8175327ce3603ef779fc5d565fdf86b5051c9d70 Mon Sep 17 00:00:00 2001 From: "Troll (Hermes Agent)" Date: Tue, 11 Aug 2026 02:57:38 +0000 Subject: [PATCH] Respect deliver_album_cover on player page and scale cover to 160px everywhere --- app.py | 4 ++-- helpers.py | 16 ++++++++++++++-- requirements.txt | 2 ++ templates/admin/request.html | 5 ++++- templates/player.html | 4 ++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 1248776..7a7ba9b 100644 --- a/app.py +++ b/app.py @@ -540,7 +540,7 @@ def play(token): max_revisions = get_max_revisions() revisions_left = max(0, max_revisions - int(req.get('revision_count') or 0)) - return render_template('player.html', req=req, revisions_left=revisions_left) + return render_template('player.html', req=req, revisions_left=revisions_left, deliver_album_cover=load_booth_settings().get('deliver_album_cover', False)) @app.route('/play//approve', methods=['POST']) @@ -1215,7 +1215,7 @@ def admin_request(rid): attachments.append((str(p), p.name)) cfg = load_booth_settings() if cfg.get('deliver_album_cover') and req.get('album_cover_url'): - cover_path = download_album_cover(rid, req['album_cover_url']) + cover_path = download_album_cover(rid, req['album_cover_url'], max_width=160) if cover_path: attachments.append((cover_path, f"cover{Path(cover_path).suffix}")) diff --git a/helpers.py b/helpers.py index 5e7c512..2a993c0 100644 --- a/helpers.py +++ b/helpers.py @@ -735,17 +735,29 @@ def format_musicgpt_cost(cost): return f"${float(cost):.4f} USD" -def download_album_cover(rid, cover_url): - """Download a MusicGPT album cover to a temp file and return its path.""" +def download_album_cover(rid, cover_url, max_width=160): + """ + Download a MusicGPT album cover to a temp file, resize it so it is not + oversized in emails or pages, and return its path. The default max_width + of 160px matches the inline album cover display size on the player/admin pages. + """ if not cover_url: return None try: import tempfile + from PIL import Image resp = requests.get(cover_url, timeout=30) if resp.status_code == 200: ext = Path(cover_url).suffix or '.jpg' tmp = Path(tempfile.gettempdir()) / f"cover_{rid}{ext}" tmp.write_bytes(resp.content) + # Resize if the image is wider than max_width to keep email/file size small. + with Image.open(tmp) as img: + if img.width > max_width: + ratio = max_width / img.width + new_height = int(img.height * ratio) + img = img.resize((max_width, new_height)) + img.save(tmp) return str(tmp) except Exception: pass diff --git a/requirements.txt b/requirements.txt index c5b0ac1..ecaade9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ # mutagen - MP3 metadata (ID3) tagging # flask-limiter - public form rate limiting # cryptography - encrypt stored SMTP password +# pillow - resize album cover images before email delivery flask gunicorn @@ -18,4 +19,5 @@ werkzeug mutagen flask-limiter cryptography +pillow requests diff --git a/templates/admin/request.html b/templates/admin/request.html index e6168fe..068e81f 100644 --- a/templates/admin/request.html +++ b/templates/admin/request.html @@ -179,7 +179,10 @@ {% if req.album_cover_url %}
- Album cover + Album cover + {% if not deliver_album_cover %} +

Album cover is hidden from the customer preview/delivery because delivery is disabled in settings.

+ {% endif %}
{% endif %} diff --git a/templates/player.html b/templates/player.html index a2827f4..79345e1 100644 --- a/templates/player.html +++ b/templates/player.html @@ -129,9 +129,9 @@ {% endif %} - {% if req.album_cover_url %} + {% if req.album_cover_url and deliver_album_cover %}
- Album cover + Album cover
{% endif %}