no more hard coded api key
This commit is contained in:
39
script.js
39
script.js
@@ -1,6 +1,5 @@
|
|||||||
let title = 'Spotlight'; // Title of the slideshow TBD
|
let title = 'Spotlight'; // Title of the slideshow TBD
|
||||||
let listFileName = 'list.txt'; // Name of the file containing the list of movie IDs
|
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
|
let moviesSeriesBoth = 3; // 1 for movies, 2 for series, 3 for both
|
||||||
let shuffleInterval = 15000; // Time in milliseconds before the next slide is shown, unless trailer is playing
|
let shuffleInterval = 15000; // Time in milliseconds before the next slide is shown, unless trailer is playing
|
||||||
let useTrailers = true; // Set to false to disable trailers
|
let useTrailers = true; // Set to false to disable trailers
|
||||||
@@ -16,6 +15,27 @@ let plotMaxLength = 550; // Maximum number of characters in the plot
|
|||||||
let trailerMaxLength = 0; // Default value 0; length measured in ms, set to 0 to disable, could be used instead of SponsorBlock
|
let trailerMaxLength = 0; // Default value 0; length measured in ms, set to 0 to disable, could be used instead of SponsorBlock
|
||||||
let startTrailerMuted = true; // Default value true; set to false to start the video unmuted
|
let startTrailerMuted = true; // Default value true; set to false to start the video unmuted
|
||||||
|
|
||||||
|
// get the Jellyfin credentials from the local storage (api token and user id)
|
||||||
|
const getJellyfinCredentials = () => {
|
||||||
|
const jellyfinCreds = localStorage.getItem("jellyfin_credentials");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const serverCredentials = JSON.parse(jellyfinCreds);
|
||||||
|
|
||||||
|
const firstServer = serverCredentials.Servers[0];
|
||||||
|
|
||||||
|
if (!firstServer) {
|
||||||
|
console.error("Could not find credentials for the client");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { token: firstServer.AccessToken, userId: firstServer.UserId };
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Could not parse jellyfin credentials", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const { token, userId } = getJellyfinCredentials();
|
||||||
|
|
||||||
|
|
||||||
// variables
|
// variables
|
||||||
@@ -584,17 +604,7 @@ const shuffleArray = (array) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchNextMovie = (useRandom = false) => {
|
const fetchNextMovie = (useRandom = false) => {
|
||||||
const fetchCurrentUserId = () =>
|
if (!userId) {
|
||||||
fetch('/Sessions', { headers: { 'Authorization': `MediaBrowser Client="Jellyfin Web", Device="YourDeviceName", DeviceId="YourDeviceId", Version="YourClientVersion", Token="${token}"` } })
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(sessions => {
|
|
||||||
const currentSession = sessions.find(session => session.UserId);
|
|
||||||
return currentSession ? currentSession.UserId : null;
|
|
||||||
})
|
|
||||||
.catch(() => null);
|
|
||||||
|
|
||||||
fetchCurrentUserId().then(currentUserId => {
|
|
||||||
if (!currentUserId) {
|
|
||||||
console.error('Could not retrieve the current user ID.');
|
console.error('Could not retrieve the current user ID.');
|
||||||
isChangingSlide = false;
|
isChangingSlide = false;
|
||||||
return;
|
return;
|
||||||
@@ -607,20 +617,19 @@ const fetchNextMovie = (useRandom = false) => {
|
|||||||
const movieId = movieList[currentMovieIndex];
|
const movieId = movieList[currentMovieIndex];
|
||||||
currentMovieIndex++;
|
currentMovieIndex++;
|
||||||
|
|
||||||
fetch(`/Users/${currentUserId}/Items/${movieId}?Fields=Overview,RemoteTrailers,PremiereDate,RunTimeTicks,ChildCount,Genres`, { headers })
|
fetch(`/Users/${userId}/Items/${movieId}?Fields=Overview,RemoteTrailers,PremiereDate,RunTimeTicks,ChildCount,Genres`, { headers })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(checkBackdropAndLogo)
|
.then(checkBackdropAndLogo)
|
||||||
.catch(() => startSlideChangeTimer())
|
.catch(() => startSlideChangeTimer())
|
||||||
.finally(() => { isChangingSlide = false; });
|
.finally(() => { isChangingSlide = false; });
|
||||||
} else {
|
} else {
|
||||||
const itemTypes = moviesSeriesBoth === 1 ? 'Movie' : (moviesSeriesBoth === 2 ? 'Series' : 'Movie,Series');
|
const itemTypes = moviesSeriesBoth === 1 ? 'Movie' : (moviesSeriesBoth === 2 ? 'Series' : 'Movie,Series');
|
||||||
fetch(`/Users/${currentUserId}/Items?IncludeItemTypes=${itemTypes}&Recursive=true&Limit=1&SortBy=random&Fields=Id,Overview,RemoteTrailers,PremiereDate,RunTimeTicks,ChildCount,Genres`, { headers })
|
fetch(`/Users/${userId}/Items?IncludeItemTypes=${itemTypes}&Recursive=true&Limit=1&SortBy=random&Fields=Id,Overview,RemoteTrailers,PremiereDate,RunTimeTicks,ChildCount,Genres`, { headers })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => { if (data.Items[0]) checkBackdropAndLogo(data.Items[0]); })
|
.then(data => { if (data.Items[0]) checkBackdropAndLogo(data.Items[0]); })
|
||||||
.catch(() => startSlideChangeTimer())
|
.catch(() => startSlideChangeTimer())
|
||||||
.finally(() => { isChangingSlide = false; });
|
.finally(() => { isChangingSlide = false; });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkNavigation = () => {
|
const checkNavigation = () => {
|
||||||
|
Reference in New Issue
Block a user