Download script.js from yushalee/guideus-cosmic-streamer: direct link, hf CLI and curl.
- Browser
- Download file 7.71 kB
-
https://huggingface.co/spaces/yushalee/guideus-cosmic-streamer/resolve/main/script.js
- Command line
-
hf download hf://spaces/yushalee/guideus-cosmic-streamer/script.js
-
curl -L -o script.js https://huggingface.co/spaces/yushalee/guideus-cosmic-streamer/resolve/main/script.js
7.71 kB
| // 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); | |
| }); | |
| }); | |
| } | |
| }); |