File size: 7,712 Bytes
bc80807 6a2e7b6 bc80807 424fdfa bc80807 6a2e7b6 424fdfa bc80807 424fdfa bc80807 424fdfa bc80807 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | // Fetch EPG Data
async function fetchEPG() {
try {
const response = await fetch('https://epg.guideus.tv');
const data = await response.json();
renderEPG(data);
} catch (error) {
console.error('Error fetching EPG:', error);
document.getElementById('epg-container').innerHTML = `
<div class="text-center py-8 text-red-500">
<i data-feather="alert-circle" class="w-12 h-12 mx-auto mb-4"></i>
<p>Failed to load program guide. Please try again later.</p>
</div>
`;
feather.replace();
}
}
// Render EPG Data
function renderEPG(data) {
const epgContainer = document.getElementById('epg-container');
if (!data || !data.length) {
epgContainer.innerHTML = `
<div class="text-center py-8 text-gray-400">
<i data-feather="tv" class="w-12 h-12 mx-auto mb-4"></i>
<p>No program information available at this time.</p>
</div>
`;
feather.replace();
return;
}
let html = `
<div class="overflow-x-auto w-full">
<table class="min-w-full divide-y divide-gray-700 mx-auto">
<thead class="bg-gray-800">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Time</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Program</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Description</th>
</tr>
</thead>
<tbody class="bg-gray-800 divide-y divide-gray-700">
`;
data.forEach((program, index) => {
html += `
<tr class="${index % 2 === 0 ? 'bg-gray-800' : 'bg-gray-700'}">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${program.time}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-primary">${program.title}</td>
<td class="px-6 py-4 text-sm text-gray-400">${program.description || 'No description available'}</td>
</tr>
`;
});
html += `
</tbody>
</table>
</div>
`;
epgContainer.innerHTML = html;
}
// Fetch Recent Videos from RSS feed
async function fetchRecentVideos() {
try {
const response = await fetch('https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fguideus.tv%2Ffeed%2F');
const data = await response.json();
// Transform RSS feed items to match our expected format
const videos = data.items.map(item => {
// Extract first image from content if available
let thumbnail = 'http://static.photos/technology/640x360';
if (item.enclosure && item.enclosure.link) {
thumbnail = item.enclosure.link;
} else if (item.description) {
const imgMatch = item.description.match(/<img[^>]+src="([^">]+)"/);
if (imgMatch && imgMatch[1]) {
thumbnail = imgMatch[1];
}
}
// Clean up description
let description = item.description || 'No description available';
description = description.replace(/<[^>]*>?/gm, '').substring(0, 100) + '...';
// Extract video ID if YouTube link
let videoId = null;
if (item.link && item.link.includes('youtube.com')) {
const youtubeMatch = item.link.match(/[?&]v=([^&]+)/);
videoId = youtubeMatch ? youtubeMatch[1] : null;
}
return {
title: item.title,
description: description,
date: new Date(item.pubDate).toLocaleDateString(),
thumbnail: thumbnail,
link: item.link,
videoId: videoId
};
});
renderVideos(videos);
} catch (error) {
console.error('Error fetching videos:', error);
document.getElementById('videos-container').innerHTML = `
<div class="col-span-full text-center py-8 text-red-500">
<i data-feather="alert-circle" class="w-12 h-12 mx-auto mb-4"></i>
<p>Failed to load recent broadcasts. Please try again later.</p>
</div>
`;
feather.replace();
}
}
// Render Recent Videos
function renderVideos(videos) {
const videosContainer = document.getElementById('videos-container');
if (!videos || !videos.length) {
videosContainer.innerHTML = `
<div class="col-span-full text-center py-8 text-gray-400">
<i data-feather="video" class="w-12 h-12 mx-auto mb-4"></i>
<p>No recent broadcasts available at this time.</p>
</div>
`;
feather.replace();
return;
}
let html = '';
videos.forEach(video => {
html += `
<div class="bg-gray-800 rounded-lg overflow-hidden shadow-lg hover:shadow-xl transition-shadow duration-300 h-full flex flex-col">
<div class="aspect-w-16 aspect-h-9 bg-black relative flex-grow overflow-hidden">
${video.videoId ? `
<iframe src="https://www.youtube-nocookie.com/embed/${video.videoId}?autoplay=0&rel=0"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
class="w-full h-full"
loading="lazy"></iframe>
` : `
<img src="${video.thumbnail}"
alt="${video.title}"
class="w-full h-full object-cover">
<a href="${video.link}" class="absolute inset-0 flex items-center justify-center">
<i data-feather="play-circle" class="w-16 h-16 text-white opacity-75 hover:opacity-100 transition-opacity"></i>
</a>
`}
</div>
<div class="p-4">
<h3 class="font-semibold text-lg mb-1 text-primary line-clamp-2">${video.title}</h3>
<p class="text-sm text-gray-400 mb-2">${video.date || ''}</p>
<p class="text-sm text-gray-300 line-clamp-2">${video.description.replace(/<[^>]*>?/gm, '') || ''}</p>
</div>
</div>
`;
});
videosContainer.innerHTML = html;
feather.replace();
}
// Initialize the app
document.addEventListener('DOMContentLoaded', () => {
// Fetch data after splash screen hides
setTimeout(() => {
fetchEPG();
fetchRecentVideos();
}, 2000);
// Register service worker for PWA
// Mobile menu toggle
document.addEventListener('click', (e) => {
if (e.target.closest('#mobile-menu-button')) {
const menu = document.querySelector('custom-navbar').shadowRoot.getElementById('mobile-menu');
menu.classList.toggle('hidden');
feather.replace();
}
});
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js').then(registration => {
console.log('ServiceWorker registration successful');
}).catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
}); |