From 9b8b92f2316bdb2eaf62bf54c0becdeda3f0b58d Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Sun, 1 Jun 2025 18:51:12 +0200 Subject: [PATCH 01/55] modified: app.py --- app.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index e0d0daa..94e9c97 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ import random from difflib import SequenceMatcher import re import json +import unicodedata app = Flask(__name__) app.secret_key = os.getenv("SECRET_KEY") @@ -53,13 +54,20 @@ def similarity(a, b): return SequenceMatcher(None, a.lower(), b.lower()).ratio() def clean_title(title): + # Unicode-Normalisierung (z.B. é -> e) + title = unicodedata.normalize('NFKD', title) + title = "".join([c for c in title if not unicodedata.combining(c)]) # Entfernt alles in () oder [] title = re.sub(r"(\s*[\(\[][^)\]]*[\)\]])", "", title) # Vereinheitliche Apostrophen und Anführungszeichen title = title.replace("’", "'").replace("‘", "'").replace("`", "'") title = title.replace('"', '').replace("„", '').replace("“", '').replace("”", '') - title = title.replace("'", "") # Optional: alle Apostrophen entfernen - return title.strip() + title = title.replace("'", "") + # Entferne alle nicht-alphanumerischen Zeichen (außer Leerzeichen) + title = re.sub(r"[^a-zA-Z0-9äöüÄÖÜß ]", "", title) + # Mehrfache Leerzeichen zu einem + title = re.sub(r"\s+", " ", title) + return title.strip().lower() def get_all_playlist_tracks(sp, playlist_id): tracks = [] @@ -215,7 +223,8 @@ def check_answer(): game_mode = data.get('game_mode', 'artist') playlist_id = data.get('playlist_id') - if game_mode == 'title': + # Immer clean_title für title und artist + if game_mode in ['title', 'artist']: guess = clean_title(guess) correct_answer = clean_title(correct_answer) From 9b894d768733f0e5f848df2bf28160a764027b48 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Sun, 1 Jun 2025 18:58:28 +0200 Subject: [PATCH 02/55] modified: templates/quiz.html --- templates/quiz.html | 69 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/templates/quiz.html b/templates/quiz.html index 6ee08d9..71c8a32 100644 --- a/templates/quiz.html +++ b/templates/quiz.html @@ -133,8 +133,7 @@ console.log('Ready with Device ID', device_id); document.getElementById('device_id').value = device_id; - // Hole Optionen - const playDuration = parseInt(getOption('playDuration', '0'), 10); + const playDuration = getPlayDuration(); const startPosition = getOption('startPosition', 'start'); let position_ms = 0; if (startPosition === 'random') { @@ -156,7 +155,7 @@ // Stoppe nach playDuration Sekunden (wenn nicht unendlich) if (playDuration > 0) { - setTimeout(() => { + window.quizifyTimeout = setTimeout(() => { player.pause(); }, playDuration * 1000); } @@ -189,11 +188,11 @@ correctAnswer = "{{ track.artists[0].name }}"; document.getElementById('question-text').innerText = i18n.question_artist; document.getElementById('answerInput').placeholder = i18n.input_artist; - } else if (currentGameMode === 'title') { + } else if (currentGameMode === 'title' ) { correctAnswer = "{{ track.name }}"; document.getElementById('question-text').innerText = i18n.question_title; document.getElementById('answerInput').placeholder = i18n.input_title; - } else if (currentGameMode === 'year') { + } else if (currentGameMode === 'year' ) { correctAnswer = "{{ track.album.release_date[:4] }}"; document.getElementById('question-text').innerText = i18n.question_year; document.getElementById('answerInput').placeholder = i18n.input_year; @@ -318,9 +317,57 @@ function getOption(key, defaultValue) { return localStorage.getItem(key) || defaultValue; } window.onload = function() { - document.getElementById('playDuration').value = getOption('playDuration', '0'); + const playDuration = getOption('playDuration', '0'); + const sel = document.getElementById('playDuration'); + const custom = document.getElementById('customDuration'); + const label = document.getElementById('customDurationLabel'); + if (['10','15','30','0'].includes(playDuration)) { + sel.value = playDuration; + custom.style.display = 'none'; + label.style.display = 'none'; + } else { + sel.value = 'custom'; + custom.value = playDuration; + custom.style.display = ''; + label.style.display = ''; + } document.getElementById('startPosition').value = getOption('startPosition', 'start'); }; + +function onPlayDurationChange() { + const sel = document.getElementById('playDuration'); + const custom = document.getElementById('customDuration'); + const label = document.getElementById('customDurationLabel'); + if (sel.value === 'custom') { + custom.style.display = ''; + label.style.display = ''; + setOption('playDuration', custom.value || '10'); + } else { + custom.style.display = 'none'; + label.style.display = 'none'; + setOption('playDuration', sel.value); + } +} + +function getPlayDuration() { + const sel = document.getElementById('playDuration'); + if (sel.value === 'custom') { + return parseInt(document.getElementById('customDuration').value) || 10; + } + return parseInt(sel.value); +} + +// "Nochmal X Sekunden"-Button Funktion +function replayDuration() { + const playDuration = getPlayDuration(); + if (window.spotifyPlayer) { + window.spotifyPlayer.resume(); + if (window.quizifyTimeout) clearTimeout(window.quizifyTimeout); + window.quizifyTimeout = setTimeout(() => { + window.spotifyPlayer.pause(); + }, playDuration * 1000); + } +} @@ -350,12 +397,15 @@ window.onload = function() {