diff --git a/app.py b/app.py index 88f2343..d5d30a0 100644 --- a/app.py +++ b/app.py @@ -8,6 +8,7 @@ import spotipy from spotipy.oauth2 import SpotifyOAuth import random from difflib import SequenceMatcher +import re app = Flask(__name__) app.secret_key = os.getenv("SECRET_KEY") @@ -27,6 +28,10 @@ def get_spotify_client(): def similarity(a, b): return SequenceMatcher(None, a.lower(), b.lower()).ratio() +def clean_title(title): + # Entfernt (feat. ...), [Remix ...], (Remix), [xyz], usw. + return re.sub(r"(\s*[\(\[][^)\]]*[\)\]])", "", title).strip() + @app.route("/") def home(): return render_template("login.html") @@ -153,14 +158,19 @@ def check_answer(): guess = data.get('guess', '').lower() correct_answer = data.get('correct_answer', '').lower() game_mode = data.get('game_mode', 'artist') - + + # Titel ggf. bereinigen + if game_mode == 'title': + guess = clean_title(guess) + correct_answer = clean_title(correct_answer) + # Bei Jahr-Modus: Exakte Übereinstimmung prüfen if game_mode == 'year': is_correct = guess == correct_answer else: # Bei anderen Modi: Ähnlichkeitsprüfung (90% Übereinstimmung gilt als korrekt) is_correct = similarity(guess, correct_answer) >= 0.9 - + return { "correct": is_correct, "correct_answer": correct_answer