small improvements

This commit is contained in:
2025-07-21 20:44:30 +02:00
parent 5a0727abac
commit b4420e334d
2 changed files with 180 additions and 95 deletions

View File

@ -12,6 +12,11 @@ from PIL import Image
from typing import List, Dict, Any
import pandas as pd
import re
from enum import Enum
class CardStyle(str,Enum):
FULL_ALBUM_COVER = "full album cover"
MINIMAL = "minimal"
class Hipsterfy(object):
@ -42,38 +47,25 @@ class HipsterfyPlaylistItem(object):
return img_html
def generate_hipsterfy_front_card(self, include_preview:bool = False, print_mode:bool = False):
def generate_hipsterfy_front_card(self, include_preview:bool = False, card_style:CardStyle = CardStyle.FULL_ALBUM_COVER):
# generates the square front card only with the centered qr code
preview_html = self.embed_html if include_preview else ""
if not self._qr_html:
return ""
if print_mode:
# Minimalistisches Layout für Druck: kein Hintergrund, kein Schatten, kein Rahmen
card_style = """
width: 300px; height: 300px;
border: 1.5px;
border-radius: 18px;
display: flex;
align-items: center;
justify-content: center;
background: none;
margin: 18px;
box-shadow: none;
transition: none;
"""
else:
card_style = """
width: 300px; height: 300px;
border: 1.5px solid #222;
border-radius: 18px;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #f9f9f9 60%, #e0e0e0 100%);
margin: 18px;
box-shadow: 0 6px 24px rgba(0,0,0,0.13), 0 1.5px 4px rgba(0,0,0,0.07);
transition: box-shadow 0.2s;
"""
card_style = """
width: 300px; height: 300px;
border: 1.5px;
border-radius: 18px;
display: flex;
align-items: center;
justify-content: center;
background: none;
margin: 18px;
box-shadow: none;
transition: none;
"""
return f"""
<div style="{card_style}">
<div style="text-align: center;">
@ -89,46 +81,108 @@ class HipsterfyPlaylistItem(object):
</div>
"""
def generate_hipsterfy_back_card(self, primary_property, secondary_property, additional_properties:List[str]=None, album_cover_gb:bool = True, print_mode:bool = False):
# generates the back card with primary and secondary property and additional properties
def generate_hipsterfy_back_card(
self,
primary_property,
secondary_property,
additional_properties: List[str] = None,
card_style: CardStyle = CardStyle.FULL_ALBUM_COVER
):
additional_html = ""
if additional_properties:
for prop in additional_properties:
value = getattr(self, f"{prop}", "N/A")
additional_html += f"<div style='margin: 4px 0; color:#fff;'><strong style='color:#fff;'>{prop.replace('_', ' ').title()}:</strong> <span style='color:#fff;'>{value}</span></div>"
# Albumcover als Hintergrund
album_bg = ""
if album_cover_gb and self.album_images and len(self.album_images) > 0:
# Style für die innere Box (Textfeld)
inner_box_style_full = """
width: 250px;
height: 250px;
margin: auto;
background: rgba(0,0,0,0.35);
border-radius: 18px;
padding: 24px 18px 18px 18px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-sizing: border-box;
position: relative;
z-index: 1;
backdrop-filter: blur(2px);
-webkit-backdrop-filter: blur(2px);
"""
inner_box_style_minimal = """
width: 250px;
height: 250px;
margin: auto;
background: #fff;
border-radius: 18px;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
padding: 24px 18px 18px 18px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-sizing: border-box;
position: relative;
z-index: 1;
"""
# FULL_ALBUM_COVER: Albumcover als Hintergrund, weiße Schrift, abgedunkelte Box
if CardStyle(card_style) == CardStyle.FULL_ALBUM_COVER and self.album_images and len(self.album_images) > 0:
album_url = self.album_images[0]['url']
album_bg = f"""
background:
outer_style = f"""
width: 300px; height: 300px;
border: 1.5px solid #222;
border-radius: 18px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background:
linear-gradient(135deg, rgba(30,30,30,0.65) 60%, rgba(0,0,0,0.85) 100%),
url('{album_url}') center center/cover no-repeat;
margin: 18px;
box-shadow: 0 6px 24px rgba(0,0,0,0.13), 0 1.5px 4px rgba(0,0,0,0.07);
color: #fff;
overflow: hidden;
position: relative;
transition: box-shadow 0.2s;
"""
text_color = "#fff"
additional_html = additional_html.replace("color:#fff", f"color:{text_color}")
primary_color = "#fff"
secondary_color = "#e0e0e0"
inner_box_style = inner_box_style_full
# MINIMAL: Weißer Hintergrund, schwarze Schrift, nur Kontur
else:
album_bg = "background: #f9f9f9;"
outer_style = """
width: 300px; height: 300px;
border: 2px solid #222;
border-radius: 18px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #fff;
margin: 18px;
box-shadow: none;
color: #222;
overflow: hidden;
position: relative;
transition: box-shadow 0.2s;
"""
inner_box_style = inner_box_style_minimal
additional_html = additional_html.replace("color:#fff", "color:#222")
primary_color = "#222"
secondary_color = "#444"
return f"""
<div style="
width: 300px; height: 300px;
border: 1.5px solid #222;
border-radius: 18px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
{album_bg}
margin: 18px;
box-shadow: 0 6px 24px rgba(0,0,0,0.13), 0 1.5px 4px rgba(0,0,0,0.07);
color: #fff;
overflow: hidden;
position: relative;
transition: box-shadow 0.2s;
">
<div style="text-align: center; padding: 24px 18px 18px 18px; background: rgba(0,0,0,0.35); border-radius: 12px;">
<p style="margin: 0 0 12px 0; font-size: 1.1em; color: #e0e0e0; text-shadow: 0 1px 4px #000;">{getattr(self, secondary_property)}</p>
<h3 style="margin: 0 0 8px 0; font-size: 1.35em; color: #fff; text-shadow: 0 2px 8px #000;">{getattr(self, primary_property)}</h3>
<div style="{outer_style}">
<div style="{inner_box_style}">
<p style="margin: 0 0 12px 0; font-size: 1.1em; color: {secondary_color}; text-shadow: none;">{getattr(self, secondary_property)}</p>
<h3 style="margin: 0 0 8px 0; font-size: 1.35em; color: {primary_color}; text-shadow: none;">{getattr(self, primary_property)}</h3>
{additional_html}
</div>
</div>