fix: intercept PlaybackInfo API response in ClientScript.js to detect transcode state and prevent CSS over-zoom

This commit is contained in:
2026-09-17 23:03:18 +02:00
parent 78e100c99e
commit 512dabc611
+45 -3
View File
@@ -70,8 +70,13 @@ namespace JellyfinPlugin.Api
console.log('Black Bar Remover: Script loaded');
let currentItemId = null;
let interceptedItemId = null;
let currentCropData = null;
window._currentPlayMethod = null;
function isTranscoding() {
if (window._currentPlayMethod === 'Transcode' || window._currentPlayMethod === 'DirectStream') {
return true;
}
try {
if (window.playbackManager) {
const currentPlayer = window.playbackManager.getCurrentPlayer();
@@ -99,7 +104,7 @@ namespace JellyfinPlugin.Api
if (!video) return;
if (isTranscoding()) {
console.log('Black Bar Remover: Video is transcoded by server, skipping CSS crop.');
console.log('Black Bar Remover: Video is transcoded by server (PlayMethod:', window._currentPlayMethod, '), skipping CSS crop.');
video.style.clipPath = '';
video.style.transform = '';
return;
@@ -137,6 +142,7 @@ namespace JellyfinPlugin.Api
.then(crop => {
console.log('Black Bar Remover: Received crop data:', crop);
if (crop) {
currentCropData = crop;
setTimeout(() => applyCrop(crop), 500);
setTimeout(() => applyCrop(crop), 2000);
}
@@ -148,17 +154,37 @@ namespace JellyfinPlugin.Api
window._originalFetch = window.fetch;
window.fetch = async function(...args) {
const url = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url);
if (url) {
if (url && typeof url === 'string') {
const match = url.match(/\/Items\/([a-f0-9]{32}|[a-f0-9\-]{36})/i);
if (match) {
const id = match[1];
if (id && id !== interceptedItemId) {
interceptedItemId = id;
window._currentPlayMethod = null;
console.log('Black Bar Remover: Intercepted itemId from fetch:', id);
}
}
}
return window._originalFetch.apply(this, args);
const res = await window._originalFetch.apply(this, args);
if (url && typeof url === 'string' && url.includes('/PlaybackInfo')) {
try {
const clone = res.clone();
clone.json().then(data => {
if (data && data.MediaSources && data.MediaSources[0]) {
const ms = data.MediaSources[0];
window._currentPlayMethod = ms.PlayMethod || (ms.TranscodingUrl ? 'Transcode' : 'DirectPlay');
console.log('Black Bar Remover: PlayMethod from fetch PlaybackInfo:', window._currentPlayMethod);
if (currentCropData) {
applyCrop(currentCropData);
}
}
}).catch(e => {});
} catch(e) {}
}
return res;
};
}
@@ -174,9 +200,25 @@ namespace JellyfinPlugin.Api
const id = match[1];
if (id && id !== interceptedItemId) {
interceptedItemId = id;
window._currentPlayMethod = null;
console.log('Black Bar Remover: Intercepted itemId from XHR:', id);
}
}
if (url.includes('/PlaybackInfo')) {
xhr.addEventListener('load', function() {
try {
const data = JSON.parse(xhr.responseText);
if (data && data.MediaSources && data.MediaSources[0]) {
const ms = data.MediaSources[0];
window._currentPlayMethod = ms.PlayMethod || (ms.TranscodingUrl ? 'Transcode' : 'DirectPlay');
console.log('Black Bar Remover: PlayMethod from XHR PlaybackInfo:', window._currentPlayMethod);
if (currentCropData) {
applyCrop(currentCropData);
}
}
} catch(e) {}
});
}
}
return originalOpen.apply(this, [method, url, ...rest]);
};