feat: auto generate edits

This commit is contained in:
robin committed 2026-11-13 16:18:25 +01:00
1 parent d026cc5470
commit f3546408d2
4 files changed
+149 -42

No files matched your search

+52 -20
View File
@@ -3,13 +3,40 @@
{% block admin_title %}Kopie erstellen{% endblock %}
{% block admin_content %}
{{ song }}
<form class="form" id="form">
<label for="titel">Titel</label>
<input id="title" name="title" type="text" autocomplete="off" required autofocus>
<label for="mode">Modus</label>
<select id="mode" name="mode">
<option value="cbr">Konstant (CBR)</option>
<option value="vbr">Variabel (VBR)</option>
</select>
<label for="artist">Artist</label>
<input id="artist" name="artist" type="text" autocomplete="off">
<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>
@@ -18,8 +45,8 @@
<table>
<thead>
<th>ID</th>
<th>Bitrate</th>
<th>Abtastrate</th>
<th>Bitrate (bit/s)</th>
<th>Abtastrate (Hz)</th>
</thead>
<tbody>
<tr>
@@ -31,7 +58,7 @@
{% for e in song.edits %}
<tr>
<td>{{ e.id }}</td>
<td>{{ e.bitrate }} ({{ (e.bitrate / song.original.bitrate * 100) | round(1) }}%)</td>
<td>{{ e.bitrate }} ({{ (e.bitrate / song.original.bitrate * 100) | round(1) }}%) {{ e.get("mode", "cbr") | upper }}</td>
<td>{{ e.sampling_rate }} ({{ (e.sampling_rate / song.original.sampling_rate * 100) | round(1) }}%)</td>
</tr>
{% endfor %}
@@ -44,20 +71,25 @@
const form = document.getElementById("form");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const res = await fetch("/api/admin/add", {
method: "POST",
body: new FormData(form),
});
const result = await res.json();
console.log(result);
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 fileInput = document.getElementById("file");
const fileName = document.getElementById("file-name");
fileInput.addEventListener("change", () => {
fileName.textContent = fileInput.files.length
? fileInput.files[0].name
: "Keine Datei ausgewählt";
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>