modified: app.py
This commit is contained in:
18
app.py
18
app.py
@@ -32,6 +32,21 @@ def clean_title(title):
|
|||||||
# Entfernt alles in () oder []
|
# Entfernt alles in () oder []
|
||||||
return re.sub(r"(\s*[\(\[][^)\]]*[\)\]])", "", title).strip()
|
return re.sub(r"(\s*[\(\[][^)\]]*[\)\]])", "", title).strip()
|
||||||
|
|
||||||
|
def get_all_playlist_tracks(sp, playlist_id):
|
||||||
|
tracks = []
|
||||||
|
offset = 0
|
||||||
|
limit = 100
|
||||||
|
while True:
|
||||||
|
response = sp.playlist_items(playlist_id, additional_types=["track"], limit=limit, offset=offset)
|
||||||
|
items = response["items"]
|
||||||
|
if not items:
|
||||||
|
break
|
||||||
|
tracks.extend([item["track"] for item in items if item.get("track")])
|
||||||
|
if len(items) < limit:
|
||||||
|
break
|
||||||
|
offset += limit
|
||||||
|
return tracks
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
return render_template("login.html")
|
return render_template("login.html")
|
||||||
@@ -72,8 +87,7 @@ def quiz(playlist_id):
|
|||||||
game_mode = request.args.get('mode', 'artist')
|
game_mode = request.args.get('mode', 'artist')
|
||||||
|
|
||||||
sp = get_spotify_client()
|
sp = get_spotify_client()
|
||||||
items = sp.playlist_items(playlist_id, additional_types=["track"])["items"]
|
tracks = get_all_playlist_tracks(sp, playlist_id)
|
||||||
tracks = [item["track"] for item in items if item.get("track")]
|
|
||||||
|
|
||||||
if not tracks:
|
if not tracks:
|
||||||
return "Keine Tracks verfügbar!"
|
return "Keine Tracks verfügbar!"
|
||||||
|
|||||||
Reference in New Issue
Block a user