From 8018010aae3d65793a480e2791022d5a6859ea30 Mon Sep 17 00:00:00 2001 From: CodeDevMLH Date: Fri, 27 Dec 2024 00:32:26 +0100 Subject: [PATCH] .. --- script copy.js | 92 ++++++++++++++++++++++++++++++++----------------- spotlight.html | 18 ++++++---- styles copy.css | 22 ++++++++---- 3 files changed, 87 insertions(+), 45 deletions(-) diff --git a/script copy.js b/script copy.js index ae17da5..0b661a7 100644 --- a/script copy.js +++ b/script copy.js @@ -1,4 +1,4 @@ -let title = 'Spotlight'; // Title of the slideshow +let title = 'Spotlight'; // Title of the slideshow TBD let listFileName = 'list.txt'; // Name of the file containing the list of movie IDs let token = 'YOURAPIKEYHERE'; // Your Jellyfin API key let moviesSeriesBoth = 3; // 1 for movies, 2 for series, 3 for both @@ -6,43 +6,88 @@ let shuffleInterval = 15000; // Time in milliseconds before the next slide is sh let useTrailers = true; // Set to false to disable trailers let setRandomMovie = true; // Set to false to disable random movie selection from the list let showOnOtherPages = false; // Set to true to show the slideshow on all pages eg. favorites tab, requests tab, etc. -//let showTitle = false; // Set to false to hide the title +//let showTitle = false; // Set to false to hide the title TBD +let disableTrailerControls = true; // Set to false to enable trailer controls +let setMuted = true; // Set to false to disable unmuting the video on hover let umuteOnHover = true; // Set to false to disable unmuting the video on hover -let isMuted = true; // Set to false to start with sound +let unmutedVolume = 20; // Set the volume level when the video is unmuted let useSponsorBlock = true; // Set to true to use SponsorBlock data to skip intro/outro segments of trailers let plotMaxLength = 550; // Maximum number of characters in the plot -let trailerMaxLength = 0; // Default value 0; length measured in ms +let trailerMaxLength = 0; // Default value 0; length measured in ms, set to 0 to disable, could be used instead of SponsorBlock +let isMuted = true; // Default value true; set to false to start the video unmuted + +// variables let isChangingSlide = false, player = null, slideChangeTimeout = null, isHomePageActive = false; let currentLocation = window.top.location.href; let movieList = [], currentMovieIndex = 0; let previousMovies = []; let forwardMovies = []; +if (setMuted) { + const slidesContainer = document.getElementById('slides-container'); + slidesContainer.addEventListener('mouseenter', () => { + if (player) { + player.unMute(); + isMuted = false; + } + }); + + slidesContainer.addEventListener('mouseleave', () => { + if (player) { + player.mute(); + isMuted = true; + } + }); +} + // Get SponsorBlock-Data for the outro segment of the trailer //function fetchSponsorBlockOutro(videoId) { -const fetchSponsorBlockOutro = (videoId) => { +// @deprecated +const fetchSponsorBlockOutroOLD = (videoId) => { return fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&category=outro`) .then(response => response.json()) - .then(segments => { segments.length > 0 ? segments[0].segment : null; }) + .then(segments => { + return segments.length > 0 ? segments[0].segment : null; + }) .catch(error => { console.error('Error fetching SponsorBlock data:', error); return null; }); }; +const fetchSponsorBlockOutro = async (videoId) => { + try { + const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&category=outro`); + const segments = await response.json(); + if (segments.length > 0 && Array.isArray(segments[0].segment)) { + return segments[0].segment; // returns array: [start, end] + } + return null; + } catch (error) { + console.error('Error fetching SponsorBlock data:', error); + return null; + } +}; + // Monitor the video player for the outro segment +let monitorOutroInterval = null; // Global interval variable function monitorOutro(player, outroSegment) { - const interval = setInterval(() => { + if (monitorOutroInterval) { // Clear the interval if it's already running + clearInterval(monitorOutroInterval); + } + + monitorOutroInterval = setInterval(() => { if (!outroSegment || !player) { - clearInterval(interval); + console.log('Invalid outro segment or player not initialized'); + clearInterval(monitorOutroInterval); return; } const currentTime = player.getCurrentTime(); if (currentTime >= outroSegment[0] && currentTime < outroSegment[1]) { - clearInterval(interval); + clearInterval(monitorOutroInterval); player.stopVideo(); // stop video setTimeout(fetchRandomMovie, 100); // fetch next movie } @@ -247,16 +292,14 @@ const createSlideElement = (movie, hasVideo = false) => { width: '100%', videoId, playerVars: { - mute: 0, // Change to start the video muted MARK: set muted, not officaly refreneced by youtube API, but working... - controls: 0, // Hide the controls + mute: isMuted ? 1 : 0, // CHeck if the video should start muted + controls: disableTrailerControls ? 0 : 1, // Hide the controls disablekb: 1, // Disable keyboard controls fs: 1, // Enavle fullscreen - rel: 0, // Disable related videos - modestbranding: 1, // Hide the YouTube logo - showinfo: 0, // Hide the video title + iv_load_policy: 3, // Disable annotations }, events: { - 'onReady': event => { + 'onReady': event => { if (useSponsorBlock) { fetchSponsorBlockOutro(videoId).then(outroSegment => { if (outroSegment) { @@ -266,7 +309,7 @@ const createSlideElement = (movie, hasVideo = false) => { console.log('No outro segment found/provided'); } }).catch(error => { - console.error('Error fetching SponsorBlock outro segment:', error); + console.error('Error reading SponsorBlock outro segment:', error); }); } if (trailerMaxLength > 0) { @@ -283,7 +326,7 @@ const createSlideElement = (movie, hasVideo = false) => { if (isMuted) { event.target.setVolume(0); // Mute the video if the setting is MuteOn } else { - event.target.setVolume(4); + event.target.setVolume(unmutedVolume); // Set the volume, value between 0 and 100 } event.target.playVideo(); }, @@ -320,6 +363,7 @@ const createSlideElement = (movie, hasVideo = false) => { 'onError': () => { console.error(`YouTube prevented playback of '${movie.Name}'`); if (player) { + clearInterval(monitorOutroInterval); player.destroy(); player = null; } @@ -344,21 +388,7 @@ const createSlideElement = (movie, hasVideo = false) => { } }); - videoContainer.addEventListener('mouseenter', () => { - if (player && umuteOnHover) { - player.unMute(); - isMuted = false; - } - }); - - videoContainer.addEventListener('mouseleave', () => { - if (player && umuteOnHover) { - player.mute(); - isMuted = true; - } - }); } else { - console.log(`Trailer disabled for '${movie.Name}'`); startSlideChangeTimer(); } diff --git a/spotlight.html b/spotlight.html index 6e602fc..fe8d316 100644 --- a/spotlight.html +++ b/spotlight.html @@ -1,21 +1,25 @@ + Jellyfin Spotlight v2.5.0 Fork v1.2 - - - + + + + -
-