modified: app.py

modified:   templates/quiz.html
This commit is contained in:
2025-11-15 00:16:22 +01:00
parent 98bb694004
commit 4cf7dbc627
2 changed files with 50 additions and 4 deletions

24
app.py
View File

@@ -258,6 +258,10 @@ def check_answer():
correct_answer = data.get('correct_answer', '').lower() correct_answer = data.get('correct_answer', '').lower()
game_mode = data.get('game_mode', 'artist') game_mode = data.get('game_mode', 'artist')
playlist_id = data.get('playlist_id') playlist_id = data.get('playlist_id')
all_tracks = data.get('all_tracks', [])
# Originalwert für Vergleich speichern
original_guess = guess
# Bei Titel und Künstler: Sonderzeichen entfernen für besseren Vergleich # Bei Titel und Künstler: Sonderzeichen entfernen für besseren Vergleich
if game_mode == 'title' or game_mode == 'artist': if game_mode == 'title' or game_mode == 'artist':
@@ -274,11 +278,29 @@ def check_answer():
key = f'score_{playlist_id}' key = f'score_{playlist_id}'
session[key] = session.get(key, 0) + 1 session[key] = session.get(key, 0) + 1
return { # Bei falscher Antwort: Finde das eingegebene Lied in all_tracks
guessed_track = None
if not is_correct and all_tracks:
for track in all_tracks:
if game_mode == 'title':
if clean_title(track['name'].lower()) == guess:
guessed_track = track
break
elif game_mode == 'artist':
if clean_title(track['artist'].lower()) == guess:
guessed_track = track
break
response = {
"correct": is_correct, "correct": is_correct,
"correct_answer": correct_answer "correct_answer": correct_answer
} }
if guessed_track:
response["guessed_track"] = guessed_track
return response
@app.route("/play_track", methods=["POST"]) @app.route("/play_track", methods=["POST"])
def play_track(): def play_track():
device_id = request.args.get('device_id') device_id = request.args.get('device_id')

View File

@@ -381,7 +381,8 @@
guess: guess, guess: guess,
correct_answer: correctAnswer, correct_answer: correctAnswer,
game_mode: currentGameMode, game_mode: currentGameMode,
playlist_id: "{{ playlist_id }}" playlist_id: "{{ playlist_id }}",
all_tracks: allTracks // Sende alle Tracks mit, um das falsche Lied zu finden
}) })
}) })
.then(response => response.json()) .then(response => response.json())
@@ -394,9 +395,32 @@
resultContainer.innerHTML = `<h3>${i18n.correct}</h3>`; resultContainer.innerHTML = `<h3>${i18n.correct}</h3>`;
} else { } else {
resultContainer.className = 'result-container incorrect'; resultContainer.className = 'result-container incorrect';
// Wenn ein falsches Lied erkannt wurde, zeige Vergleich an
if (data.guessed_track) {
resultContainer.innerHTML = `
<h3>${i18n.wrong}</h3>
<div style="display:flex; gap:20px; margin-top:20px; justify-content:center; flex-wrap:wrap;">
<!-- Falsches Lied (Links) -->
<div style="flex:1; min-width:250px; max-width:350px; padding:15px; background:rgba(244,67,54,0.15); border:2px solid #f44336; border-radius:12px;">
<h4 style="color:#f44336; margin-bottom:10px;">❌ ${i18n.your_answer || 'Your Answer'}</h4>
<p style="margin:5px 0;"><strong>${i18n.song || 'Song'}:</strong> ${data.guessed_track.name}</p>
<p style="margin:5px 0;"><strong>${i18n.artist || 'Artist'}:</strong> ${data.guessed_track.artist}</p>
</div>
<!-- Richtiges Lied (Rechts) -->
<div style="flex:1; min-width:250px; max-width:350px; padding:15px; background:rgba(76,175,80,0.15); border:2px solid #4CAF50; border-radius:12px;">
<h4 style="color:#4CAF50; margin-bottom:10px;">✓ ${i18n.correct_answer || 'Correct Answer'}</h4>
<p style="margin:5px 0;"><strong>${i18n.song || 'Song'}:</strong> {{ track.name | clean }}</p>
<p style="margin:5px 0;"><strong>${i18n.artist || 'Artist'}:</strong> {{ track.artists[0].name | clean }}</p>
</div>
</div>
`;
} else {
// Fallback: Nur die richtige Antwort anzeigen
resultContainer.innerHTML = `<h3>${i18n.wrong}</h3> resultContainer.innerHTML = `<h3>${i18n.wrong}</h3>
<p>${i18n.right_answer} <strong>${data.correct_answer}</strong></p>`; <p>${i18n.right_answer} <strong>${data.correct_answer}</strong></p>`;
} }
}
// Song-Infos ergänzen // Song-Infos ergänzen
resultContainer.innerHTML += ` resultContainer.innerHTML += `