Spaces:
Running
Running
File size: 2,451 Bytes
c7476df | 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 | // 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();
}); |