fix: intercept PlaybackInfo API response in ClientScript.js to detect transcode state and prevent CSS over-zoom
This commit is contained in:
@@ -70,8 +70,13 @@ namespace JellyfinPlugin.Api
|
|||||||
console.log('Black Bar Remover: Script loaded');
|
console.log('Black Bar Remover: Script loaded');
|
||||||
let currentItemId = null;
|
let currentItemId = null;
|
||||||
let interceptedItemId = null;
|
let interceptedItemId = null;
|
||||||
|
let currentCropData = null;
|
||||||
|
window._currentPlayMethod = null;
|
||||||
|
|
||||||
function isTranscoding() {
|
function isTranscoding() {
|
||||||
|
if (window._currentPlayMethod === 'Transcode' || window._currentPlayMethod === 'DirectStream') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (window.playbackManager) {
|
if (window.playbackManager) {
|
||||||
const currentPlayer = window.playbackManager.getCurrentPlayer();
|
const currentPlayer = window.playbackManager.getCurrentPlayer();
|
||||||
@@ -99,7 +104,7 @@ namespace JellyfinPlugin.Api
|
|||||||
if (!video) return;
|
if (!video) return;
|
||||||
|
|
||||||
if (isTranscoding()) {
|
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.clipPath = '';
|
||||||
video.style.transform = '';
|
video.style.transform = '';
|
||||||
return;
|
return;
|
||||||
@@ -137,6 +142,7 @@ namespace JellyfinPlugin.Api
|
|||||||
.then(crop => {
|
.then(crop => {
|
||||||
console.log('Black Bar Remover: Received crop data:', crop);
|
console.log('Black Bar Remover: Received crop data:', crop);
|
||||||
if (crop) {
|
if (crop) {
|
||||||
|
currentCropData = crop;
|
||||||
setTimeout(() => applyCrop(crop), 500);
|
setTimeout(() => applyCrop(crop), 500);
|
||||||
setTimeout(() => applyCrop(crop), 2000);
|
setTimeout(() => applyCrop(crop), 2000);
|
||||||
}
|
}
|
||||||
@@ -148,17 +154,37 @@ namespace JellyfinPlugin.Api
|
|||||||
window._originalFetch = window.fetch;
|
window._originalFetch = window.fetch;
|
||||||
window.fetch = async function(...args) {
|
window.fetch = async function(...args) {
|
||||||
const url = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url);
|
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);
|
const match = url.match(/\/Items\/([a-f0-9]{32}|[a-f0-9\-]{36})/i);
|
||||||
if (match) {
|
if (match) {
|
||||||
const id = match[1];
|
const id = match[1];
|
||||||
if (id && id !== interceptedItemId) {
|
if (id && id !== interceptedItemId) {
|
||||||
interceptedItemId = id;
|
interceptedItemId = id;
|
||||||
|
window._currentPlayMethod = null;
|
||||||
console.log('Black Bar Remover: Intercepted itemId from fetch:', id);
|
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];
|
const id = match[1];
|
||||||
if (id && id !== interceptedItemId) {
|
if (id && id !== interceptedItemId) {
|
||||||
interceptedItemId = id;
|
interceptedItemId = id;
|
||||||
|
window._currentPlayMethod = null;
|
||||||
console.log('Black Bar Remover: Intercepted itemId from XHR:', id);
|
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]);
|
return originalOpen.apply(this, [method, url, ...rest]);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user