function renderLiveChannels() { // Si no hay eventos cargados, cargarlos primero if (eventsChannels.length === 0 && events2Channels.length === 0) { showToast(' Cargando eventos...'); currentMode = 'live'; // Cargar ambos archivos de eventos en paralelo Promise.all([ fetch(EVENTS_M3U).then(function(r) { return r.text(); }), fetch(EVENTS2_M3U).then(function(r) { return r.text(); }) ]).then(function(results) { // Procesar eventos 1 var lines1 = results[0].split('\n'); for (var i = 0; i < lines1.length; i++) { if (lines1[i].startsWith('#EXTINF:')) { var name = lines1[i].split(',').slice(1).join(',').trim() || 'Canal'; var u = lines1[i + 1]; if (u) { var id = extractId(u); if (id) eventsChannels.push({ name: name, logo: LOGO_URL, id: id }); } } } // Procesar eventos 2 var lines2 = results[1].split('\n'); for (var i = 0; i < lines2.length; i++) { if (lines2[i].startsWith('#EXTINF:')) { var name = lines2[i].split(',').slice(1).join(',').trim() || 'Canal'; var u = lines2[i + 1]; if (u) { var id = extractId(u); if (id) events2Channels.push({ name: name, logo: LOGO_URL, id: id }); } } } eventsLoaded = true; filterAndRenderLive(); }).catch(function(err) { console.error('Error cargando eventos:', err); showToast('❌ Error al cargar eventos'); }); } else { // Ya están cargados, solo filtrar filterAndRenderLive(); } } function filterAndRenderLive() { var liveChannels = []; eventsChannels.forEach(function(ch) { if (isEventLive(ch.name)) liveChannels.push(ch); }); events2Channels.forEach(function(ch) { if (isEventLive(ch.name)) liveChannels.push(ch); }); currentMode = 'live'; render(liveChannels); }