From 46e9d5c40dc4dad65b6e85be03b031fe142b49a2 Mon Sep 17 00:00:00 2001 From: mikka Date: Sun, 19 Apr 2026 11:19:35 +0200 Subject: [PATCH] Zweite version Playist management --- app.py | 53 +++++++++++++++++++++++++++++++++------- static/script.js | 7 +++++- templates/index.html | 4 +-- templates/karte.html | 6 +++++ templates/neueliste.html | 1 + templates/playlists.html | 6 +++++ templates/suche.html | 7 ++++-- 7 files changed, 70 insertions(+), 14 deletions(-) mode change 100755 => 100644 app.py mode change 100755 => 100644 static/script.js mode change 100755 => 100644 templates/index.html mode change 100755 => 100644 templates/karte.html create mode 100644 templates/neueliste.html create mode 100644 templates/playlists.html mode change 100755 => 100644 templates/suche.html diff --git a/app.py b/app.py old mode 100755 new mode 100644 index d82b498..0f812c3 --- a/app.py +++ b/app.py @@ -47,8 +47,6 @@ def datei(id): return audio -with open("songs.json","r") as f: - songs = json.load(f) def kartenGeneriren(song): id = song["wikiid"] statements = wikiapi(id,"statements") @@ -66,7 +64,6 @@ def kartenGeneriren(song): song["interprete"] = " x ".join(set(wikiapi(statement["value"]["content"],"labels")["en"] for statement in statements.get("P175",[]))) if "ytid" not in song and "P1651" in statements: song["ytid"] = statements["P1651"][0]["value"]["content"] - print(song) if "ytid" in song: song["datei"] = datei(song["ytid"]) song["img"] = f"http://img.youtube.com/vi/{ song["ytid"] }/sddefault.jpg" @@ -76,8 +73,7 @@ def kartenGeneriren(song): song["img"] = f"https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/{statements["P18"][0]["value"]["content"]}&width=300" if "img" not in song: song["img"] = "https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/Eurovision_Song_Contest_heart_(2014–2025).svg&width=300" -for song in songs: - kartenGeneriren(song) + app = Flask(__name__) @@ -90,28 +86,67 @@ def zeit(sekunden): @app.route("/") def hello_world(): + liste = request.args.get("liste") + print("/") + print(liste) + if liste is None: + return redirect("/playlists") + print(liste) + with open(liste+".json","r") as f: + songs = json.load(f) + for song in songs: + kartenGeneriren(song) + print(songs) gesamtLaenge = 0 for song in songs: gesamtLaenge += song["laenge"] - return render_template('index.html', karten=songs,gesamtLaenge=gesamtLaenge ) + return render_template('index.html', karten=songs,gesamtLaenge=gesamtLaenge,liste=liste ) + + +@app.route("/playlists") +def playlists(): + listen = glob("*.json") + listen = (liste.replace(".json","") for liste in listen) + print("/playlists") + print(listen) + return render_template('playlists.html',lists=listen) + +@app.route("/neueliste") +def neueliste(): + name = request.args.get("name") + print("/neueliste") + print(name) + if name is not None: + with open(name +".json", "x") as f: + json.dump([],f) + return redirect("/?liste="+name) + print(liste) + return render_template('neueliste.html',name=name) @app.route("/suche") def suche(): such = request.args.get("suche") + liste = request.args.get("liste") + print("/suche") + print(liste) if such is not None: ergebnisse = wikisuche(such) else: ergebnisse = [] - return render_template('suche.html', ergebnisse=ergebnisse,anfrage=such) + return render_template('suche.html', ergebnisse=ergebnisse,anfrage=such,liste=liste) @app.route("/suche",methods=["POST"]) def suche_finden(): + liste = request.args.get("liste") + with open(liste +".json","r") as f: + songs = json.load(f) song = {"wikiid":request.form.get("id")} kartenGeneriren(song) songs.append(song) - with open("songs.json","w") as f: + print(liste) + with open(liste+".json","w") as f: json.dump(songs,f,indent=2,ensure_ascii=False) - return redirect("/",303) + return redirect("/?liste="+liste,303) @app.route("/ADMIN") def admin(): diff --git a/static/script.js b/static/script.js old mode 100755 new mode 100644 index 7794646..0b01684 --- a/static/script.js +++ b/static/script.js @@ -1,6 +1,11 @@ const audios = document.querySelectorAll("audio") for (const [index,audio] of audios.entries()){ - audio.addEventListener("ended", (event) => { audios[index + 1].play()}) + audio.addEventListener("ended", (event) => { + if (index+1!= audios.length){ + audios[index + 1].play() + } + + }) } console.log(audios) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html old mode 100755 new mode 100644 index 17c39b2..da1045d --- a/templates/index.html +++ b/templates/index.html @@ -47,8 +47,8 @@

ESC Playlist

2026

-Du willst ein weiteres Lied in der Playlist? -

Die Playlist ist insgesamt lang {{ gesamtLaenge | zeit }} und enthält {{ karten|length }} Lieder

+Du willst ein weiteres Lied in der Playlist? +

Die Playlist {{liste}} ist insgesamt lang {{ gesamtLaenge | zeit }} und enthält {{ karten|length }} Lieder

{% for karte in karten %} {% set karte_loop = loop %} diff --git a/templates/karte.html b/templates/karte.html old mode 100755 new mode 100644 index 8e2eb5a..7a8654e --- a/templates/karte.html +++ b/templates/karte.html @@ -1,11 +1,17 @@
+ {% if karte.ytid %} + {% endif %}

{{ karte.titel}}

Übersetzter Titel:{{ karte.uetitel}}

Interpreten:{{ karte.interprete}}

+ {% if karte.jahrgang %}

Jahrgang: {{ karte.jahrgang }}

+ {% endif %} + {% if karte.plazirung%}

Plazirung: {{ karte.plazirung }}

+ {% endif %}

Länge: {{karte.laenge|zeit}}

Interesanter Fakt: {{ karte.interesanterfakt }}

{% if karte.text %} diff --git a/templates/neueliste.html b/templates/neueliste.html new file mode 100644 index 0000000..9fc279b --- /dev/null +++ b/templates/neueliste.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/templates/playlists.html b/templates/playlists.html new file mode 100644 index 0000000..62a6f1d --- /dev/null +++ b/templates/playlists.html @@ -0,0 +1,6 @@ +
    +{% for list in lists %} +
  • {{list}}
  • +{% endfor %} +
+Lust auf was neues? \ No newline at end of file diff --git a/templates/suche.html b/templates/suche.html old mode 100755 new mode 100644 index c54ffe0..71fc9c0 --- a/templates/suche.html +++ b/templates/suche.html @@ -1,4 +1,7 @@ -
+{% if liste == empty %} +

Du musst etwas in die Playlist Screiben

+{% endif %} +
{% if ergebnisse %}
    {% for ergebnis in ergebnisse %} @@ -6,7 +9,7 @@ {% endfor %}
{%elif anfrage%} -

Leider gibt es diesen Eintrag nicht!

+

Leider gibt es den Eintrag {{anfrage}} nicht!

{%endif%} Doch nicht? \ No newline at end of file