From d7ab08c02234be2c945574f95dbfb71351426c04 Mon Sep 17 00:00:00 2001 From: lenafx Date: Thu, 1 Jan 2026 17:23:53 +0100 Subject: [PATCH] fixes on the web player --- desktop/src/scripts/anime/player.js | 35 ++++++++++++++++++++++++----- desktop/views/anime/anime.html | 6 +++++ docker/src/scripts/anime/player.js | 35 ++++++++++++++++++++++++----- 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/desktop/src/scripts/anime/player.js b/desktop/src/scripts/anime/player.js index 16880ae..98221f8 100644 --- a/desktop/src/scripts/anime/player.js +++ b/desktop/src/scripts/anime/player.js @@ -643,6 +643,10 @@ const AnimePlayer = (function() { const currentExt = els.extSelect.value; + if (currentExt !== 'local') { + _isLocal = false; + _rawVideoData = null; + } if (currentExt === 'local') { try { const localId = await getLocalEntryId(); @@ -650,7 +654,14 @@ const AnimePlayer = (function() { setLoading("Local entry not found in library."); return; } - const localUrl = `/api/library/stream/anime/${localId}/${_currentEpisode}`; + const check = await fetch(`/api/library/anime/${localId}/episodes`); + const eps = await check.json(); + + if (!eps.includes(_currentEpisode)) { + // 🔥 forzar online + els.extSelect.value = _entrySource; + return loadStream(); + } _rawVideoData = { url: window.location.origin + localUrl, @@ -666,9 +677,16 @@ const AnimePlayer = (function() { } const server = els.serverSelect.value || ""; - const sourceParam = `&source=${_entrySource}`; const extParam = `&ext=${currentExt}`; - const url = `/api/watch/stream?animeId=${_animeId}&episode=${_currentEpisode}&server=${encodeURIComponent(server)}&category=${_audioMode}${extParam}${sourceParam}`; + const realSource = _entrySource === 'local' ? 'anilist' : _entrySource; + + const url = + `/api/watch/stream?animeId=${_animeId}` + + `&episode=${_currentEpisode}` + + `&server=${encodeURIComponent(server)}` + + `&category=${_audioMode}` + + `${extParam}` + + `&source=${realSource}`; try { const res = await fetch(url); @@ -691,9 +709,10 @@ const AnimePlayer = (function() { if (headers['Referer'] && headers['Referer'] !== "null") proxyUrl += `&referer=${encodeURIComponent(headers['Referer'])}`; if (headers['User-Agent']) proxyUrl += `&userAgent=${encodeURIComponent(headers['User-Agent'])}`; + const subtitles = (source.subtitles || []).map(sub => ({ label: sub.language, - srclang: sub.id, + srclang: sub.language.toLowerCase().slice(0, 2), // en src: `/api/proxy?url=${encodeURIComponent(sub.url)}` })); @@ -753,7 +772,8 @@ const AnimePlayer = (function() { sendRPC({ startTimestamp: start, endTimestamp: end }); }); - if (Hls.isSupported() && (type === 'm3u8' || url.includes('.m3u8'))) { + + if (Hls.isSupported() && (type === 'm3u8')) { hlsInstance = new Hls(); hlsInstance.attachMedia(els.video); @@ -762,8 +782,13 @@ const AnimePlayer = (function() { }); hlsInstance.on(Hls.Events.MANIFEST_PARSED, () => { + attachSubtitles(subtitles); initPlyr(); + els.video.addEventListener('loadedmetadata', () => { + applyAniSkip(_malId, _currentEpisode); + }, { once: true }); + plyrInstance.on('ready', () => { createAudioSelector(hlsInstance); createQualitySelector(hlsInstance); diff --git a/desktop/views/anime/anime.html b/desktop/views/anime/anime.html index df3fc46..79a8209 100644 --- a/desktop/views/anime/anime.html +++ b/desktop/views/anime/anime.html @@ -81,6 +81,12 @@
+
Sub
diff --git a/docker/src/scripts/anime/player.js b/docker/src/scripts/anime/player.js index 16880ae..98221f8 100644 --- a/docker/src/scripts/anime/player.js +++ b/docker/src/scripts/anime/player.js @@ -643,6 +643,10 @@ const AnimePlayer = (function() { const currentExt = els.extSelect.value; + if (currentExt !== 'local') { + _isLocal = false; + _rawVideoData = null; + } if (currentExt === 'local') { try { const localId = await getLocalEntryId(); @@ -650,7 +654,14 @@ const AnimePlayer = (function() { setLoading("Local entry not found in library."); return; } - const localUrl = `/api/library/stream/anime/${localId}/${_currentEpisode}`; + const check = await fetch(`/api/library/anime/${localId}/episodes`); + const eps = await check.json(); + + if (!eps.includes(_currentEpisode)) { + // 🔥 forzar online + els.extSelect.value = _entrySource; + return loadStream(); + } _rawVideoData = { url: window.location.origin + localUrl, @@ -666,9 +677,16 @@ const AnimePlayer = (function() { } const server = els.serverSelect.value || ""; - const sourceParam = `&source=${_entrySource}`; const extParam = `&ext=${currentExt}`; - const url = `/api/watch/stream?animeId=${_animeId}&episode=${_currentEpisode}&server=${encodeURIComponent(server)}&category=${_audioMode}${extParam}${sourceParam}`; + const realSource = _entrySource === 'local' ? 'anilist' : _entrySource; + + const url = + `/api/watch/stream?animeId=${_animeId}` + + `&episode=${_currentEpisode}` + + `&server=${encodeURIComponent(server)}` + + `&category=${_audioMode}` + + `${extParam}` + + `&source=${realSource}`; try { const res = await fetch(url); @@ -691,9 +709,10 @@ const AnimePlayer = (function() { if (headers['Referer'] && headers['Referer'] !== "null") proxyUrl += `&referer=${encodeURIComponent(headers['Referer'])}`; if (headers['User-Agent']) proxyUrl += `&userAgent=${encodeURIComponent(headers['User-Agent'])}`; + const subtitles = (source.subtitles || []).map(sub => ({ label: sub.language, - srclang: sub.id, + srclang: sub.language.toLowerCase().slice(0, 2), // en src: `/api/proxy?url=${encodeURIComponent(sub.url)}` })); @@ -753,7 +772,8 @@ const AnimePlayer = (function() { sendRPC({ startTimestamp: start, endTimestamp: end }); }); - if (Hls.isSupported() && (type === 'm3u8' || url.includes('.m3u8'))) { + + if (Hls.isSupported() && (type === 'm3u8')) { hlsInstance = new Hls(); hlsInstance.attachMedia(els.video); @@ -762,8 +782,13 @@ const AnimePlayer = (function() { }); hlsInstance.on(Hls.Events.MANIFEST_PARSED, () => { + attachSubtitles(subtitles); initPlyr(); + els.video.addEventListener('loadedmetadata', () => { + applyAniSkip(_malId, _currentEpisode); + }, { once: true }); + plyrInstance.on('ready', () => { createAudioSelector(hlsInstance); createQualitySelector(hlsInstance);