Respect deliver_album_cover on player page and scale cover to 160px everywhere
This commit is contained in:
parent
530e9e53ff
commit
8175327ce3
5 changed files with 24 additions and 7 deletions
4
app.py
4
app.py
|
|
@ -540,7 +540,7 @@ def play(token):
|
||||||
max_revisions = get_max_revisions()
|
max_revisions = get_max_revisions()
|
||||||
revisions_left = max(0, max_revisions - int(req.get('revision_count') or 0))
|
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/<token>/approve', methods=['POST'])
|
@app.route('/play/<token>/approve', methods=['POST'])
|
||||||
|
|
@ -1215,7 +1215,7 @@ def admin_request(rid):
|
||||||
attachments.append((str(p), p.name))
|
attachments.append((str(p), p.name))
|
||||||
cfg = load_booth_settings()
|
cfg = load_booth_settings()
|
||||||
if cfg.get('deliver_album_cover') and req.get('album_cover_url'):
|
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:
|
if cover_path:
|
||||||
attachments.append((cover_path, f"cover{Path(cover_path).suffix}"))
|
attachments.append((cover_path, f"cover{Path(cover_path).suffix}"))
|
||||||
|
|
||||||
|
|
|
||||||
16
helpers.py
16
helpers.py
|
|
@ -735,17 +735,29 @@ def format_musicgpt_cost(cost):
|
||||||
return f"${float(cost):.4f} USD"
|
return f"${float(cost):.4f} USD"
|
||||||
|
|
||||||
|
|
||||||
def download_album_cover(rid, cover_url):
|
def download_album_cover(rid, cover_url, max_width=160):
|
||||||
"""Download a MusicGPT album cover to a temp file and return its path."""
|
"""
|
||||||
|
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:
|
if not cover_url:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from PIL import Image
|
||||||
resp = requests.get(cover_url, timeout=30)
|
resp = requests.get(cover_url, timeout=30)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
ext = Path(cover_url).suffix or '.jpg'
|
ext = Path(cover_url).suffix or '.jpg'
|
||||||
tmp = Path(tempfile.gettempdir()) / f"cover_{rid}{ext}"
|
tmp = Path(tempfile.gettempdir()) / f"cover_{rid}{ext}"
|
||||||
tmp.write_bytes(resp.content)
|
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)
|
return str(tmp)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
# mutagen - MP3 metadata (ID3) tagging
|
# mutagen - MP3 metadata (ID3) tagging
|
||||||
# flask-limiter - public form rate limiting
|
# flask-limiter - public form rate limiting
|
||||||
# cryptography - encrypt stored SMTP password
|
# cryptography - encrypt stored SMTP password
|
||||||
|
# pillow - resize album cover images before email delivery
|
||||||
|
|
||||||
flask
|
flask
|
||||||
gunicorn
|
gunicorn
|
||||||
|
|
@ -18,4 +19,5 @@ werkzeug
|
||||||
mutagen
|
mutagen
|
||||||
flask-limiter
|
flask-limiter
|
||||||
cryptography
|
cryptography
|
||||||
|
pillow
|
||||||
requests
|
requests
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,10 @@
|
||||||
|
|
||||||
{% if req.album_cover_url %}
|
{% if req.album_cover_url %}
|
||||||
<div class="section" style="text-align:center">
|
<div class="section" style="text-align:center">
|
||||||
<img src="{{ req.album_cover_url }}" alt="Album cover" style="max-width:320px;border-radius:.5rem">
|
<img src="{{ req.album_cover_url }}" alt="Album cover" style="max-width:160px;border-radius:.5rem">
|
||||||
|
{% if not deliver_album_cover %}
|
||||||
|
<p class="copy-hint">Album cover is hidden from the customer preview/delivery because delivery is disabled in settings.</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,9 +129,9 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Album cover -->
|
<!-- Album cover -->
|
||||||
{% if req.album_cover_url %}
|
{% if req.album_cover_url and deliver_album_cover %}
|
||||||
<div style="text-align:center;margin:1rem 0">
|
<div style="text-align:center;margin:1rem 0">
|
||||||
<img src="{{ req.album_cover_url }}" alt="Album cover" style="max-width:320px;border-radius:.5rem">
|
<img src="{{ req.album_cover_url }}" alt="Album cover" style="max-width:160px;border-radius:.5rem">
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue