Checkbox für Playliste hinzugefügt
This commit is contained in:
95
app.py
95
app.py
@@ -70,6 +70,16 @@ def normalize_url(value):
|
||||
return None
|
||||
|
||||
|
||||
def playlist_item_enabled(item):
|
||||
return not (isinstance(item, dict) and item.get("enabled") is False)
|
||||
|
||||
|
||||
def playlist_item_name(item):
|
||||
if isinstance(item, dict):
|
||||
return item.get("url") or item.get("name")
|
||||
return item
|
||||
|
||||
|
||||
# -------------------------------------------------
|
||||
# Auth / Benutzer
|
||||
# -------------------------------------------------
|
||||
@@ -108,7 +118,7 @@ def logout():
|
||||
# Customer / Willkommensseite
|
||||
# -------------------------------------------------
|
||||
@app.route("/customer", methods=["GET", "POST"])
|
||||
@login_required
|
||||
# @login_required
|
||||
def add_customer():
|
||||
"""Add new customer with logo search and welcome page"""
|
||||
error = None
|
||||
@@ -147,7 +157,7 @@ def add_customer():
|
||||
return render_template("customer.html", error=error, success=success, logo_url=logo_url)
|
||||
|
||||
@app.route("/api/customer", methods=["POST"])
|
||||
@login_required
|
||||
# @login_required
|
||||
def api_add_customer():
|
||||
"""API endpoint for customer creation"""
|
||||
try:
|
||||
@@ -231,25 +241,29 @@ def player(screen):
|
||||
|
||||
# 1. Playlist-Reihenfolge
|
||||
for item in playlist:
|
||||
if not playlist_item_enabled(item):
|
||||
continue
|
||||
item_name = playlist_item_name(item)
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
if url_data:
|
||||
normal_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0)})
|
||||
normal_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0), "enabled": True})
|
||||
continue
|
||||
|
||||
if os.path.exists(os.path.join(folder, item)) and allowed_file(item):
|
||||
normal_files.append({"kind": "file", "name": item})
|
||||
if item_name and os.path.exists(os.path.join(folder, item_name)) and allowed_file(item_name):
|
||||
normal_files.append({"kind": "file", "name": item_name, "enabled": True})
|
||||
|
||||
existing_file_names = {
|
||||
item["name"] for item in normal_files if item["kind"] == "file"
|
||||
}
|
||||
|
||||
# 2. Neue Dateien hintendran
|
||||
for f in sorted(os.listdir(folder)):
|
||||
if f in existing_file_names or f.startswith("._"):
|
||||
continue
|
||||
if allowed_file(f):
|
||||
normal_files.append({"kind": "file", "name": f})
|
||||
if not playlist:
|
||||
for f in sorted(os.listdir(folder)):
|
||||
if f in existing_file_names or f.startswith("._"):
|
||||
continue
|
||||
if allowed_file(f):
|
||||
normal_files.append({"kind": "file", "name": f})
|
||||
|
||||
# ------------------------------
|
||||
# Priority-Playlist (global)
|
||||
@@ -260,23 +274,26 @@ def player(screen):
|
||||
if priority_cfg.get("enabled", False):
|
||||
prio_files = []
|
||||
for item in priority_cfg.get("playlist", []):
|
||||
if not playlist_item_enabled(item):
|
||||
continue
|
||||
item_name = playlist_item_name(item)
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
if url_data:
|
||||
prio_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0)})
|
||||
prio_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0), "enabled": True})
|
||||
continue
|
||||
|
||||
file_path = os.path.join(MEDIA_DIR, "priority", item)
|
||||
file_path = os.path.join(MEDIA_DIR, "priority", item_name)
|
||||
if os.path.exists(file_path):
|
||||
prio_files.append({"kind": "file", "name": item})
|
||||
prio_files.append({"kind": "file", "name": item_name, "enabled": True})
|
||||
else:
|
||||
prio_files = []
|
||||
|
||||
return render_template(
|
||||
"player.html",
|
||||
screen=screen,
|
||||
normal_files=normal_files, # ✅ explizit
|
||||
prio_files=prio_files, # ✅ IMMER Liste
|
||||
normal_files=[item for item in normal_files if item.get("enabled", True)],
|
||||
prio_files=[item for item in prio_files if item.get("enabled", True)],
|
||||
interval=screen_cfg.get("interval", 10),
|
||||
newsticker_text=screen_cfg.get("newsticker_text", ""),
|
||||
newsticker_enabled=screen_cfg.get("newsticker_enabled", False)
|
||||
@@ -336,6 +353,8 @@ def admin():
|
||||
|
||||
# 1️⃣ Playlist-Reihenfolge
|
||||
for item in playlist:
|
||||
item_name = playlist_item_name(item)
|
||||
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
if url_data:
|
||||
@@ -343,15 +362,16 @@ def admin():
|
||||
"name": url_data["url"],
|
||||
"type": "url",
|
||||
"size": "URL",
|
||||
"zoom": url_data.get("zoom", 1.0)
|
||||
"zoom": url_data.get("zoom", 1.0),
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
continue
|
||||
|
||||
file_path = os.path.join(path, item)
|
||||
file_path = os.path.join(path, item_name)
|
||||
if not os.path.exists(file_path):
|
||||
continue
|
||||
|
||||
ext = os.path.splitext(item)[1].lower()
|
||||
ext = os.path.splitext(item_name)[1].lower()
|
||||
if ext == ".mp4":
|
||||
ftype = "video"
|
||||
if ext in (".jpg", ".jpeg", ".png"):
|
||||
@@ -362,14 +382,16 @@ def admin():
|
||||
size = os.path.getsize(file_path) // 1024
|
||||
|
||||
files.append({
|
||||
"name": item,
|
||||
"name": item_name,
|
||||
"type": ftype,
|
||||
"size": size
|
||||
"size": size,
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
|
||||
# 2️⃣ Neue Dateien anhängen (nicht in Playlist)
|
||||
playlist_names = {playlist_item_name(item) for item in playlist}
|
||||
for f in sorted(os.listdir(path)):
|
||||
if f in playlist or f.startswith("._"):
|
||||
if f in playlist_names or f.startswith("._"):
|
||||
continue
|
||||
|
||||
file_path = os.path.join(path, f)
|
||||
@@ -397,6 +419,7 @@ def admin():
|
||||
|
||||
# 1️⃣ Playlist-Reihenfolge
|
||||
for item in prio_playlist:
|
||||
item_name = playlist_item_name(item)
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
if url_data:
|
||||
@@ -404,22 +427,24 @@ def admin():
|
||||
"name": url_data["url"],
|
||||
"type": "url",
|
||||
"size": "URL",
|
||||
"zoom": url_data.get("zoom", 1.0)
|
||||
})
|
||||
"zoom": url_data.get("zoom", 1.0),
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
continue
|
||||
|
||||
file_path = os.path.join(prio_dir, item)
|
||||
file_path = os.path.join(prio_dir, item_name)
|
||||
if not os.path.exists(file_path):
|
||||
continue
|
||||
|
||||
ext = os.path.splitext(item)[1].lower()
|
||||
ext = os.path.splitext(item_name)[1].lower()
|
||||
ftype = "video" if ext == ".mp4" else "image"
|
||||
size = os.path.getsize(file_path) // 1024
|
||||
|
||||
priority_files.append({
|
||||
"name": item,
|
||||
"name": item_name,
|
||||
"type": ftype,
|
||||
"size": size
|
||||
"size": size,
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
|
||||
# 2️⃣ Neue Dateien anhängen (nicht in Playlist)
|
||||
@@ -576,6 +601,7 @@ def save_playlist(screen):
|
||||
cfg = load_config()
|
||||
data = request.get_json()
|
||||
new_order = data["playlist"] # List of filenames/URLs as strings
|
||||
enabled_map = data.get("enabled", {})
|
||||
|
||||
# Get the current playlist with all data (including zoom factors)
|
||||
if screen == "priority":
|
||||
@@ -586,20 +612,17 @@ def save_playlist(screen):
|
||||
# Create a mapping: filename/url -> full item (preserves zoom factor)
|
||||
item_map = {}
|
||||
for item in old_playlist:
|
||||
if isinstance(item, dict) and "url" in item:
|
||||
key = item["url"] # URL as key
|
||||
else:
|
||||
key = item # Filename as key
|
||||
item_map[key] = item
|
||||
item_map[playlist_item_name(item)] = item
|
||||
|
||||
# Build new playlist: use the mapping to preserve zoom factors
|
||||
new_playlist = []
|
||||
for key in new_order:
|
||||
if key in item_map:
|
||||
new_playlist.append(item_map[key])
|
||||
item = dict(item_map[key]) if isinstance(item_map[key], dict) else {"name": item_map[key]}
|
||||
item["enabled"] = enabled_map.get(key, True if not isinstance(item_map[key], dict) else item_map[key].get("enabled", True))
|
||||
new_playlist.append(item)
|
||||
else:
|
||||
# Item not found in mapping - add as is
|
||||
new_playlist.append(key)
|
||||
new_playlist.append({"url": key, "zoom": 1.0, "enabled": enabled_map.get(key, True)} if is_url(key) else {"name": key, "enabled": enabled_map.get(key, True)})
|
||||
|
||||
if screen == "priority":
|
||||
cfg.setdefault("priority", {})["playlist"] = new_playlist
|
||||
@@ -614,4 +637,4 @@ def save_playlist(screen):
|
||||
# Main
|
||||
# -------------------------------------------------
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, host="0.0.0.0", port=5005)
|
||||
app.run(debug=True, host="0.0.0.0", port=5005)
|
||||
|
||||
Reference in New Issue
Block a user