Add files via upload
This commit is contained in:
parent
07f2ed525b
commit
6e7f0c1505
37 changed files with 4084 additions and 20 deletions
353
app/static/css/style.css
Normal file
353
app/static/css/style.css
Normal file
|
|
@ -0,0 +1,353 @@
|
|||
:root {
|
||||
--bg: #0a0a0d;
|
||||
--grid-line: rgba(255, 255, 255, 0.035);
|
||||
--surface: #131317;
|
||||
--surface-2: #1a1a20;
|
||||
--border: rgba(255, 255, 255, 0.08);
|
||||
--text: #e8e8ec;
|
||||
--text-dim: #8b8b96;
|
||||
--accent: #5d8aef;
|
||||
--accent-dim: rgba(93, 138, 239, 0.14);
|
||||
--error: #ff6b6b;
|
||||
--radius: 10px;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: var(--bg);
|
||||
background-image:
|
||||
linear-gradient(var(--grid-line) 1px, transparent 1px),
|
||||
linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
|
||||
background-size: 32px 32px;
|
||||
color: var(--text);
|
||||
font-family: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
body {
|
||||
opacity: 0;
|
||||
transition: opacity .4s ease;
|
||||
}
|
||||
body.loaded { opacity: 1; }
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 22px 36px;
|
||||
}
|
||||
|
||||
.brand {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.brand-accent { color: var(--accent); }
|
||||
|
||||
.gh-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 50%;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-dim);
|
||||
text-decoration: none;
|
||||
transition: color .15s, border-color .15s;
|
||||
}
|
||||
.gh-btn:hover { color: var(--text); border-color: var(--accent); }
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 22px;
|
||||
padding: 0 36px;
|
||||
margin-bottom: 28px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-bottom: 2px solid transparent;
|
||||
color: var(--text-dim);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
padding: 10px 2px 12px;
|
||||
margin-bottom: -1px;
|
||||
cursor: pointer;
|
||||
transition: color .15s, border-color .15s;
|
||||
}
|
||||
.tab-btn:hover { color: var(--text); }
|
||||
.tab-btn.active { color: var(--text); border-color: var(--accent); }
|
||||
|
||||
main {
|
||||
max-width: 880px;
|
||||
margin: 0 auto;
|
||||
padding: 0 24px 80px;
|
||||
}
|
||||
|
||||
.tab-panel { display: none; flex-direction: column; gap: 20px; }
|
||||
.tab-panel.active { display: flex; }
|
||||
.tab-panel.fade-out { opacity: 0; transform: translateY(5px); transition: opacity .18s ease, transform .18s ease; }
|
||||
.tab-panel.fade-in { animation: fadeInUp .38s cubic-bezier(.16,.8,.24,1); }
|
||||
|
||||
@keyframes fadeInUp {
|
||||
from { opacity: 0; transform: translateY(10px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 24px;
|
||||
transition: border-color .25s ease, transform .25s ease, box-shadow .25s ease;
|
||||
}
|
||||
.card:hover { border-color: rgba(255, 255, 255, 0.14); }
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.card-header h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-dim); }
|
||||
|
||||
.mode-switch {
|
||||
display: inline-flex;
|
||||
background: var(--surface-2);
|
||||
border-radius: 999px;
|
||||
padding: 3px;
|
||||
margin-bottom: 18px;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.mode-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
padding: 7px 16px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
transition: background .2s cubic-bezier(.2,.7,.3,1), color .2s ease, transform .1s ease;
|
||||
}
|
||||
.mode-btn:active { transform: scale(.94); }
|
||||
.mode-btn.active { background: var(--accent); color: var(--bg); }
|
||||
|
||||
.mode-panel { display: none; }
|
||||
.mode-panel.active { display: block; }
|
||||
|
||||
.big-input, input[type=text], input:not([type]) {
|
||||
width: 100%;
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
font-size: 15px;
|
||||
padding: 14px 18px;
|
||||
border-radius: 999px;
|
||||
outline: none;
|
||||
margin-bottom: 12px;
|
||||
transition: border-color .2s ease, box-shadow .2s ease;
|
||||
}
|
||||
.big-input:focus, input:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px var(--accent-dim);
|
||||
}
|
||||
|
||||
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
|
||||
.row input { margin-bottom: 0; flex: 1; min-width: 120px; }
|
||||
|
||||
select {
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
font-size: 14px;
|
||||
padding: 12px 14px;
|
||||
border-radius: 10px;
|
||||
outline: none;
|
||||
transition: border-color .2s ease, box-shadow .2s ease;
|
||||
}
|
||||
select:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px var(--accent-dim);
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: var(--accent);
|
||||
color: #05070f;
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
padding: 12px 22px;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
transition: opacity .15s, transform .1s ease;
|
||||
}
|
||||
.primary-btn:hover { opacity: .88; }
|
||||
.primary-btn:active { transform: scale(.96); }
|
||||
.primary-btn:disabled { opacity: .4; cursor: not-allowed; }
|
||||
|
||||
.ghost-btn {
|
||||
background: transparent;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
padding: 10px 16px;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
transition: color .15s ease, border-color .15s ease, transform .1s ease;
|
||||
}
|
||||
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }
|
||||
.ghost-btn:active { transform: scale(.96); }
|
||||
|
||||
.file-btn { display: inline-flex; cursor: pointer; }
|
||||
|
||||
.progress-box { margin-top: 18px; }
|
||||
.progress-box.hidden { display: none; }
|
||||
.progress-track {
|
||||
height: 6px;
|
||||
background: var(--surface-2);
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
width: 0%;
|
||||
background: var(--accent);
|
||||
transition: width .3s cubic-bezier(.2,.7,.3,1);
|
||||
box-shadow: 0 0 10px 0 var(--accent-dim);
|
||||
}
|
||||
.progress-text { font-size: 13px; color: var(--text-dim); margin-top: 8px; transition: opacity .15s ease; }
|
||||
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.result-card {
|
||||
animation: fadeInUp .3s cubic-bezier(.2,.7,.3,1) backwards;
|
||||
transition: border-color .15s ease, transform .15s ease;
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
.result-card img {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 8px;
|
||||
object-fit: cover;
|
||||
background: #222;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.result-card .meta { flex: 1; min-width: 0; }
|
||||
.result-card .title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.result-card .artist { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.result-card:hover { border-color: var(--accent); }
|
||||
.result-card .dl-btn {
|
||||
background: var(--accent-dim);
|
||||
color: var(--accent);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 8px 10px;
|
||||
transition: transform .1s ease, background .15s ease;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.result-card .dl-btn:active { transform: scale(.92); }
|
||||
|
||||
.drop-zone {
|
||||
border: 2px dashed var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 48px 20px;
|
||||
text-align: center;
|
||||
transition: border-color .2s ease, background .2s ease, transform .15s ease;
|
||||
}
|
||||
.drop-zone.dragover { border-color: var(--accent); background: var(--accent-dim); transform: scale(1.01); }
|
||||
.drop-zone p { color: var(--text-dim); margin: 8px 0; }
|
||||
.drop-zone .hint { font-size: 12px; }
|
||||
|
||||
.conv-result { margin-top: 20px; }
|
||||
.conv-result.hidden { display: none; }
|
||||
#conv-file-info { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
|
||||
#conv-output { margin-top: 14px; font-size: 14px; }
|
||||
#conv-output a { color: var(--accent); }
|
||||
|
||||
.meta-form { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
|
||||
.meta-form.hidden { display: none; }
|
||||
.meta-cover-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
|
||||
.cover-preview {
|
||||
width: 72px; height: 72px;
|
||||
border-radius: 10px;
|
||||
object-fit: cover;
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.batch-list { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
|
||||
.batch-item { font-size: 13px; color: var(--text-dim); display: flex; justify-content: space-between; }
|
||||
.batch-item .ok { color: #6ee7a8; }
|
||||
.batch-item .err { color: var(--error); }
|
||||
|
||||
.script-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 12px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.script-grid textarea {
|
||||
width: 100%;
|
||||
height: 340px;
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
font-family: "Cascadia Code", Consolas, monospace;
|
||||
font-size: 13px;
|
||||
padding: 14px;
|
||||
border-radius: 10px;
|
||||
resize: vertical;
|
||||
outline: none;
|
||||
}
|
||||
.script-grid textarea:focus { border-color: var(--accent); }
|
||||
.script-error {
|
||||
margin-top: 10px;
|
||||
color: var(--error);
|
||||
font-size: 13px;
|
||||
font-family: Consolas, monospace;
|
||||
}
|
||||
.script-error.hidden { display: none; }
|
||||
|
||||
.hidden { display: none !important; }
|
||||
|
||||
.footer {
|
||||
position: fixed;
|
||||
bottom: 14px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.18);
|
||||
pointer-events: none;
|
||||
letter-spacing: .02em;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.script-grid { grid-template-columns: 1fr; }
|
||||
.topbar { padding: 18px 20px; }
|
||||
.tabs { padding: 0 12px; overflow-x: auto; }
|
||||
}
|
||||
BIN
app/static/img/favicon.ico
Normal file
BIN
app/static/img/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
BIN
app/static/img/icon.png
Normal file
BIN
app/static/img/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
467
app/static/js/app.js
Normal file
467
app/static/js/app.js
Normal file
|
|
@ -0,0 +1,467 @@
|
|||
requestAnimationFrame(() => document.body.classList.add("loaded"));
|
||||
|
||||
// --- tabs ---
|
||||
function crossfade(fromPanel, toPanel) {
|
||||
if (fromPanel === toPanel) return;
|
||||
if (fromPanel) {
|
||||
fromPanel.classList.add("fade-out");
|
||||
setTimeout(() => {
|
||||
fromPanel.classList.remove("active", "fade-out");
|
||||
}, 170);
|
||||
}
|
||||
setTimeout(() => {
|
||||
toPanel.classList.add("active", "fade-in");
|
||||
setTimeout(() => toPanel.classList.remove("fade-in"), 380);
|
||||
}, fromPanel ? 140 : 0);
|
||||
}
|
||||
|
||||
document.querySelectorAll(".tab-btn").forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
if (btn.classList.contains("active")) return;
|
||||
document.querySelectorAll(".tab-btn").forEach((b) => b.classList.remove("active"));
|
||||
btn.classList.add("active");
|
||||
const current = document.querySelector(".tab-panel.active");
|
||||
const next = document.getElementById(`tab-${btn.dataset.tab}`);
|
||||
crossfade(current, next);
|
||||
});
|
||||
});
|
||||
|
||||
function switchMode(switchEl, panelPrefix, attr) {
|
||||
switchEl.querySelectorAll(".mode-btn").forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
if (btn.classList.contains("active")) return;
|
||||
switchEl.querySelectorAll(".mode-btn").forEach((b) => b.classList.remove("active"));
|
||||
btn.classList.add("active");
|
||||
const val = btn.dataset[attr];
|
||||
const current = switchEl.parentElement.querySelector(".mode-panel.active");
|
||||
const next = document.getElementById(`${panelPrefix}-${val}`);
|
||||
crossfade(current, next);
|
||||
return val;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll(".mode-switch").forEach((sw) => {
|
||||
if (sw.querySelector("[data-mode]")) switchMode(sw, "mode", "mode");
|
||||
if (sw.querySelector("[data-meta-mode]")) switchMode(sw, "meta", "metaMode");
|
||||
});
|
||||
|
||||
// =================== DOWNLOADER ===================
|
||||
|
||||
const dlUrl = document.getElementById("dl-url");
|
||||
const dlFormat = document.getElementById("dl-format");
|
||||
const dlQuality = document.getElementById("dl-quality");
|
||||
const dlGo = document.getElementById("dl-go");
|
||||
const dlProgress = document.getElementById("dl-progress");
|
||||
const dlProgressBar = document.getElementById("dl-progress-bar");
|
||||
const dlProgressText = document.getElementById("dl-progress-text");
|
||||
|
||||
const AUDIO_QUALITIES = [
|
||||
["320", "320 kbps"],
|
||||
["256", "256 kbps"],
|
||||
["192", "192 kbps"],
|
||||
["128", "128 kbps"],
|
||||
];
|
||||
const VIDEO_QUALITIES = [
|
||||
["best", "лучшее"],
|
||||
["2160", "2160p (4K)"],
|
||||
["1440", "1440p"],
|
||||
["1080", "1080p"],
|
||||
["720", "720p"],
|
||||
["480", "480p"],
|
||||
["360", "360p"],
|
||||
];
|
||||
|
||||
function refreshQualityOptions() {
|
||||
const isVideo = dlFormat.value === "mp4";
|
||||
const list = isVideo ? VIDEO_QUALITIES : AUDIO_QUALITIES;
|
||||
dlQuality.innerHTML = list.map(([v, label]) => `<option value="${v}">${label}</option>`).join("");
|
||||
}
|
||||
dlFormat.addEventListener("change", refreshQualityOptions);
|
||||
refreshQualityOptions();
|
||||
|
||||
function startDownload(url, fmt, quality) {
|
||||
dlProgress.classList.remove("hidden");
|
||||
dlProgressBar.style.width = "0%";
|
||||
dlProgressText.textContent = "запускаю...";
|
||||
|
||||
fetch("/api/download", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ url, format: fmt, quality }),
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
if (data.error) {
|
||||
dlProgressText.textContent = "ошибка: " + data.error;
|
||||
return;
|
||||
}
|
||||
pollJob(data.job_id);
|
||||
})
|
||||
.catch((e) => (dlProgressText.textContent = "ошибка: " + e));
|
||||
}
|
||||
|
||||
function pollJob(jobId) {
|
||||
const iv = setInterval(() => {
|
||||
fetch(`/api/job/${jobId}`)
|
||||
.then((r) => r.json())
|
||||
.then((job) => {
|
||||
if (job.error) {
|
||||
clearInterval(iv);
|
||||
dlProgressText.textContent = "ошибка: " + job.error;
|
||||
return;
|
||||
}
|
||||
dlProgressBar.style.width = (job.progress || 0) + "%";
|
||||
|
||||
if (job.status === "downloading") {
|
||||
dlProgressText.textContent = `скачиваю... ${job.progress || 0}% ${job.speed || ""}`;
|
||||
} else if (job.status === "processing") {
|
||||
dlProgressText.textContent = "обрабатываю...";
|
||||
} else if (job.status === "done") {
|
||||
clearInterval(iv);
|
||||
dlProgressText.textContent = "готово ✓";
|
||||
loadHistory();
|
||||
} else if (job.status === "error") {
|
||||
clearInterval(iv);
|
||||
dlProgressText.textContent = "ошибка: " + job.error;
|
||||
}
|
||||
})
|
||||
.catch(() => clearInterval(iv));
|
||||
}, 800);
|
||||
}
|
||||
|
||||
dlGo.addEventListener("click", () => {
|
||||
const url = dlUrl.value.trim();
|
||||
if (!url) return;
|
||||
startDownload(url, dlFormat.value, dlQuality.value);
|
||||
});
|
||||
|
||||
// --- search ---
|
||||
|
||||
const searchQ = document.getElementById("search-q");
|
||||
const searchPlatform = document.getElementById("search-platform");
|
||||
const searchGo = document.getElementById("search-go");
|
||||
const searchResults = document.getElementById("search-results");
|
||||
|
||||
function renderResultCard(item, delayIndex = 0) {
|
||||
const div = document.createElement("div");
|
||||
div.className = "result-card";
|
||||
div.style.animationDelay = `${Math.min(delayIndex * 35, 300)}ms`;
|
||||
div.innerHTML = `
|
||||
<img src="${item.cover_url || ""}" onerror="this.style.opacity=0">
|
||||
<div class="meta">
|
||||
<div class="title">${escapeHtml(item.title)}</div>
|
||||
<div class="artist">${escapeHtml(item.artist)} ${item.duration ? "· " + item.duration : ""}</div>
|
||||
</div>
|
||||
<button class="dl-btn">скачать</button>
|
||||
`;
|
||||
div.querySelector(".dl-btn").addEventListener("click", () => {
|
||||
startDownload(item.url, dlFormat.value, dlQuality.value);
|
||||
});
|
||||
return div;
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
const d = document.createElement("div");
|
||||
d.textContent = s || "";
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
searchGo.addEventListener("click", () => {
|
||||
const q = searchQ.value.trim();
|
||||
if (!q) return;
|
||||
searchResults.innerHTML = '<div class="progress-text">ищу...</div>';
|
||||
fetch(`/api/search?platform=${searchPlatform.value}&q=${encodeURIComponent(q)}`)
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
searchResults.innerHTML = "";
|
||||
if (data.error || !data.results || !data.results.length) {
|
||||
searchResults.innerHTML = '<div class="progress-text">ничего не найдено</div>';
|
||||
return;
|
||||
}
|
||||
data.results.forEach((item, i) => searchResults.appendChild(renderResultCard(item, i)));
|
||||
});
|
||||
});
|
||||
|
||||
// --- history ---
|
||||
|
||||
const historyList = document.getElementById("history-list");
|
||||
|
||||
function loadHistory() {
|
||||
fetch("/api/history")
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
historyList.innerHTML = "";
|
||||
(data.history || []).forEach((item, i) => {
|
||||
const div = document.createElement("div");
|
||||
div.className = "result-card";
|
||||
div.style.animationDelay = `${Math.min(i * 35, 300)}ms`;
|
||||
div.innerHTML = `
|
||||
<img src="${item.cover_url || ""}" onerror="this.style.opacity=0">
|
||||
<div class="meta">
|
||||
<div class="title">${escapeHtml(item.title)}</div>
|
||||
<div class="artist">${escapeHtml(item.artist)} · ${item.format.toUpperCase()}</div>
|
||||
</div>
|
||||
`;
|
||||
historyList.appendChild(div);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById("history-clear").addEventListener("click", () => {
|
||||
fetch("/api/history/clear", { method: "POST" }).then(loadHistory);
|
||||
});
|
||||
|
||||
loadHistory();
|
||||
|
||||
// =================== CONVERTER ===================
|
||||
|
||||
const dropZone = document.getElementById("drop-zone");
|
||||
const convFile = document.getElementById("conv-file");
|
||||
const convResult = document.getElementById("conv-result");
|
||||
const convFileInfo = document.getElementById("conv-file-info");
|
||||
const convTarget = document.getElementById("conv-target");
|
||||
const convGo = document.getElementById("conv-go");
|
||||
const convOutput = document.getElementById("conv-output");
|
||||
|
||||
let currentUpload = null;
|
||||
|
||||
["dragover", "dragenter"].forEach((ev) =>
|
||||
dropZone.addEventListener(ev, (e) => {
|
||||
e.preventDefault();
|
||||
dropZone.classList.add("dragover");
|
||||
})
|
||||
);
|
||||
["dragleave", "drop"].forEach((ev) =>
|
||||
dropZone.addEventListener(ev, (e) => {
|
||||
e.preventDefault();
|
||||
dropZone.classList.remove("dragover");
|
||||
})
|
||||
);
|
||||
dropZone.addEventListener("drop", (e) => {
|
||||
const file = e.dataTransfer.files[0];
|
||||
if (file) uploadForConvert(file);
|
||||
});
|
||||
convFile.addEventListener("change", () => {
|
||||
if (convFile.files[0]) uploadForConvert(convFile.files[0]);
|
||||
});
|
||||
|
||||
function uploadForConvert(file) {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
convOutput.innerHTML = "";
|
||||
fetch("/api/convert/upload", { method: "POST", body: fd })
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
if (data.error) {
|
||||
convFileInfo.textContent = "ошибка: " + data.error;
|
||||
convResult.classList.remove("hidden");
|
||||
return;
|
||||
}
|
||||
currentUpload = data;
|
||||
convFileInfo.textContent = `${data.filename} · ${(data.size / 1024).toFixed(1)} KB · тип: ${data.type}`;
|
||||
convTarget.innerHTML = data.targets.map((t) => `<option value="${t}">${t.toUpperCase()}</option>`).join("");
|
||||
convResult.classList.remove("hidden");
|
||||
});
|
||||
}
|
||||
|
||||
convGo.addEventListener("click", () => {
|
||||
if (!currentUpload) return;
|
||||
convOutput.textContent = "конвертирую...";
|
||||
fetch("/api/convert/run", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
id: currentUpload.id,
|
||||
saved: currentUpload.saved,
|
||||
filename: currentUpload.filename,
|
||||
target: convTarget.value,
|
||||
}),
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
if (data.error) {
|
||||
convOutput.textContent = "ошибка: " + data.error;
|
||||
return;
|
||||
}
|
||||
convOutput.innerHTML = `<a href="/api/convert/download/${data.result}" download="${data.filename}">скачать ${data.filename}</a>`;
|
||||
});
|
||||
});
|
||||
|
||||
// =================== METADATA ===================
|
||||
|
||||
const metaFile = document.getElementById("meta-file");
|
||||
const metaForm = document.getElementById("meta-form");
|
||||
const metaCoverPreview = document.getElementById("meta-cover-preview");
|
||||
const metaCoverInput = document.getElementById("meta-cover-input");
|
||||
const metaTitle = document.getElementById("meta-title");
|
||||
const metaArtist = document.getElementById("meta-artist");
|
||||
const metaAlbum = document.getElementById("meta-album");
|
||||
const metaYear = document.getElementById("meta-year");
|
||||
const metaTrack = document.getElementById("meta-track");
|
||||
const metaSave = document.getElementById("meta-save");
|
||||
const metaSaveResult = document.getElementById("meta-save-result");
|
||||
|
||||
let currentMetaFile = null;
|
||||
let newCoverFile = null;
|
||||
|
||||
metaFile.addEventListener("change", () => {
|
||||
const file = metaFile.files[0];
|
||||
if (!file) return;
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
fetch("/api/metadata/upload", { method: "POST", body: fd })
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
if (data.error) {
|
||||
alert(data.error);
|
||||
return;
|
||||
}
|
||||
currentMetaFile = data;
|
||||
newCoverFile = null;
|
||||
metaTitle.value = data.tags.title || "";
|
||||
metaArtist.value = data.tags.artist || "";
|
||||
metaAlbum.value = data.tags.album || "";
|
||||
metaYear.value = data.tags.year || "";
|
||||
metaTrack.value = data.tags.track_number || "";
|
||||
metaCoverPreview.src = data.tags.has_cover ? `/api/metadata/cover/${data.saved}?t=${Date.now()}` : "";
|
||||
metaForm.classList.remove("hidden");
|
||||
metaSaveResult.textContent = "";
|
||||
});
|
||||
});
|
||||
|
||||
metaCoverInput.addEventListener("change", () => {
|
||||
const file = metaCoverInput.files[0];
|
||||
if (!file) return;
|
||||
newCoverFile = file;
|
||||
metaCoverPreview.src = URL.createObjectURL(file);
|
||||
});
|
||||
|
||||
metaSave.addEventListener("click", () => {
|
||||
if (!currentMetaFile) return;
|
||||
const fd = new FormData();
|
||||
fd.append("saved", currentMetaFile.saved);
|
||||
fd.append("title", metaTitle.value);
|
||||
fd.append("artist", metaArtist.value);
|
||||
fd.append("album", metaAlbum.value);
|
||||
fd.append("year", metaYear.value);
|
||||
fd.append("track_number", metaTrack.value);
|
||||
if (newCoverFile) fd.append("cover", newCoverFile);
|
||||
|
||||
fetch("/api/metadata/save", { method: "POST", body: fd })
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
if (data.error) {
|
||||
metaSaveResult.textContent = "ошибка: " + data.error;
|
||||
return;
|
||||
}
|
||||
metaSaveResult.innerHTML = `сохранено — <a href="/api/metadata/download/${data.download}" download>скачать</a>`;
|
||||
});
|
||||
});
|
||||
|
||||
// --- batch ---
|
||||
|
||||
const metaBatchFiles = document.getElementById("meta-batch-files");
|
||||
const metaBatchList = document.getElementById("meta-batch-list");
|
||||
const metaBatchForm = document.getElementById("meta-batch-form");
|
||||
const metaBatchCoverPreview = document.getElementById("meta-batch-cover-preview");
|
||||
const metaBatchCoverInput = document.getElementById("meta-batch-cover-input");
|
||||
const metaBatchArtist = document.getElementById("meta-batch-artist");
|
||||
const metaBatchAlbum = document.getElementById("meta-batch-album");
|
||||
const metaBatchYear = document.getElementById("meta-batch-year");
|
||||
const metaBatchSave = document.getElementById("meta-batch-save");
|
||||
const metaBatchResult = document.getElementById("meta-batch-result");
|
||||
|
||||
let batchUploads = [];
|
||||
let batchCoverSaved = null;
|
||||
|
||||
metaBatchFiles.addEventListener("change", async () => {
|
||||
batchUploads = [];
|
||||
metaBatchList.innerHTML = "";
|
||||
for (const file of metaBatchFiles.files) {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
const res = await fetch("/api/metadata/upload", { method: "POST", body: fd }).then((r) => r.json());
|
||||
if (!res.error) {
|
||||
batchUploads.push(res);
|
||||
const div = document.createElement("div");
|
||||
div.className = "batch-item";
|
||||
div.innerHTML = `<span>${escapeHtml(file.name)}</span><span class="ok">загружен</span>`;
|
||||
metaBatchList.appendChild(div);
|
||||
}
|
||||
}
|
||||
if (batchUploads.length) metaBatchForm.classList.remove("hidden");
|
||||
});
|
||||
|
||||
metaBatchCoverInput.addEventListener("change", async () => {
|
||||
const file = metaBatchCoverInput.files[0];
|
||||
if (!file) return;
|
||||
metaBatchCoverPreview.src = URL.createObjectURL(file);
|
||||
const fd = new FormData();
|
||||
fd.append("file", file, "cover.jpg");
|
||||
// reuse the audio upload-like storage isn't right for images; store cover directly via convert upload endpoint instead
|
||||
const res = await fetch("/api/convert/upload", { method: "POST", body: fd }).then((r) => r.json());
|
||||
if (!res.error) batchCoverSaved = res.saved;
|
||||
});
|
||||
|
||||
metaBatchSave.addEventListener("click", () => {
|
||||
fetch("/api/metadata/batch", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
saved_files: batchUploads.map((u) => u.saved),
|
||||
artist: metaBatchArtist.value,
|
||||
album: metaBatchAlbum.value,
|
||||
year: metaBatchYear.value,
|
||||
cover_saved: batchCoverSaved,
|
||||
}),
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
metaBatchResult.innerHTML = `обновлено: ${data.updated.length}` + (data.errors.length ? `, ошибок: ${data.errors.length}` : "");
|
||||
});
|
||||
});
|
||||
|
||||
// =================== SCRIPTS ===================
|
||||
|
||||
const scriptInput = document.getElementById("script-input");
|
||||
const scriptOutput = document.getElementById("script-output");
|
||||
const scriptFormat = document.getElementById("script-format");
|
||||
const scriptDownload = document.getElementById("script-download");
|
||||
const scriptError = document.getElementById("script-error");
|
||||
let currentLang = "python";
|
||||
|
||||
document.querySelectorAll("[data-lang]").forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
currentLang = btn.dataset.lang;
|
||||
});
|
||||
});
|
||||
|
||||
scriptFormat.addEventListener("click", () => {
|
||||
scriptError.classList.add("hidden");
|
||||
fetch("/api/scripts/format", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ code: scriptInput.value, language: currentLang }),
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
scriptOutput.value = data.formatted || "";
|
||||
if (!data.ok) {
|
||||
scriptError.textContent = (data.line ? `строка ${data.line}: ` : "") + data.error;
|
||||
scriptError.classList.remove("hidden");
|
||||
scriptDownload.disabled = true;
|
||||
} else {
|
||||
scriptDownload.disabled = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
scriptDownload.addEventListener("click", () => {
|
||||
const ext = currentLang === "python" ? "py" : "lua";
|
||||
const blob = new Blob([scriptOutput.value], { type: "text/plain" });
|
||||
const a = document.createElement("a");
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `formatted.${ext}`;
|
||||
a.click();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue