Spaces:
Running
Running
Download script.js from sammy004/lyrical-streamer: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/spaces/sammy004/lyrical-streamer/resolve/main/script.js
- Command line
-
hf download hf://spaces/sammy004/lyrical-streamer/script.js
-
curl -L -o script.js https://huggingface.co/spaces/sammy004/lyrical-streamer/resolve/main/script.js
2.45 kB
| // YouTube API key | |
| const API_KEY = 'AIzaSyD-arluaFfSq6EbDsYCcNC2OwzqNIL6iIE'; | |
| const MAX_RESULTS = 15; | |
| const CHANNEL_ID = 'UC-9-kyTW8ZkZNDHQJ6FgpwQ'; // YouTube Music channel | |
| // Create matrix rain effect | |
| function createMatrixRain() { | |
| const chars = "01γ’γ€γ¦γ¨γͺγ«γγ―γ±γ³γ΅γ·γΉγ»γ½γΏγγγγγγγγγγγγγγγγγ γ‘γ’γ€γ¦γ¨γ©γͺγ«γ¬γγ―γ²γ³"; | |
| const container = document.body; | |
| for (let i = 0; i < 50; i++) { | |
| const char = document.createElement('div'); | |
| char.className = 'matrix-char'; | |
| char.textContent = chars.charAt(Math.floor(Math.random() * chars.length)); | |
| char.style.left = `${Math.random() * 100}vw`; | |
| char.style.animationDelay = `${Math.random() * 5}s`; | |
| char.style.animationDuration = `${3 + Math.random() * 7}s`; | |
| container.appendChild(char); | |
| } | |
| } | |
| // Fetch videos from YouTube API | |
| async function fetchVideos() { | |
| try { | |
| const response = await fetch( | |
| `https://www.googleapis.com/youtube/v3/search?key=${API_KEY}&channelId=${CHANNEL_ID}&part=snippet,id&order=date&maxResults=${MAX_RESULTS}` | |
| ); | |
| const data = await response.json(); | |
| displayVideos(data.items); | |
| } catch (error) { | |
| console.error('Error fetching videos:', error); | |
| document.getElementById('video-container').innerHTML = ` | |
| <div class="col-span-full text-center py-10"> | |
| <i data-feather="alert-circle" class="w-12 h-12 mx-auto"></i> | |
| <p class="mt-4">Failed to load videos. Please try again later.</p> | |
| </div> | |
| `; | |
| feather.replace(); | |
| } | |
| } | |
| // Display videos in the grid | |
| function displayVideos(videos) { | |
| const container = document.getElementById('video-container'); | |
| container.innerHTML = ''; | |
| videos.forEach(video => { | |
| if (video.id.kind === 'youtube#video') { | |
| const videoCard = document.createElement('video-card'); | |
| videoCard.setAttribute('video-id', video.id.videoId); | |
| videoCard.setAttribute('title', video.snippet.title); | |
| videoCard.setAttribute('thumbnail', video.snippet.thumbnails.medium.url); | |
| videoCard.setAttribute('channel', video.snippet.channelTitle); | |
| container.appendChild(videoCard); | |
| } | |
| }); | |
| } | |
| // Initialize the app | |
| document.addEventListener('DOMContentLoaded', () => { | |
| createMatrixRain(); | |
| fetchVideos(); | |
| }); |