diff --git a/player.html b/player.html
index 451de66..13f9fef 100644
--- a/player.html
+++ b/player.html
@@ -49,6 +49,10 @@
-
Aplica cambios a todos los ... canales seleccionados...
+
Aplica cambios a todos los 0 canales seleccionados.
diff --git a/player.js b/player.js
index 83b4fd0..1a20b43 100644
--- a/player.js
+++ b/player.js
@@ -190,6 +190,10 @@ $(document).ready(async function () {
if (typeof MovistarTokenHandler !== 'undefined' && typeof MovistarTokenHandler.setLogCallback === 'function') {
MovistarTokenHandler.setLogCallback(logToMovistarSettingsUI);
loadAndDisplayInitialMovistarStatus();
+ setInterval(async () => {
+ const status = await window.MovistarTokenHandler.getShortTokenStatus();
+ updateMovistarTokenStatusButton(status.expiry);
+ }, 60000); // Update every minute
}
if (typeof initXCodecPanelManagement === 'function') {
initXCodecPanelManagement();
@@ -778,6 +782,7 @@ function bindEvents() {
$('#movistarCopyCdnBtnSettings').on('click', handleMovistarCopyCdnToken);
$('#movistarApplyCdnToChannelsBtnSettings').on('click', handleMovistarApplyCdnToChannels);
$('#clearMovistarVodCacheBtnSettings').on('click', handleClearMovistarVodCache);
+ $('#movistarTokenStatusBtn').on('click', handleMovistarTokenStatusButtonClick);
$('#loadMovistarVODBtn').on('click', loadMovistarVODData);
@@ -999,6 +1004,8 @@ function updateMovistarCdnTokenUI(token, expiryTimestamp) {
}
$('#movistarCopyCdnBtnSettings').prop('disabled', !token);
$('#movistarApplyCdnToChannelsBtnSettings').prop('disabled', !token || (expiryTimestamp <= Math.floor(Date.now()/1000)));
+
+ updateMovistarTokenStatusButton(expiryTimestamp);
}
async function loadAndRenderLongTokensListSettings() {
@@ -1291,18 +1298,29 @@ async function handleMovistarCopyCdnToken() {
}
}
-async function handleMovistarApplyCdnToChannels() {
+async function handleMovistarApplyCdnToChannels(confirmed = false) {
+ if (!confirmed) {
+ const userConfirmed = await showConfirmationModal(
+ "Esto aplicará el token CDN actual a todos los canales de Movistar+ en la lista. ¿Continuar?",
+ "Confirmar Aplicación de Token", "Sí, Aplicar", "btn-success"
+ );
+ if (!userConfirmed) {
+ logToMovistarSettingsUI("Aplicación de token a canales cancelada por el usuario.", "info");
+ return { updatedCount: 0, success: false };
+ }
+ }
+
logToMovistarSettingsUI("Aplicando token CDN a canales Movistar+...", "info");
const status = await window.MovistarTokenHandler.getShortTokenStatus();
if (!status.token || status.expiry <= Math.floor(Date.now()/1000)) {
showNotification("El token CDN actual no es válido o ha expirado. Refréscalo primero.", "warning");
logToMovistarSettingsUI("Aplicación cancelada: token CDN no válido/expirado.", "warning");
- return;
+ return { updatedCount: 0, success: false };
}
if (!channels || channels.length === 0) {
showNotification("No hay lista M3U cargada para aplicar el token.", "info");
logToMovistarSettingsUI("Aplicación cancelada: no hay canales cargados.", "info");
- return;
+ return { updatedCount: 0, success: false };
}
showLoading(true, "Aplicando token a canales...");
@@ -1322,15 +1340,14 @@ async function handleMovistarApplyCdnToChannels() {
});
if (updatedCount > 0) {
- showNotification(`Token CDN aplicado a ${updatedCount} canales de Movistar+.`, "success");
logToMovistarSettingsUI(`Token aplicado a ${updatedCount} canales.`, "success");
regenerateCurrentM3UContentFromString();
filterAndRenderChannels();
} else {
- showNotification("No se encontraron canales de Movistar+ para aplicar el token.", "info");
logToMovistarSettingsUI("No se encontraron canales Movistar+.", "info");
}
showLoading(false);
+ return { updatedCount, success: true };
}
async function handleClearMovistarVodCache() {
@@ -1455,4 +1472,69 @@ function setActivePlayer(id) {
taskbarItem.classList.toggle('active', isNowActive);
}
});
+}
+
+function updateMovistarTokenStatusButton(expiryTimestamp) {
+ const $statusBtn = $('#movistarTokenStatusBtn');
+ if (!expiryTimestamp) {
+ $statusBtn.hide();
+ return;
+ }
+
+ $statusBtn.show();
+ const nowSeconds = Math.floor(Date.now() / 1000);
+ const remainingSeconds = expiryTimestamp - nowSeconds;
+ const $statusText = $('#movistarTokenStatusText');
+
+ if (remainingSeconds <= 0) {
+ $statusText.text('M+ Expirado');
+ $statusBtn.removeClass('btn-ok btn-warning').addClass('btn-danger');
+ } else {
+ const hours = Math.floor(remainingSeconds / 3600);
+ const minutes = Math.floor((remainingSeconds % 3600) / 60);
+ $statusText.text(`M+ ${hours}h ${minutes}m`);
+
+ if (remainingSeconds < 3600) { // Less than 1 hour
+ $statusBtn.removeClass('btn-ok btn-danger').addClass('btn-warning');
+ } else {
+ $statusBtn.removeClass('btn-warning btn-danger').addClass('btn-ok');
+ }
+ }
+}
+
+async function handleMovistarTokenStatusButtonClick() {
+ const confirmed = await showConfirmationModal(
+ "¿Quieres forzar la actualización del token de Movistar+ y aplicarlo a los canales de la lista actual?",
+ "Actualizar Token Movistar+",
+ "Sí, Actualizar y Aplicar",
+ "btn-primary"
+ );
+
+ if (!confirmed) return;
+
+ showLoading(true, "Actualizando y aplicando token de Movistar+...");
+ try {
+ const refreshResult = await window.MovistarTokenHandler.refreshCdnToken(true);
+ if (!refreshResult.success) {
+ throw new Error(refreshResult.message);
+ }
+
+ showNotification("Token CDN refrescado con éxito. Aplicando a canales...", "info");
+
+ const applyResult = await handleMovistarApplyCdnToChannels(true); // Pass true to avoid double confirmation
+
+ if (applyResult.updatedCount > 0) {
+ showNotification(`Token aplicado a ${applyResult.updatedCount} canales de Movistar+.`, "success");
+ } else {
+ showNotification("No se encontraron canales de Movistar+ para actualizar en la lista.", "info");
+ }
+
+ // Update UI for both settings and header button
+ updateMovistarCdnTokenUI(refreshResult.shortToken, refreshResult.shortTokenExpiry);
+
+ } catch (error) {
+ showNotification(`Error al actualizar token: ${error.message}`, "error");
+ } finally {
+ showLoading(false);
+ }
}
\ No newline at end of file