fix: cap SABR reloads at 3 to prevent infinite backoff loop on throttled videos

This commit is contained in:
Emilien 2026-06-28 16:18:00 +02:00
parent cae8432a0e
commit 9fbe812899

View File

@ -42,6 +42,8 @@ var SABRPlayer = (function () {
var sabrStream = null; // handle returned by setupSabrScheme var sabrStream = null; // handle returned by setupSabrScheme
var sabrManifest = null; // captured from player.getManifest() on 'loaded' var sabrManifest = null; // captured from player.getManifest() on 'loaded'
var currentLoadOptions = null; // for onReloadOnce -> re-run loadVideo var currentLoadOptions = null; // for onReloadOnce -> re-run loadVideo
var reloadCount = 0; // cap reloads to prevent infinite loop on blocked/throttled videos
var MAX_RELOADS = 3;
function getSavedVolume() { function getSavedVolume() {
try { try {
@ -446,13 +448,27 @@ var SABRPlayer = (function () {
} }
}); });
sabrStream.onReloadOnce(function () { sabrStream.onReloadOnce(function () {
console.warn('[SABRPlayer] SABR reload requested by server; re-loading video'); reloadCount++;
if (reloadCount >= MAX_RELOADS) {
console.error('[SABRPlayer] SABR reload limit reached; giving up on video', currentVideoId);
if (shakaContainer) {
var errDiv = document.createElement('div');
errDiv.className = 'sabr-error-display';
errDiv.innerHTML = '<p>This video is currently unavailable via SABR.</p>' +
'<p>YouTube is throttling this request.</p>' +
'<p><a href="?quality=dash">Try DASH player instead</a></p>';
shakaContainer.appendChild(errDiv);
}
return;
}
console.warn('[SABRPlayer] SABR reload requested by server; re-loading video (attempt ' + reloadCount + '/' + MAX_RELOADS + ')');
if (currentVideoId && loadFn) loadFn(currentVideoId, shakaContainer, currentLoadOptions || {}); if (currentVideoId && loadFn) loadFn(currentVideoId, shakaContainer, currentLoadOptions || {});
}); });
} }
async function loadVideo(videoId, containerElement, options) { async function loadVideo(videoId, containerElement, options) {
options = options || {}; options = options || {};
if (videoId !== currentVideoId) reloadCount = 0;
currentVideoId = videoId; currentVideoId = videoId;
currentLoadOptions = options; currentLoadOptions = options;
playbackWebPoToken = null; playbackWebPoToken = null;