Zweite version
Playist management
This commit is contained in:
parent
39f95c2857
commit
46e9d5c40d
7 changed files with 70 additions and 14 deletions
53
app.py
Executable file → Normal file
53
app.py
Executable file → Normal file
|
|
@ -47,8 +47,6 @@ def datei(id):
|
||||||
|
|
||||||
return audio
|
return audio
|
||||||
|
|
||||||
with open("songs.json","r") as f:
|
|
||||||
songs = json.load(f)
|
|
||||||
def kartenGeneriren(song):
|
def kartenGeneriren(song):
|
||||||
id = song["wikiid"]
|
id = song["wikiid"]
|
||||||
statements = wikiapi(id,"statements")
|
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",[])))
|
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:
|
if "ytid" not in song and "P1651" in statements:
|
||||||
song["ytid"] = statements["P1651"][0]["value"]["content"]
|
song["ytid"] = statements["P1651"][0]["value"]["content"]
|
||||||
print(song)
|
|
||||||
if "ytid" in song:
|
if "ytid" in song:
|
||||||
song["datei"] = datei(song["ytid"])
|
song["datei"] = datei(song["ytid"])
|
||||||
song["img"] = f"http://img.youtube.com/vi/{ song["ytid"] }/sddefault.jpg"
|
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"
|
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:
|
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"
|
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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
@ -90,28 +86,67 @@ def zeit(sekunden):
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello_world():
|
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
|
gesamtLaenge = 0
|
||||||
for song in songs:
|
for song in songs:
|
||||||
gesamtLaenge += song["laenge"]
|
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")
|
@app.route("/suche")
|
||||||
def suche():
|
def suche():
|
||||||
such = request.args.get("suche")
|
such = request.args.get("suche")
|
||||||
|
liste = request.args.get("liste")
|
||||||
|
print("/suche")
|
||||||
|
print(liste)
|
||||||
if such is not None:
|
if such is not None:
|
||||||
ergebnisse = wikisuche(such)
|
ergebnisse = wikisuche(such)
|
||||||
else:
|
else:
|
||||||
ergebnisse = []
|
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"])
|
@app.route("/suche",methods=["POST"])
|
||||||
def suche_finden():
|
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")}
|
song = {"wikiid":request.form.get("id")}
|
||||||
kartenGeneriren(song)
|
kartenGeneriren(song)
|
||||||
songs.append(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)
|
json.dump(songs,f,indent=2,ensure_ascii=False)
|
||||||
return redirect("/",303)
|
return redirect("/?liste="+liste,303)
|
||||||
|
|
||||||
@app.route("/ADMIN")
|
@app.route("/ADMIN")
|
||||||
def admin():
|
def admin():
|
||||||
|
|
|
||||||
7
static/script.js
Executable file → Normal file
7
static/script.js
Executable file → Normal file
|
|
@ -1,6 +1,11 @@
|
||||||
const audios = document.querySelectorAll("audio")
|
const audios = document.querySelectorAll("audio")
|
||||||
|
|
||||||
for (const [index,audio] of audios.entries()){
|
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)
|
console.log(audios)
|
||||||
4
templates/index.html
Executable file → Normal file
4
templates/index.html
Executable file → Normal file
|
|
@ -47,8 +47,8 @@
|
||||||
</style>
|
</style>
|
||||||
<h1>ESC Playlist</h1>
|
<h1>ESC Playlist</h1>
|
||||||
<h2>2026</h2>
|
<h2>2026</h2>
|
||||||
<a href="/suche">Du willst ein weiteres Lied in der Playlist?</a>
|
<a href="/suche?liste={{liste}}">Du willst ein weiteres Lied in der Playlist?</a>
|
||||||
<p>Die Playlist ist insgesamt lang {{ gesamtLaenge | zeit }} und enthält {{ karten|length }} Lieder</p>
|
<p>Die Playlist {{liste}} ist insgesamt lang {{ gesamtLaenge | zeit }} und enthält {{ karten|length }} Lieder</p>
|
||||||
<div id = "flex-container">
|
<div id = "flex-container">
|
||||||
{% for karte in karten %}
|
{% for karte in karten %}
|
||||||
{% set karte_loop = loop %}
|
{% set karte_loop = loop %}
|
||||||
|
|
|
||||||
6
templates/karte.html
Executable file → Normal file
6
templates/karte.html
Executable file → Normal file
|
|
@ -1,11 +1,17 @@
|
||||||
<article>
|
<article>
|
||||||
<img src="{{ karte.img }}"/>
|
<img src="{{ karte.img }}"/>
|
||||||
|
{% if karte.ytid %}
|
||||||
<audio controls autoplay src="/static/{{karte.datei}}"></audio>
|
<audio controls autoplay src="/static/{{karte.datei}}"></audio>
|
||||||
|
{% endif %}
|
||||||
<h2>{{ karte.titel}}</h2>
|
<h2>{{ karte.titel}}</h2>
|
||||||
<p><b>Übersetzter Titel:</b>{{ karte.uetitel}}</p>
|
<p><b>Übersetzter Titel:</b>{{ karte.uetitel}}</p>
|
||||||
<p><b>Interpreten:</b>{{ karte.interprete}}</p>
|
<p><b>Interpreten:</b>{{ karte.interprete}}</p>
|
||||||
|
{% if karte.jahrgang %}
|
||||||
<p><b>Jahrgang:</b> {{ karte.jahrgang }}</p>
|
<p><b>Jahrgang:</b> {{ karte.jahrgang }}</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if karte.plazirung%}
|
||||||
<p><b>Plazirung:</b> {{ karte.plazirung }}</p>
|
<p><b>Plazirung:</b> {{ karte.plazirung }}</p>
|
||||||
|
{% endif %}
|
||||||
<p><b>Länge:</b> {{karte.laenge|zeit}}</p>
|
<p><b>Länge:</b> {{karte.laenge|zeit}}</p>
|
||||||
<p><b id = "kursive">Interesanter</b><b> Fakt:</b> {{ karte.interesanterfakt }}</p>
|
<p><b id = "kursive">Interesanter</b><b> Fakt:</b> {{ karte.interesanterfakt }}</p>
|
||||||
{% if karte.text %}
|
{% if karte.text %}
|
||||||
|
|
|
||||||
1
templates/neueliste.html
Normal file
1
templates/neueliste.html
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<form><input name="name" value={{name}} placeholder="Name der Playlist"></form>
|
||||||
6
templates/playlists.html
Normal file
6
templates/playlists.html
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<ul>
|
||||||
|
{% for list in lists %}
|
||||||
|
<li><a href="/?liste={{list}}">{{list}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
<a href="/neueliste">Lust auf was neues?</a>
|
||||||
7
templates/suche.html
Executable file → Normal file
7
templates/suche.html
Executable file → Normal file
|
|
@ -1,4 +1,7 @@
|
||||||
<form><input name="suche" placeholder="Suche" value="{{anfrage or ""}}"></form>
|
{% if liste == empty %}
|
||||||
|
<p>Du musst etwas in die Playlist Screiben</p>
|
||||||
|
{% endif %}
|
||||||
|
<form><input type="hidden" name="liste" value="{{liste}}"><input name="suche" placeholder="Suche" value="{{anfrage or ""}}"></form>
|
||||||
{% if ergebnisse %}
|
{% if ergebnisse %}
|
||||||
<form method="post"><ol>
|
<form method="post"><ol>
|
||||||
{% for ergebnis in ergebnisse %}
|
{% for ergebnis in ergebnisse %}
|
||||||
|
|
@ -6,7 +9,7 @@
|
||||||
{% endfor %}</ol></form>
|
{% endfor %}</ol></form>
|
||||||
|
|
||||||
{%elif anfrage%}
|
{%elif anfrage%}
|
||||||
<p>Leider gibt es diesen Eintrag nicht!</p>
|
<p>Leider gibt es den Eintrag {{anfrage}} nicht!</p>
|
||||||
{%endif%}
|
{%endif%}
|
||||||
|
|
||||||
<a href="/">Doch nicht?</a>
|
<a href="/">Doch nicht?</a>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue