Compare commits
8
Commits
cb050dbc44
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f754d8d8bf | ||
|
|
ffe20e8272 | ||
|
|
a9ccdca62c | ||
|
|
7ddb932a6c | ||
|
|
f3546408d2 | ||
|
|
d026cc5470 | ||
|
|
203bab6cf7 | ||
|
|
6595eed927 |
No files matched your search
+131
-9
@@ -2,19 +2,141 @@
|
||||
{
|
||||
"name": "Umsonst gelebt",
|
||||
"artist": "Jugend Chor",
|
||||
"id": "002",
|
||||
"original_name": "-",
|
||||
"original": {
|
||||
"filename": "m003.mp3",
|
||||
"sampling_rate": 44.1,
|
||||
"bitrate": 256
|
||||
"filename": "8101b201694b47fe88d3764e66d8894e.mp3",
|
||||
"sampling_rate": 44100,
|
||||
"bitrate": 256000,
|
||||
"size": 7037136
|
||||
},
|
||||
"edits": [
|
||||
{
|
||||
"filename": "m004.mp3",
|
||||
"sampling_rate": 22.1,
|
||||
"bitrate": 63
|
||||
"id": "55fa1a2bf70e4c3297e1c7070389276d",
|
||||
"filename": "55fa1a2bf70e4c3297e1c7070389276d.mp3",
|
||||
"mode": "vbr",
|
||||
"quality": 6,
|
||||
"bitrate": 65146,
|
||||
"sampling_rate": 22050,
|
||||
"size": 1780043
|
||||
},
|
||||
{
|
||||
"id": "05cc0367e7af4977ac1f79d816e9f164",
|
||||
"filename": "05cc0367e7af4977ac1f79d816e9f164.mp3",
|
||||
"mode": "cbr",
|
||||
"quality": null,
|
||||
"bitrate": 64000,
|
||||
"sampling_rate": 8000,
|
||||
"size": 1750133
|
||||
}
|
||||
]
|
||||
],
|
||||
"id": "001"
|
||||
},
|
||||
{
|
||||
"name": "Meinem Jesus will ich weihen",
|
||||
"artist": "Jungscharchor",
|
||||
"original": {
|
||||
"filename": "27894cac76974fb58fdeb5a8fa639605.mp3",
|
||||
"sampling_rate": 44100,
|
||||
"bitrate": 128000,
|
||||
"size": 1810393
|
||||
},
|
||||
"edits": [
|
||||
{
|
||||
"id": "2c06e685fb224f629d7a20d31ec5e6d9",
|
||||
"filename": "2c06e685fb224f629d7a20d31ec5e6d9.mp3",
|
||||
"mode": "vbr",
|
||||
"quality": 9,
|
||||
"bitrate": 30101,
|
||||
"sampling_rate": 22050,
|
||||
"size": 417068
|
||||
}
|
||||
],
|
||||
"id": "002"
|
||||
},
|
||||
{
|
||||
"name": "Ich glaube an Jesus",
|
||||
"artist": "Gruppe",
|
||||
"original": {
|
||||
"filename": "c9bf5b8afe124b949f09211359b8ff5b.mp3",
|
||||
"sampling_rate": 44100,
|
||||
"bitrate": 128000,
|
||||
"size": 3432051
|
||||
},
|
||||
"edits": [
|
||||
{
|
||||
"id": "52f737589f4b461eaf7b0a3273921613",
|
||||
"filename": "52f737589f4b461eaf7b0a3273921613.mp3",
|
||||
"mode": "vbr",
|
||||
"quality": 4,
|
||||
"bitrate": 55191,
|
||||
"sampling_rate": 22050,
|
||||
"size": 1465187
|
||||
}
|
||||
],
|
||||
"id": "003"
|
||||
},
|
||||
{
|
||||
"name": "Bin erlöst von aller Sünd",
|
||||
"artist": "Jungscharchor",
|
||||
"original": {
|
||||
"filename": "5a94207c76b343b8b802b6c2894c69fa.mp3",
|
||||
"sampling_rate": 44100,
|
||||
"bitrate": 128000,
|
||||
"size": 2686933
|
||||
},
|
||||
"edits": [
|
||||
{
|
||||
"id": "7822fb105be341c9b169ef7ace84aeb8",
|
||||
"filename": "7822fb105be341c9b169ef7ace84aeb8.mp3",
|
||||
"mode": "vbr",
|
||||
"quality": 9,
|
||||
"bitrate": 43628,
|
||||
"sampling_rate": 44100,
|
||||
"size": 903637
|
||||
}
|
||||
],
|
||||
"id": "004"
|
||||
},
|
||||
{
|
||||
"name": "Du bist nah mir wie das Meer dem Strande",
|
||||
"artist": "Jungscharlehrer",
|
||||
"original": {
|
||||
"filename": "380549bd1fb84a728d0068e42043f074.mp3",
|
||||
"sampling_rate": 44100,
|
||||
"bitrate": 128000,
|
||||
"size": 2466338
|
||||
},
|
||||
"edits": [
|
||||
{
|
||||
"id": "d6a8f772629b43ecb5a9b03a6dea010c",
|
||||
"filename": "d6a8f772629b43ecb5a9b03a6dea010c.mp3",
|
||||
"mode": "vbr",
|
||||
"quality": 2,
|
||||
"bitrate": 67476,
|
||||
"sampling_rate": 22050,
|
||||
"size": 1280972
|
||||
}
|
||||
],
|
||||
"id": "005"
|
||||
},
|
||||
{
|
||||
"name": "Zeugnis",
|
||||
"original": {
|
||||
"filename": "9a534ade55264c16a392c48dc14aedcc.mp3",
|
||||
"sampling_rate": 44100,
|
||||
"bitrate": 128000,
|
||||
"size": 12757866
|
||||
},
|
||||
"edits": [
|
||||
{
|
||||
"id": "fd6ed7f4a2c64a498ff64beaf19eacc2",
|
||||
"filename": "fd6ed7f4a2c64a498ff64beaf19eacc2.mp3",
|
||||
"mode": "cbr",
|
||||
"quality": null,
|
||||
"bitrate": 32000,
|
||||
"sampling_rate": 8000,
|
||||
"size": 3187229
|
||||
}
|
||||
],
|
||||
"id": "006"
|
||||
}
|
||||
]
|
||||
@@ -15,6 +15,7 @@ from db import init_db, get_db, close_db, create_participant, now
|
||||
from datetime import datetime, timezone
|
||||
import threading
|
||||
from mutagen import File
|
||||
import subprocess
|
||||
|
||||
bp = Blueprint("main", __name__)
|
||||
|
||||
@@ -322,11 +323,21 @@ def admin_list():
|
||||
songs = load_songs_list()
|
||||
return render_template("admin_tasksList.html", songs=songs)
|
||||
|
||||
@bp.route("/admin/add/<songId>")
|
||||
@admin_required
|
||||
def admin_add_task(songId):
|
||||
song = False
|
||||
for s in load_songs_list():
|
||||
if s["id"] == songId:
|
||||
song = s
|
||||
if not song:
|
||||
return 404
|
||||
return render_template("admin_add_task.html", song=song)
|
||||
|
||||
@bp.route("/api/admin/add", methods=["POST"])
|
||||
@admin_required
|
||||
def api_admin_add():
|
||||
title = request.form.get("title", "").strip()
|
||||
artist = request.form.get("artist", "").strip()
|
||||
file = request.files.get("file")
|
||||
|
||||
if not title:
|
||||
@@ -340,21 +351,97 @@ def api_admin_add():
|
||||
filename_new = uuid.uuid4().hex + ext
|
||||
|
||||
BASE_MUSIC_DIR.mkdir(parents=True, exist_ok=True)
|
||||
file.save(BASE_MUSIC_DIR / filename_new)
|
||||
path = BASE_MUSIC_DIR / filename_new
|
||||
file.save(path)
|
||||
|
||||
# read bitrate and sampling rate
|
||||
audio = File(BASE_MUSIC_DIR / filename_new)
|
||||
audio = File(path)
|
||||
|
||||
#stem = os.path.splitext(filename_new)[0]
|
||||
song = add_song({
|
||||
"name": title,
|
||||
"artist": artist,
|
||||
"original": {
|
||||
"filename": filename_new,
|
||||
"sampling_rate": audio.info.sample_rate,
|
||||
"bitrate": audio.info.bitrate
|
||||
"bitrate": audio.info.bitrate,
|
||||
"size": path.stat().st_size, # Bytes
|
||||
},
|
||||
"edits": [],
|
||||
})
|
||||
|
||||
return jsonify({"saved": True, "filename": filename_new})
|
||||
|
||||
VALID_SAMPLING_RATES = {8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000}
|
||||
|
||||
@bp.route("/api/admin/add/<songId>", methods=["POST"])
|
||||
@admin_required
|
||||
def api_admin_add_task(songId):
|
||||
mode = request.form.get("mode", "cbr")
|
||||
sampling_rate = request.form.get("sampling_rate", type=int)
|
||||
|
||||
if mode not in ("cbr", "vbr"):
|
||||
return jsonify({"saved": False, "error": "Ungültiger Modus"}), 400
|
||||
if sampling_rate not in VALID_SAMPLING_RATES:
|
||||
return jsonify({"saved": False, "error": "Ungültige Abtastrate"}), 400
|
||||
|
||||
songs = load_songs_list()
|
||||
song = next((s for s in songs if str(s["id"]) == songId), None)
|
||||
if song is None:
|
||||
return jsonify({"saved": False, "error": "Song nicht gefunden"}), 404
|
||||
|
||||
original = song["original"]
|
||||
if sampling_rate > original["sampling_rate"]:
|
||||
return jsonify({"saved": False, "error": "Abtastrate höher als Original"}), 400
|
||||
|
||||
if mode == "vbr":
|
||||
quality = request.form.get("quality", type=int)
|
||||
if quality is None or not 0 <= quality <= 9:
|
||||
return jsonify({"saved": False, "error": "Ungültige VBR-Qualität"}), 400
|
||||
quality_args = ["-q:a", str(quality)]
|
||||
else:
|
||||
bitrate_kbps = request.form.get("bitrate", type=int)
|
||||
if not bitrate_kbps or bitrate_kbps <= 0:
|
||||
return jsonify({"saved": False, "error": "Bitrate fehlt"}), 400
|
||||
if bitrate_kbps * 1000 > original["bitrate"] + 1000:
|
||||
return jsonify({"saved": False, "error": "Bitrate höher als Original"}), 400
|
||||
quality_args = ["-b:a", f"{bitrate_kbps}k"]
|
||||
|
||||
src = BASE_MUSIC_DIR / original["filename"]
|
||||
if not src.is_file():
|
||||
return jsonify({"saved": False, "error": "Originaldatei fehlt"}), 404
|
||||
|
||||
edit_id = uuid.uuid4().hex
|
||||
dst = BASE_MUSIC_DIR / (edit_id + ".mp3") # immer MP3, siehe Hinweis unten
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
["ffmpeg", "-y", "-i", str(src), "-vn",
|
||||
"-c:a", "libmp3lame", *quality_args,
|
||||
"-ar", str(sampling_rate), str(dst)],
|
||||
check=True, capture_output=True, timeout=300,
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
dst.unlink(missing_ok=True)
|
||||
current_app.logger.error("ffmpeg: %s", e.stderr.decode(errors="replace")[-1000:])
|
||||
return jsonify({"saved": False, "error": "Konvertierung fehlgeschlagen"}), 500
|
||||
except subprocess.TimeoutExpired:
|
||||
dst.unlink(missing_ok=True)
|
||||
return jsonify({"saved": False, "error": "Zeitüberschreitung"}), 500
|
||||
|
||||
# tatsächliche Werte aus der fertigen Datei lesen
|
||||
out = File(dst)
|
||||
actual_bitrate = out.info.bitrate if out else None
|
||||
actual_rate = out.info.sample_rate if out else sampling_rate
|
||||
|
||||
song.setdefault("edits", []).append({
|
||||
"id": edit_id,
|
||||
"filename": dst.name,
|
||||
"mode": mode,
|
||||
"quality": quality if mode == "vbr" else None,
|
||||
"bitrate": actual_bitrate,
|
||||
"sampling_rate": actual_rate,
|
||||
"size": dst.stat().st_size, # Bytes
|
||||
})
|
||||
save_songs_list(songs)
|
||||
|
||||
return jsonify({"saved": True, "id": edit_id})
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -176,3 +176,8 @@ td.toggle a {
|
||||
td.toggle a:hover {
|
||||
filter: brightness(1.1); /* optional: Hover-Effekt */
|
||||
}
|
||||
|
||||
.percentage {
|
||||
color: var(--muted);
|
||||
font-size: small;
|
||||
}
|
||||
@@ -7,9 +7,6 @@
|
||||
<label for="titel">Titel</label>
|
||||
<input id="title" name="title" type="text" autocomplete="off" required autofocus>
|
||||
|
||||
<label for="artist">Artist</label>
|
||||
<input id="artist" name="artist" type="text" autocomplete="off">
|
||||
|
||||
<label for="file">Datei</label>
|
||||
<div class="file-upload">
|
||||
<input id="file" name="file" type="file" accept="audio/*,.mp3,.wav,.flac,.ogg,.m4a" required>
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
{% extends "admin.html" %}
|
||||
|
||||
{% block admin_title %}Kopie erstellen{% endblock %}
|
||||
|
||||
{% block admin_content %}
|
||||
<form class="form" id="form">
|
||||
<label for="mode">Modus</label>
|
||||
<select id="mode" name="mode">
|
||||
<option value="cbr">Konstant (CBR)</option>
|
||||
<option value="vbr">Variabel (VBR)</option>
|
||||
</select>
|
||||
|
||||
<div id="cbr-field">
|
||||
<label for="bitrate">Bitrate (kbit/s)</label>
|
||||
<select id="bitrate" name="bitrate">
|
||||
{% for b in [32, 48, 64, 96, 128, 160, 192, 256, 320] if b * 1000 <= song.original.bitrate %}
|
||||
<option value="{{ b }}">{{ b }} kbit/s</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="vbr-field" hidden>
|
||||
<label for="quality">VBR-Qualität</label>
|
||||
<select id="quality" name="quality">
|
||||
<option value="0">V0 (beste, ca. 220–260 kbit/s)</option>
|
||||
<option value="2">V2 (ca. 170–210 kbit/s)</option>
|
||||
<option value="4">V4 (ca. 140–185 kbit/s)</option>
|
||||
<option value="6">V6 (ca. 100–130 kbit/s)</option>
|
||||
<option value="8">V8 (ca. 70–105 kbit/s)</option>
|
||||
<option value="9">V9 (schlechteste, ca. 65–85 kbit/s)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<label for="sampling_rate">Abtastrate (Hz)</label>
|
||||
<select id="sampling_rate" name="sampling_rate" required>
|
||||
{% for r in [8000, 11025, 16000, 22050, 32000, 44100, 48000] if r <= song.original.sampling_rate %}
|
||||
<option value="{{ r }}" {% if r == song.original.sampling_rate %}selected{% endif %}>{{ r }} Hz</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<button type="submit">Erstellen</button>
|
||||
</form>
|
||||
|
||||
<div class="table-wrap" style="margin-top: 2rem;">
|
||||
<table>
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>Bitrate (bit/s)</th>
|
||||
<th>Abtastrate (Hz)</th>
|
||||
<th>Dateigröße (MB)</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Original</td>
|
||||
<td>{{ song.original.bitrate }}</td>
|
||||
<td>{{ song.original.sampling_rate }}</td>
|
||||
<td>{{ (song.original.size / 1000000) | round(2) }}</td>
|
||||
</tr>
|
||||
{% if song.edits %}
|
||||
{% for e in song.edits %}
|
||||
<tr>
|
||||
<td>{{ e.id }}</td>
|
||||
<td>{{ e.bitrate }} <span class="percentage">({{ (e.bitrate / song.original.bitrate * 100) | round(1) }}%) {{ e.get("mode", "cbr") | upper }}</span></td>
|
||||
<td>{{ e.sampling_rate }} <span class="percentage">({{ (e.sampling_rate / song.original.sampling_rate * 100) | round(1) }}%)</span></td>
|
||||
<td>{{ (e.size / 1000000) | round(2) }} <span class="percentage">({{ (e.size / song.original.size * 100) | round(1) }}%)</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const form = document.getElementById("form");
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const button = form.querySelector("button");
|
||||
button.disabled = true; // Doppelklick verhindern
|
||||
try {
|
||||
const res = await fetch("/api/admin/add/{{ song.id }}", {
|
||||
method: "POST",
|
||||
body: new FormData(form),
|
||||
});
|
||||
if (!res.ok) throw new Error("Fehler " + res.status);
|
||||
location.reload(); // Tabelle aktualisieren
|
||||
} catch (err) {
|
||||
alert("Erstellen fehlgeschlagen: " + err.message);
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
const mode = document.getElementById("mode");
|
||||
mode.addEventListener("change", () => {
|
||||
document.getElementById("cbr-field").hidden = mode.value !== "cbr";
|
||||
document.getElementById("vbr-field").hidden = mode.value !== "vbr";
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
@@ -16,22 +16,22 @@
|
||||
<thead>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Artist</th>
|
||||
<th>ID</th>
|
||||
<th>Bitrate</th>
|
||||
<th>Abtastrate</th>
|
||||
<th>Bitrate (bit/s)</th>
|
||||
<th>Abtastrate (Hz)</th>
|
||||
<th>Dateigröße (MB)</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for s in songs %}
|
||||
<tr>
|
||||
<td class="toggle">
|
||||
<a>+</a>
|
||||
<a href="{{ url_for('main.admin_add_task', songId=s.id) }}">+</a>
|
||||
</td>
|
||||
<td>{{ s.name }}</td>
|
||||
<td>{{ s.artist }}</td>
|
||||
<td>{{ s.id }}</td>
|
||||
<td>{{ s.original.bitrate }}</td>
|
||||
<td>{{ s.original.sampling_rate }}</td>
|
||||
<td>{{ (s.original.size / 1000000) | round(2) }}</td>
|
||||
</tr>
|
||||
{% if s.edits %}
|
||||
{% for e in s.edits %}
|
||||
@@ -39,9 +39,9 @@
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ e.bitrate }} ({{ (e.bitrate / s.original.bitrate * 100) | round(1) }}%)</td>
|
||||
<td>{{ e.sampling_rate }} ({{ (e.sampling_rate / s.original.sampling_rate * 100) | round(1) }}%)</td>
|
||||
<td>{{ e.bitrate }} <span class="percentage">({{ (e.bitrate / s.original.bitrate * 100) | round(1) }}%)</span></td>
|
||||
<td>{{ e.sampling_rate }} <span class="percentage">({{ (e.sampling_rate / s.original.sampling_rate * 100) | round(1) }}%)</span></td>
|
||||
<td>{{ (e.size / 1000000) | round(2) }} <span class="percentage">({{ (e.size / s.original.size * 100) | round(1) }}%)</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -132,6 +132,7 @@ form.addEventListener("submit", async (e) => {
|
||||
if (data.solution.truth !== false) {
|
||||
if (data.solution.truth === data.solution.choice) {
|
||||
result_div.classList.add("right");
|
||||
result_div.classList.remove("wrong");
|
||||
result_title.innerHTML = "Richtig";
|
||||
result_content.innerHTML = "Du hast richtig gehört!";
|
||||
console.log("Richtig [debug]");
|
||||
@@ -139,6 +140,7 @@ form.addEventListener("submit", async (e) => {
|
||||
result_title.innerHTML = "Falsch";
|
||||
result_content.innerHTML = "Du hast falsch gehört!";
|
||||
result_div.classList.add("wrong");
|
||||
result_div.classList.remove("right");
|
||||
console.log("Falsch [debug]");
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user