|
|
|
@@ -1403,7 +1403,9 @@ const ApiUtils = {
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
id: trailer.Id,
|
|
|
|
id: trailer.Id,
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${trailer.Id}/stream.mp4?mediaSourceId=${mediaSourceId}&api_key=${STATE.jellyfinData.accessToken}`
|
|
|
|
// static=true forces Jellyfin to direct-stream (no transcoding) which enables
|
|
|
|
|
|
|
|
// HTTP Range Requests (Accept-Ranges: bytes) — required by Safari for video playback
|
|
|
|
|
|
|
|
url: `${STATE.jellyfinData.serverAddress}/Videos/${trailer.Id}/stream.mp4?mediaSourceId=${mediaSourceId}&api_key=${STATE.jellyfinData.accessToken}&static=true`
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
@@ -1734,9 +1736,108 @@ const SlideCreator = {
|
|
|
|
// Create a wrapper for opacity transition
|
|
|
|
// Create a wrapper for opacity transition
|
|
|
|
videoBackdrop = SlideUtils.createElement("div", {
|
|
|
|
videoBackdrop = SlideUtils.createElement("div", {
|
|
|
|
className: `backdrop video-backdrop ${videoClass}`,
|
|
|
|
className: `backdrop video-backdrop ${videoClass}`,
|
|
|
|
style: "opacity: 0; transition: opacity 1.2s ease-in-out;" // Start interrupted/transparent
|
|
|
|
style: "opacity: 0; transition: opacity 1.2s ease-in-out;"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Detect Safari/WebKit — the YouTube IFrame API causes Error 153 on WebKit
|
|
|
|
|
|
|
|
// due to cross-origin postMessage restrictions. Use a plain iframe embed instead.
|
|
|
|
|
|
|
|
const isSafariWebKit = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/Chromium/.test(navigator.userAgent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isSafariWebKit) {
|
|
|
|
|
|
|
|
// ── Safari: plain iframe embed ───────────────────────────────────────────
|
|
|
|
|
|
|
|
// Fetch SponsorBlock data and apply as URL params (start= / end=)
|
|
|
|
|
|
|
|
ApiUtils.fetchSponsorBlockData(videoId).then(segments => {
|
|
|
|
|
|
|
|
let startParam = '';
|
|
|
|
|
|
|
|
let endParam = '';
|
|
|
|
|
|
|
|
if (segments.intro) {
|
|
|
|
|
|
|
|
startParam = `&start=${Math.ceil(segments.intro[1])}`;
|
|
|
|
|
|
|
|
console.info(`SponsorBlock (Safari) intro skip: starting at ${Math.ceil(segments.intro[1])}s`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (segments.outro) {
|
|
|
|
|
|
|
|
endParam = `&end=${Math.floor(segments.outro[0])}`;
|
|
|
|
|
|
|
|
console.info(`SponsorBlock (Safari) outro skip: ending at ${Math.floor(segments.outro[0])}s`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// enablejsapi=1 needed for postMessage commands — does NOT trigger IFrame API handshake
|
|
|
|
|
|
|
|
const embedUrl = `https://www.youtube-nocookie.com/embed/${videoId}?autoplay=1&mute=1&controls=0&playsinline=1&rel=0&iv_load_policy=3&enablejsapi=1&origin=${encodeURIComponent(window.location.origin)}${startParam}${endParam}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ytIframe = document.createElement('iframe');
|
|
|
|
|
|
|
|
ytIframe.style.cssText = 'width:100%;height:100%;border:0;pointer-events:none;';
|
|
|
|
|
|
|
|
ytIframe.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share');
|
|
|
|
|
|
|
|
ytIframe.setAttribute('allowfullscreen', '');
|
|
|
|
|
|
|
|
ytIframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
|
|
|
|
|
|
|
|
ytIframe.src = embedUrl;
|
|
|
|
|
|
|
|
videoBackdrop.appendChild(ytIframe);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Show immediately — no onStateChange available for plain iframes
|
|
|
|
|
|
|
|
videoBackdrop.style.opacity = '1';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Helper: send postMessage command to the iframe player
|
|
|
|
|
|
|
|
const ytCmd = (func, args = []) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ytIframe.contentWindow?.postMessage(
|
|
|
|
|
|
|
|
JSON.stringify({ event: 'command', func, args }),
|
|
|
|
|
|
|
|
'https://www.youtube-nocookie.com'
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} catch(e) { /* cross-origin access may fail on some iOS versions */ }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Listen for YouTube state changes (e.g. video ended → advance slide)
|
|
|
|
|
|
|
|
const handleYtMessage = (event) => {
|
|
|
|
|
|
|
|
if (!event.origin.includes('youtube')) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
|
|
|
|
|
|
if (data.event === 'onStateChange' && data.info === 0) { // 0 = YT.PlayerState.ENDED
|
|
|
|
|
|
|
|
const slide = document.querySelector(`.slide[data-item-id="${itemId}"]`);
|
|
|
|
|
|
|
|
if (slide && slide.classList.contains('active')) {
|
|
|
|
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('message', handleYtMessage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a postMessage-based stub compatible with all slide management code
|
|
|
|
|
|
|
|
// Key: we NEVER clear ytIframe.src — that would break the YouTube session and cause Error 153.
|
|
|
|
|
|
|
|
// Instead we use postMessage pause/play/seek to control playback state.
|
|
|
|
|
|
|
|
STATE.slideshow.videoPlayers[itemId] = {
|
|
|
|
|
|
|
|
_isSafariIframe: true,
|
|
|
|
|
|
|
|
_iframe: ytIframe,
|
|
|
|
|
|
|
|
_videoId: videoId,
|
|
|
|
|
|
|
|
_embedUrl: embedUrl,
|
|
|
|
|
|
|
|
_msgHandler: handleYtMessage,
|
|
|
|
|
|
|
|
pauseVideo() { ytCmd('pauseVideo'); },
|
|
|
|
|
|
|
|
stopVideo() { ytCmd('pauseVideo'); ytCmd('seekTo', [0, true]); },
|
|
|
|
|
|
|
|
playVideo() { ytCmd('playVideo'); },
|
|
|
|
|
|
|
|
mute() { ytCmd('mute'); },
|
|
|
|
|
|
|
|
unMute() { ytCmd('unMute'); },
|
|
|
|
|
|
|
|
setVolume(v) { ytCmd('setVolume', [v]); },
|
|
|
|
|
|
|
|
getIframe() { return ytIframe; },
|
|
|
|
|
|
|
|
getPlayerState() { return 1; }, // approximate: avoids triggering fallback timeouts
|
|
|
|
|
|
|
|
loadVideoById({ videoId: vid, startSeconds = 0 }) {
|
|
|
|
|
|
|
|
if (vid === this._videoId) {
|
|
|
|
|
|
|
|
// Same video — seek to start and resume. NEVER change src (would cause Error 153).
|
|
|
|
|
|
|
|
ytCmd('seekTo', [startSeconds, true]);
|
|
|
|
|
|
|
|
ytCmd('playVideo');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Different video — need a fresh embed URL
|
|
|
|
|
|
|
|
const url = `https://www.youtube-nocookie.com/embed/${vid}?autoplay=1&mute=1&controls=0&playsinline=1&rel=0&iv_load_policy=3&enablejsapi=1&origin=${encodeURIComponent(window.location.origin)}`;
|
|
|
|
|
|
|
|
ytIframe.src = url;
|
|
|
|
|
|
|
|
this._videoId = vid;
|
|
|
|
|
|
|
|
this._embedUrl = url;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
|
|
|
|
window.removeEventListener('message', this._msgHandler);
|
|
|
|
|
|
|
|
ytIframe.remove();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`🍎 Safari detected — using plain iframe embed for YouTube video ${videoId}`);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// ── Non-Safari: YouTube IFrame API ──────────────────────────────────────
|
|
|
|
const ytPlayerDiv = SlideUtils.createElement("div", {
|
|
|
|
const ytPlayerDiv = SlideUtils.createElement("div", {
|
|
|
|
id: `youtube-player-${itemId}`,
|
|
|
|
id: `youtube-player-${itemId}`,
|
|
|
|
style: "width: 100%; height: 100%;"
|
|
|
|
style: "width: 100%; height: 100%;"
|
|
|
|
@@ -1744,9 +1845,7 @@ const SlideCreator = {
|
|
|
|
|
|
|
|
|
|
|
|
videoBackdrop.appendChild(ytPlayerDiv);
|
|
|
|
videoBackdrop.appendChild(ytPlayerDiv);
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize YouTube Player
|
|
|
|
|
|
|
|
SlideUtils.loadYouTubeIframeAPI().then(() => {
|
|
|
|
SlideUtils.loadYouTubeIframeAPI().then(() => {
|
|
|
|
// Fetch SponsorBlock data
|
|
|
|
|
|
|
|
ApiUtils.fetchSponsorBlockData(videoId).then(segments => {
|
|
|
|
ApiUtils.fetchSponsorBlockData(videoId).then(segments => {
|
|
|
|
const playerVars = {
|
|
|
|
const playerVars = {
|
|
|
|
autoplay: 1,
|
|
|
|
autoplay: 1,
|
|
|
|
@@ -1770,8 +1869,7 @@ const SlideCreator = {
|
|
|
|
quality = 'hd720';
|
|
|
|
quality = 'hd720';
|
|
|
|
} else if (CONFIG.preferredVideoQuality === '1080p') {
|
|
|
|
} else if (CONFIG.preferredVideoQuality === '1080p') {
|
|
|
|
quality = 'hd1080';
|
|
|
|
quality = 'hd1080';
|
|
|
|
} else { // Auto or fallback
|
|
|
|
} else {
|
|
|
|
// If screen is wider than 1920, prefer highres, otherwise 1080p
|
|
|
|
|
|
|
|
quality = window.screen.width > 1920 ? 'highres' : 'hd1080';
|
|
|
|
quality = window.screen.width > 1920 ? 'highres' : 'hd1080';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1798,6 +1896,8 @@ const SlideCreator = {
|
|
|
|
const iframe = event.target.getIframe();
|
|
|
|
const iframe = event.target.getIframe();
|
|
|
|
if (iframe) {
|
|
|
|
if (iframe) {
|
|
|
|
iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
|
|
|
|
iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
|
|
|
|
|
|
|
|
// Full allow attribute matching what YouTube sets on their own embed pages
|
|
|
|
|
|
|
|
iframe.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Store start/end time and videoId for later use
|
|
|
|
// Store start/end time and videoId for later use
|
|
|
|
@@ -1825,13 +1925,10 @@ const SlideCreator = {
|
|
|
|
if (!slide || !slide.classList.contains('active') || document.hidden || (isVideoPlayerOpen && !isVideoPlayerOpen.classList.contains('hide'))) {
|
|
|
|
if (!slide || !slide.classList.contains('active') || document.hidden || (isVideoPlayerOpen && !isVideoPlayerOpen.classList.contains('hide'))) {
|
|
|
|
event.target.stopVideo();
|
|
|
|
event.target.stopVideo();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Pause slideshow timer when video starts if configured
|
|
|
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
if (CONFIG.waitForTrailerToEnd && STATE.slideshow.slideInterval) {
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
STATE.slideshow.slideInterval.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Safety check after 1s: handle navigation-away during the window,
|
|
|
|
|
|
|
|
// and fallback to muted play if autoplay failed for any reason.
|
|
|
|
|
|
|
|
const timeoutId = setTimeout(() => {
|
|
|
|
const timeoutId = setTimeout(() => {
|
|
|
|
const isVideoPlayerOpenNow = document.querySelector('.videoPlayerContainer') || document.querySelector('.youtubePlayerContainer');
|
|
|
|
const isVideoPlayerOpenNow = document.querySelector('.videoPlayerContainer') || document.querySelector('.youtubePlayerContainer');
|
|
|
|
if (document.hidden || (isVideoPlayerOpenNow && !isVideoPlayerOpenNow.classList.contains('hide')) || !slide.classList.contains('active')) {
|
|
|
|
if (document.hidden || (isVideoPlayerOpenNow && !isVideoPlayerOpenNow.classList.contains('hide')) || !slide.classList.contains('active')) {
|
|
|
|
@@ -1842,7 +1939,6 @@ const SlideCreator = {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If somehow not playing/buffering yet, force muted fallback
|
|
|
|
|
|
|
|
const state = event.target.getPlayerState();
|
|
|
|
const state = event.target.getPlayerState();
|
|
|
|
if (state !== YT.PlayerState.PLAYING && state !== YT.PlayerState.BUFFERING) {
|
|
|
|
if (state !== YT.PlayerState.PLAYING && state !== YT.PlayerState.BUFFERING) {
|
|
|
|
console.warn(`Autoplay stalled for ${itemId}, attempting muted fallback`);
|
|
|
|
console.warn(`Autoplay stalled for ${itemId}, attempting muted fallback`);
|
|
|
|
@@ -1856,7 +1952,6 @@ const SlideCreator = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'onStateChange': (event) => {
|
|
|
|
'onStateChange': (event) => {
|
|
|
|
// Fade in when playing
|
|
|
|
|
|
|
|
if (event.data === YT.PlayerState.PLAYING) {
|
|
|
|
if (event.data === YT.PlayerState.PLAYING) {
|
|
|
|
if (event.target._wrapperDiv) {
|
|
|
|
if (event.target._wrapperDiv) {
|
|
|
|
event.target._wrapperDiv.style.opacity = "1";
|
|
|
|
event.target._wrapperDiv.style.opacity = "1";
|
|
|
|
@@ -1872,7 +1967,6 @@ const SlideCreator = {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'onError': (event) => {
|
|
|
|
'onError': (event) => {
|
|
|
|
console.warn(`YouTube player error ${event.data} for video ${videoId}`);
|
|
|
|
console.warn(`YouTube player error ${event.data} for video ${videoId}`);
|
|
|
|
// Fallback to next slide on error
|
|
|
|
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
if (CONFIG.waitForTrailerToEnd) {
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1881,6 +1975,7 @@ const SlideCreator = {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} // end non-Safari
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Check for local video trailers in MediaSources if yt is not available
|
|
|
|
// 2. Check for local video trailers in MediaSources if yt is not available
|
|
|
|
} else if (!isYoutube) {
|
|
|
|
} else if (!isYoutube) {
|
|
|
|
@@ -1928,7 +2023,10 @@ const SlideCreator = {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
videoBackdrop.addEventListener('error', (event) => {
|
|
|
|
videoBackdrop.addEventListener('error', (event) => {
|
|
|
|
console.warn(`Local video error for item ${itemId}`);
|
|
|
|
const src = event.target.src || event.target.getAttribute('data-src') || 'unknown';
|
|
|
|
|
|
|
|
const errCode = event.target.error ? event.target.error.code : 'n/a';
|
|
|
|
|
|
|
|
const errMsg = event.target.error ? event.target.error.message : 'n/a';
|
|
|
|
|
|
|
|
console.warn(`Local video error for item ${itemId} | code=${errCode} | msg=${errMsg} | url=${src}`);
|
|
|
|
const slide = event.target.closest('.slide');
|
|
|
|
const slide = event.target.closest('.slide');
|
|
|
|
if (slide && slide.classList.contains('active')) {
|
|
|
|
if (slide && slide.classList.contains('active')) {
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
SlideshowManager.nextSlide();
|
|
|
|
|