added download monitor

This commit is contained in:
2026-01-06 19:26:06 +01:00
parent ba05e08e71
commit 8296e8d7da
12 changed files with 616 additions and 30 deletions

View File

@@ -1779,11 +1779,19 @@ const AnimePlayer = (function() {
btn.disabled = true;
btn.innerHTML = `<div class="spinner" style="width:18px; height:18px; border-width:2px;"></div>`;
// --- CAMBIO AQUÍ: Calcular duración del video actual ---
let totalDuration = 0;
if (els.video && isFinite(els.video.duration) && els.video.duration > 0) {
totalDuration = Math.floor(els.video.duration);
}
// -------------------------------------------------------
let body = {
anilist_id: parseInt(_animeId),
episode_number: parseInt(_currentEpisode),
stream_url: _rawVideoData.url,
headers: _rawVideoData.headers || {},
duration: totalDuration, // <--- ENVIAMOS LA DURACIÓN
chapters: _skipIntervals.map(i => ({
title: i.type === 'op' ? 'Opening' : 'Ending',
start_time: i.startTime,

View File

@@ -388,6 +388,95 @@ const DashboardApp = {
Library: {
tempMatchContext: null,
pollInterval: null,
updateDownloadStatus: async function() {
try {
const res = await fetch(`${API_BASE}/library/downloads/status`, {
headers: window.AuthUtils.getSimpleAuthHeaders()
});
if (!res.ok) return;
const data = await res.json();
this.renderDownloadMonitor(data);
// Si hay descargas completadas nuevas, podríamos recargar la lista de archivos
// (Opcional: lógica para detectar cambios y llamar a loadContent)
} catch (e) {
console.error("Error polling downloads:", e);
}
},
renderDownloadMonitor: function(data) {
const monitor = document.getElementById('downloads-monitor');
const listContainer = document.getElementById('downloads-list-container');
const activeCountEl = document.getElementById('dl-stat-active');
// Datos por defecto
const downloads = data.downloads || { list: [], active: 0, failed: 0 };
// Actualizar contadores cabecera
if(activeCountEl) activeCountEl.textContent = `${downloads.active} Active / ${downloads.list.length} Total`;
// Ocultar si vacío
if (downloads.list.length === 0) {
monitor.classList.add('hidden');
return;
}
monitor.classList.remove('hidden');
listContainer.innerHTML = downloads.list.map(item => {
const fileName = item.fileName || `Unknown_File_${item.unitNumber}`;
const folderName = item.folderName || 'Unsorted';
const status = item.status || 'pending';
const progress = item.progress || 0;
const speed = item.speed || '0 KB/s';
const isCompleted = status === 'completed';
const isFailed = status === 'failed';
let statusText = `${progress}%`;
if (isCompleted) statusText = 'Done';
if (isFailed) statusText = 'Failed';
const folderIcon = `<svg width="12" height="12" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/></svg>`;
// ESTRUCTURA NUEVA: Más plana para permitir Flexbox horizontal
return `
<div class="dl-item compact">
<div class="dl-left-col">
<div class="dl-filename" title="${fileName}">${fileName}</div>
<div class="dl-folder" title="${folderName}">${folderIcon} ${folderName}</div>
</div>
<div class="dl-right-col">
<div class="dl-meta-info">
<span class="dl-speed">${isCompleted ? '' : speed}</span>
<span class="dl-status-text ${status}">${statusText}</span>
</div>
<div class="dl-progress-track">
<div class="dl-progress-fill ${status}" style="width: ${progress}%"></div>
</div>
</div>
</div>
`;
}).join('');
},
startPolling: function() {
if (this.pollInterval) clearInterval(this.pollInterval);
this.updateDownloadStatus(); // Primera llamada inmediata
this.pollInterval = setInterval(() => this.updateDownloadStatus(), 2000); // Cada 2 segundos
},
stopPolling: function() {
if (this.pollInterval) {
clearInterval(this.pollInterval);
this.pollInterval = null;
}
},
loadStats: async function() {
const types = ['anime', 'manga', 'novels'];
const elements = { 'anime': 'local-anime-count', 'manga': 'local-manga-count', 'novels': 'local-novel-count' };
@@ -584,6 +673,7 @@ const DashboardApp = {
tabs.forEach(tab => {
tab.addEventListener('click', () => {
// Gestión de clases activas
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
@@ -593,9 +683,13 @@ const DashboardApp = {
if (sec.id === targetId) sec.classList.add('active');
});
// Lógica específica por pestaña
if (tab.dataset.target === 'local') {
DashboardApp.Library.loadStats();
DashboardApp.Library.loadContent('anime');
DashboardApp.Library.loadContent(DashboardApp.State.currentLocalType || 'anime');
DashboardApp.Library.startPolling(); // <--- INICIAR POLLING
} else {
DashboardApp.Library.stopPolling(); // <--- DETENER POLLING AL SALIR
}
});
});