Spaces:
Running

lyrical-streamer / script.js
sammy004's picture
Build a YouTube video streemer use api AIzaSyD-arluaFfSq6EbDsYCcNC2OwzqNIL6iIE call it lyrical streemer it should be in matrix desighn
c7476df verified
Raw History Blame Contribute Delete
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();
});