fix editor, quick update x-tcdn-token M+
This commit is contained in:
		
							parent
							
								
									c321f6321e
								
							
						
					
					
						commit
						f031f9e0d4
					
				@ -49,6 +49,10 @@
 | 
				
			|||||||
                    <span class="header-search-icon"></span>
 | 
					                    <span class="header-search-icon"></span>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <div class="header-actions">
 | 
					                <div class="header-actions">
 | 
				
			||||||
 | 
					                    <button class="btn-header-action" id="movistarTokenStatusBtn" title="Estado y actualización del token de Movistar+" style="display: none;">
 | 
				
			||||||
 | 
					                        <span class="icon-placeholder" style="font-style: normal;">Ⓜ️</span>
 | 
				
			||||||
 | 
					                        <span class="btn-text" id="movistarTokenStatusText">Movistar</span>
 | 
				
			||||||
 | 
					                    </button>
 | 
				
			||||||
                    <button class="btn-header-action" id="openEditorBtn" title="Editor Avanzado">
 | 
					                    <button class="btn-header-action" id="openEditorBtn" title="Editor Avanzado">
 | 
				
			||||||
                        <span class="icon-placeholder" style="font-family: FontAwesome;"></span><span class="btn-text" data-lang-key="advancedEditorButton">Editor</span>
 | 
					                        <span class="icon-placeholder" style="font-family: FontAwesome;"></span><span class="btn-text" data-lang-key="advancedEditorButton">Editor</span>
 | 
				
			||||||
                    </button>
 | 
					                    </button>
 | 
				
			||||||
