feat(player): add explicit detection, inline audio preview, seeking scrubber, and stream endpoint

This commit is contained in:
Antigravity committed 2026-10-12 14:03:57 +03:00
1 parent 49bd123a03
commit 30ba67c707
5 files changed
+382 -20

No files matched your search

+90 -15
View File
@@ -69,23 +69,39 @@ document.addEventListener("DOMContentLoaded", () => {
if (tracks.length === 0) {
searchTracksList.innerHTML = `<p class="empty-state">Треков не найдено</p>`;
} else {
searchTracksList.innerHTML = tracks.map(t => `
<div class="search-track-row">
<div class="track-left">
<img class="track-thumb" src="${t.cover || 'static/placeholder.png'}" onerror="this.src='data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'44\' height=\'44\' viewBox=\'0 0 24 24\' fill=\'none\' stroke=\'%2364748b\' stroke-width=\'2\'><rect x=\'3\' y=\'3\' width=\'18\' height=\'18\' rx=\'2\'/><circle cx=\'12\' cy=\'12\' r=\'4\'/></svg>'">
<div class="track-details">
<span class="track-title">${escapeHtml(t.title)}</span>
<span class="track-meta">
<span class="tag-badge tag-${t.service}">${t.service_name}</span> • ${escapeHtml(t.artist)} • ${escapeHtml(t.album || 'Single')} (${t.duration})
</span>
searchTracksList.innerHTML = tracks.map(t => {
const explicitBadge = t.explicit_status === 'explicit'
? `<span class="badge badge-explicit" title="Оригинал: текст без цензуры (18+)">🔞 18+ Explicit</span>`
: (t.explicit_status === 'clean'
? `<span class="badge badge-clean" title="Внимание: трек зацензурен (слова запиканы / вырезаны)">⚠️ Clean (Цензура)</span>`
: '');
const versionBadge = t.version ? `<span class="badge badge-version">${escapeHtml(t.version)}</span>` : '';
return `
<div class="search-track-row" id="track-row-${escapeHtml(t.id)}">
<div class="track-left">
<img class="track-thumb" src="${t.cover || 'static/placeholder.png'}" onerror="this.src='data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'44\' height=\'44\' viewBox=\'0 0 24 24\' fill=\'none\' stroke=\'%2364748b\' stroke-width=\'2\'><rect x=\'3\' y=\'3\' width=\'18\' height=\'18\' rx=\'2\'/><circle cx=\'12\' cy=\'12\' r=\'4\'/></svg>'">
<div class="track-details">
<div style="display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;">
<span class="track-title">${escapeHtml(t.title)}</span>
${explicitBadge}
${versionBadge}
</div>
<span class="track-meta">
<span class="tag-badge tag-${t.service}">${t.service_name}</span> • ${escapeHtml(t.artist)} • ${escapeHtml(t.album || 'Single')} (${t.duration})
</span>
</div>
</div>
<div class="track-actions">
<button class="btn-play-preview" onclick="playPreviewTrack('${escapeAttr(t.url)}', '${escapeAttr(t.title)}', '${escapeAttr(t.artist)}', '${escapeAttr(t.cover || '')}', '${escapeAttr(t.explicit_status || '')}', '${escapeAttr(t.preview_url || '')}')">
▶ Слушать
</button>
<button class="btn-sm btn-import" onclick="handleImport('${escapeAttr(t.url)}')">📥 В Navidrome</button>
<a class="btn-sm btn-direct-dl" href="api/direct-download?url=${encodeURIComponent(t.url)}" download>💾 Скачать</a>
</div>
</div>
<div class="track-actions">
<button class="btn-sm btn-import" onclick="handleImport('${escapeAttr(t.url)}')">📥 В Navidrome</button>
<a class="btn-sm btn-direct-dl" href="api/direct-download?url=${encodeURIComponent(t.url)}" download>💾 Скачать</a>
</div>
</div>
`).join("");
`;
}).join("");
}
// Albums
@@ -106,6 +122,65 @@ document.addEventListener("DOMContentLoaded", () => {
}
}
// Audio Preview Player
let currentPlayingUrl = null;
window.playPreviewTrack = function(url, title, artist, cover, explicitStatus, previewUrl) {
const bar = document.getElementById("audioPlayerBar");
const audio = document.getElementById("globalAudioPlayer");
const playerCover = document.getElementById("playerCover");
const playerTitle = document.getElementById("playerTitle");
const playerArtist = document.getElementById("playerArtist");
const playerBadge = document.getElementById("playerExplicitBadge");
const playerImportBtn = document.getElementById("playerImportBtn");
const playerDownloadBtn = document.getElementById("playerDownloadBtn");
if (currentPlayingUrl === url && !audio.paused) {
audio.pause();
return;
}
currentPlayingUrl = url;
playerCover.src = cover || "static/placeholder.png";
playerTitle.textContent = title;
playerArtist.textContent = artist;
if (explicitStatus === "explicit") {
playerBadge.className = "badge badge-explicit";
playerBadge.textContent = "🔞 18+ Explicit (Без цензуры)";
playerBadge.style.display = "inline-flex";
} else if (explicitStatus === "clean") {
playerBadge.className = "badge badge-clean";
playerBadge.textContent = "⚠️ Clean (С цензурой)";
playerBadge.style.display = "inline-flex";
} else {
playerBadge.style.display = "none";
}
playerImportBtn.onclick = () => handleImport(url);
playerDownloadBtn.onclick = () => {
window.location.href = "api/direct-download?url=" + encodeURIComponent(url);
};
bar.style.display = "flex";
// Choose source: Apple 30s direct preview or server stream with HTTP Range
const streamSrc = previewUrl || ("api/stream?url=" + encodeURIComponent(url));
audio.src = streamSrc;
audio.play().catch(e => console.warn("Playback error:", e));
};
const playerCloseBtn = document.getElementById("playerCloseBtn");
if (playerCloseBtn) {
playerCloseBtn.addEventListener("click", () => {
const audio = document.getElementById("globalAudioPlayer");
audio.pause();
audio.src = "";
currentPlayingUrl = null;
document.getElementById("audioPlayerBar").style.display = "none";
});
}
// Global handler for import button
window.handleImport = async function(url) {
await startDownload(url);
+188
View File
@@ -420,3 +420,191 @@ input[type="text"]:focus {
color: var(--accent-color);
text-decoration: none;
}
/* Explicit & Clean Badges */
.badge-explicit {
background-color: #ef4444;
color: #ffffff;
font-weight: 700;
font-size: 0.72rem;
padding: 0.15rem 0.45rem;
border-radius: 4px;
display: inline-flex;
align-items: center;
gap: 0.2rem;
letter-spacing: 0.02em;
}
.badge-clean {
background-color: #eab308;
color: #0f172a;
font-weight: 700;
font-size: 0.72rem;
padding: 0.15rem 0.45rem;
border-radius: 4px;
display: inline-flex;
align-items: center;
gap: 0.2rem;
}
.badge-version {
background-color: #334155;
color: #cbd5e1;
font-size: 0.72rem;
padding: 0.15rem 0.45rem;
border-radius: 4px;
}
/* Play Preview Button */
.btn-play-preview {
background-color: #10b981;
color: white;
border: none;
font-size: 0.78rem;
font-weight: 600;
padding: 0.35rem 0.65rem;
border-radius: 6px;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 0.3rem;
transition: all 0.15s ease;
}
.btn-play-preview:hover {
background-color: #059669;
transform: translateY(-1px);
}
.btn-play-preview.is-playing {
background-color: #f59e0b;
color: #0f172a;
}
/* Floating Audio Player Bar */
.audio-player-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(15, 23, 42, 0.96);
backdrop-filter: blur(12px);
border-top: 1px solid var(--border-color);
box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.6);
padding: 0.75rem 1.5rem;
display: flex;
align-items: center;
justify-content: space-between;
gap: 1.25rem;
z-index: 1000;
animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
from { transform: translateY(100%); }
to { transform: translateY(0); }
}
.player-track-info {
display: flex;
align-items: center;
gap: 0.75rem;
min-width: 220px;
max-width: 320px;
}
.player-cover {
width: 48px;
height: 48px;
border-radius: 6px;
object-fit: cover;
background-color: #334155;
flex-shrink: 0;
}
.player-meta {
display: flex;
flex-direction: column;
gap: 0.15rem;
overflow: hidden;
}
.player-title-row {
display: flex;
align-items: center;
gap: 0.4rem;
overflow: hidden;
}
.player-title {
font-size: 0.88rem;
font-weight: 600;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.player-artist {
font-size: 0.75rem;
color: var(--text-secondary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.player-controls-container {
flex: 1;
max-width: 640px;
display: flex;
align-items: center;
}
.player-controls-container audio {
width: 100%;
height: 38px;
outline: none;
}
.player-actions {
display: flex;
align-items: center;
gap: 0.5rem;
flex-shrink: 0;
}
.btn-player-close {
background: none;
border: none;
color: var(--text-secondary);
font-size: 1.4rem;
line-height: 1;
cursor: pointer;
padding: 0.2rem 0.4rem;
border-radius: 4px;
margin-left: 0.3rem;
}
.btn-player-close:hover {
color: #fff;
background-color: rgba(255, 255, 255, 0.1);
}
@media (max-width: 820px) {
.audio-player-bar {
flex-direction: column;
padding: 0.75rem 1rem;
gap: 0.6rem;
}
.player-track-info {
max-width: 100%;
width: 100%;
}
.player-controls-container {
width: 100%;
max-width: 100%;
}
.player-actions {
width: 100%;
justify-content: flex-end;
}
}