diff --git a/vars-music.js b/vars-music.js index fbb17ce..d841b32 100644 --- a/vars-music.js +++ b/vars-music.js @@ -1,7 +1,5 @@ - // Add this to your existing JavaScript file - - -async function displayVariousMusic() { + // Various music container + async function displayVariousMusic() { const content = document.getElementById('content'); content.innerHTML = `
@@ -274,18 +272,28 @@ async function displayVariousMusic() { content.innerHTML = `
-

Various Music

+

Music Explorer

-
+ ${getGenreSelectorHTML()} + ${getShortsSection()} + ${getChannelSectionHTML()} +
+
+ +
${getVideoPlayerHTML()} `; + // Initialize components initializeYouTubePlayer(); + fetchMusicShorts(); + fetchPopularMusicChannels(); fetchMusicVideos(); + initializeEventListeners(); } function initializeYouTubePlayer() { @@ -747,33 +755,7 @@ setTimeout(() => { }, 100); -// Enhanced displayVariousMusic function -async function displayVariousMusic() { - const content = document.getElementById('content'); - content.innerHTML = ` -
-
-

Music Explorer

- -
- ${getGenreSelectorHTML()} - ${getChannelSectionHTML()} -
-
- -
-
- ${getVideoPlayerHTML()} - `; - // Initialize components - initializeYouTubePlayer(); - fetchPopularMusicChannels(); - fetchMusicVideos(); - initializeEventListeners(); -} // Initialize event listeners function initializeEventListeners() { @@ -842,3 +824,80 @@ function debounce(func, wait) { timeout = setTimeout(later, wait); }; } + +function getShortsSection() { + return ` +
+
+

Music Shorts

+
+
+ +
+ +
+
+ `; +} + + +async function fetchMusicShorts() { + const API_KEY = 'AIzaSyB0-q2rcbRKwE_mNZTg7uV8WTqpeot5q84'; + try { + const response = await fetch( + `https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&videoDuration=short&maxResults=15&videoCategoryId=10&key=${API_KEY}` + ); + const data = await response.json(); + displayShorts(data.items); + } catch (error) { + console.error('Error fetching shorts:', error); + } +} + +function displayShorts(shorts) { + const shortsContainer = document.getElementById('shortsContainer'); + shortsContainer.innerHTML = shorts.map(short => ` +
+
+ ${short.snippet.title} +
+ Short +
+
+ +
+
+
+

${short.snippet.title.substring(0, 40)}${short.snippet.title.length > 40 ? '...' : ''}

+

${short.snippet.channelTitle}

+
+
+ `).join(''); +} + +function playShort(videoId) { + const playerContainer = document.getElementById('youtube-player-container'); + playerContainer.classList.remove('hidden'); + videoPlayer.loadVideoById(videoId); + updatePlayPauseButton(); +} + +function scrollShortsLeft() { + const container = document.querySelector('.shorts-container'); + container.scrollBy({ + left: -300, + behavior: 'smooth' + }); +} + +function scrollShortsRight() { + const container = document.querySelector('.shorts-container'); + container.scrollBy({ + left: 300, + behavior: 'smooth' + }); +}