@ -287,7 +291,7 @@
 | 
				
			|||||||
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
 | 
					                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <div class="modal-body">
 | 
					                <div class="modal-body">
 | 
				
			||||||
                    <p class="text-secondary"><span data-lang-key="multiEditDescription" data-lang-vars='{"count": "#multiEditChannelCount"}'>Aplica cambios a todos los ... canales seleccionados...</span></p>
 | 
					                    <p class="text-secondary">Aplica cambios a todos los <strong id="multiEditChannelCount">0</strong> canales seleccionados.</p>
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    <div class="multi-edit-field">
 | 
					                    <div class="multi-edit-field">
 | 
				
			||||||
                        <div class="form-check form-switch"><input class="form-check-input" type="checkbox" id="multiEditEnableGroup"><label for="multiEditEnableGroup" data-lang-key="changeGroupLabel">Cambiar Grupo</label></div>
 | 
					                        <div class="form-check form-switch"><input class="form-check-input" type="checkbox" id="multiEditEnableGroup"><label for="multiEditEnableGroup" data-lang-key="changeGroupLabel">Cambiar Grupo</label></div>
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										92
									
								
								player.js
									
									
									
									
									
								
							
							
						
						
									
										92
									
								
								player.js
									
									
									
									
									
								
							@ -190,6 +190,10 @@ $(document).ready(async function () {
 | 
				
			|||||||
     if (typeof MovistarTokenHandler !== 'undefined' && typeof MovistarTokenHandler.setLogCallback === 'function') {
 | 
					     if (typeof MovistarTokenHandler !== 'undefined' && typeof MovistarTokenHandler.setLogCallback === 'function') {
 | 
				
			||||||
        MovistarTokenHandler.setLogCallback(logToMovistarSettingsUI);
 | 
					        MovistarTokenHandler.setLogCallback(logToMovistarSettingsUI);
 | 
				
			||||||
        loadAndDisplayInitialMovistarStatus();
 | 
					        loadAndDisplayInitialMovistarStatus();
 | 
				
			||||||
 | 
					        setInterval(async () => {
 | 
				
			||||||
 | 
					            const status = await window.MovistarTokenHandler.getShortTokenStatus();
 | 
				
			||||||
 | 
					            updateMovistarTokenStatusButton(status.expiry);
 | 
				
			||||||
 | 
					        }, 60000); // Update every minute
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (typeof initXCodecPanelManagement === 'function') {
 | 
					    if (typeof initXCodecPanelManagement === 'function') {
 | 
				
			||||||
        initXCodecPanelManagement();
 | 
					        initXCodecPanelManagement();
 | 
				
			||||||
@ -778,6 +782,7 @@ function bindEvents() {
 | 
				
			|||||||
    $('#movistarCopyCdnBtnSettings').on('click', handleMovistarCopyCdnToken);
 | 
					    $('#movistarCopyCdnBtnSettings').on('click', handleMovistarCopyCdnToken);
 | 
				
			||||||
    $('#movistarApplyCdnToChannelsBtnSettings').on('click', handleMovistarApplyCdnToChannels);
 | 
					    $('#movistarApplyCdnToChannelsBtnSettings').on('click', handleMovistarApplyCdnToChannels);
 | 
				
			||||||
    $('#clearMovistarVodCacheBtnSettings').on('click', handleClearMovistarVodCache);
 | 
					    $('#clearMovistarVodCacheBtnSettings').on('click', handleClearMovistarVodCache);
 | 
				
			||||||
 | 
					    $('#movistarTokenStatusBtn').on('click', handleMovistarTokenStatusButtonClick);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $('#loadMovistarVODBtn').on('click', loadMovistarVODData);
 | 
					    $('#loadMovistarVODBtn').on('click', loadMovistarVODData);
 | 
				
			||||||
@ -999,6 +1004,8 @@ function updateMovistarCdnTokenUI(token, expiryTimestamp) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    $('#movistarCopyCdnBtnSettings').prop('disabled', !token);
 | 
					    $('#movistarCopyCdnBtnSettings').prop('disabled', !token);
 | 
				
			||||||
    $('#movistarApplyCdnToChannelsBtnSettings').prop('disabled', !token || (expiryTimestamp <= Math.floor(Date.now()/1000)));
 | 
					    $('#movistarApplyCdnToChannelsBtnSettings').prop('disabled', !token || (expiryTimestamp <= Math.floor(Date.now()/1000)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    updateMovistarTokenStatusButton(expiryTimestamp);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function loadAndRenderLongTokensListSettings() {
 | 
					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");
 | 
					    logToMovistarSettingsUI("Aplicando token CDN a canales Movistar+...", "info");
 | 
				
			||||||
    const status = await window.MovistarTokenHandler.getShortTokenStatus();
 | 
					    const status = await window.MovistarTokenHandler.getShortTokenStatus();
 | 
				
			||||||
    if (!status.token || status.expiry <= Math.floor(Date.now()/1000)) {
 | 
					    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");
 | 
					        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");
 | 
					        logToMovistarSettingsUI("Aplicación cancelada: token CDN no válido/expirado.", "warning");
 | 
				
			||||||
        return;
 | 
					        return { updatedCount: 0, success: false };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!channels || channels.length === 0) {
 | 
					    if (!channels || channels.length === 0) {
 | 
				
			||||||
        showNotification("No hay lista M3U cargada para aplicar el token.", "info");
 | 
					        showNotification("No hay lista M3U cargada para aplicar el token.", "info");
 | 
				
			||||||
        logToMovistarSettingsUI("Aplicación cancelada: no hay canales cargados.", "info");
 | 
					        logToMovistarSettingsUI("Aplicación cancelada: no hay canales cargados.", "info");
 | 
				
			||||||
        return;
 | 
					        return { updatedCount: 0, success: false };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    showLoading(true, "Aplicando token a canales...");
 | 
					    showLoading(true, "Aplicando token a canales...");
 | 
				
			||||||
@ -1322,15 +1340,14 @@ async function handleMovistarApplyCdnToChannels() {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (updatedCount > 0) {
 | 
					    if (updatedCount > 0) {
 | 
				
			||||||
        showNotification(`Token CDN aplicado a ${updatedCount} canales de Movistar+.`, "success");
 | 
					 | 
				
			||||||
        logToMovistarSettingsUI(`Token aplicado a ${updatedCount} canales.`, "success");
 | 
					        logToMovistarSettingsUI(`Token aplicado a ${updatedCount} canales.`, "success");
 | 
				
			||||||
        regenerateCurrentM3UContentFromString();
 | 
					        regenerateCurrentM3UContentFromString();
 | 
				
			||||||
        filterAndRenderChannels();
 | 
					        filterAndRenderChannels();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        showNotification("No se encontraron canales de Movistar+ para aplicar el token.", "info");
 | 
					 | 
				
			||||||
        logToMovistarSettingsUI("No se encontraron canales Movistar+.", "info");
 | 
					        logToMovistarSettingsUI("No se encontraron canales Movistar+.", "info");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    showLoading(false);
 | 
					    showLoading(false);
 | 
				
			||||||
 | 
					    return { updatedCount, success: true };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function handleClearMovistarVodCache() {
 | 
					async function handleClearMovistarVodCache() {
 | 
				
			||||||
@ -1456,3 +1473,68 @@ function setActivePlayer(id) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user