disallow /watch from crawlers

This commit is contained in:
ashley 2025-10-06 16:06:22 +02:00
parent 82a2afcece
commit 56f99dd3a5

View File

@ -3,7 +3,8 @@ var _yt_player = videojs;
var versionclient = "youtube.player.web_20250917_22_RC00" var versionclient = "youtube.player.web_20250917_22_RC00"
document.addEventListener("DOMContentLoaded", () => {
document.addEventListener("DOMContentLoaded", () => {
// video.js 8 init - source can be seen in https://poketube.fun/static/vjs.min.js or the vjs.min.js file // video.js 8 init - source can be seen in https://poketube.fun/static/vjs.min.js or the vjs.min.js file
const video = videojs('video', { const video = videojs('video', {
controls: true, controls: true,
@ -27,6 +28,9 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
// FIX: ensure inline playback hint for iOS/Safari // FIX: ensure inline playback hint for iOS/Safari
try { videoEl.setAttribute('playsinline', ''); videoEl.setAttribute('webkit-playsinline', ''); } catch {} try { videoEl.setAttribute('playsinline', ''); videoEl.setAttribute('webkit-playsinline', ''); } catch {}
// NEW: keep hidden audio eager and ready sooner (helps first-seek stability)
try { audio.setAttribute('preload', 'auto'); } catch {}
// global anti-ping-pong guard // global anti-ping-pong guard
let syncing = false; // prevents normal ping-pong let syncing = false; // prevents normal ping-pong
let restarting = false; // prevents loop-end ping-pong let restarting = false; // prevents loop-end ping-pong
@ -54,13 +58,15 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
let seekingInProgress = false; let seekingInProgress = false;
let resumeAfterSeek = false; let resumeAfterSeek = false;
// NEW FIX: grace window to silence arbiter + bridge immediately after seeks / restarts // NEW: short quiesce windows to ignore chatty events after seek or coordinator actions
let suppressBridgeUntil = 0; const SEEK_QUIESCE_MS = 700; // time to ignore play/pause/arbiter after seek
const nowPerf = () => performance?.now?.() || Date.now(); const ACTION_COOLDOWN_MS = 550; // time to ignore arbiter after coordinated play/pause
const bridgingSilenced = () => nowPerf() < suppressBridgeUntil; let quiesceUntil = 0; // timestamp (ms) until which we ignore event noise
function silenceBridging(ms = 900) { // tuned: long enough for decoders to settle after a seek let arbiterCooldownUntil = 0; // timestamp (ms) for arbiter cool-down
suppressBridgeUntil = nowPerf() + ms;
} const now = () => performance.now();
const inQuiesce = () => now() < quiesceUntil;
const inCooldown = () => now() < arbiterCooldownUntil;
// FIX: state arbiter watchdog (forces both to share same paused/playing state) // FIX: state arbiter watchdog (forces both to share same paused/playing state)
let arbiterTimer = null; let arbiterTimer = null;
@ -68,12 +74,17 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
function startArbiter() { function startArbiter() {
if (arbiterTimer) clearInterval(arbiterTimer); if (arbiterTimer) clearInterval(arbiterTimer);
arbiterTimer = setInterval(() => { arbiterTimer = setInterval(() => {
if (syncing || restarting || seekingInProgress || bridgingSilenced()) return; // NEW: do nothing during seek quiesce or cooldown; this is where ping-pong used to start
if (inQuiesce() || inCooldown() || syncing || restarting || seekingInProgress) return;
// treat "playing" strictly; ended counts as paused // treat "playing" strictly; ended counts as paused
const vPlaying = !video.paused() && !video.ended(); const vPlaying = !video.paused() && !video.ended();
const aPlaying = !audio.paused && !audio.ended; const aPlaying = !audio.paused && !audio.ended;
// NEW: if both aren't actually playable at the current time, don't force a pause yet
const t = Number(video.currentTime());
if (!bothPlayableAt(t)) return;
// if exactly one is playing, pause the one that is playing (safe + deterministic) // if exactly one is playing, pause the one that is playing (safe + deterministic)
if (vPlaying && !aPlaying) { if (vPlaying && !aPlaying) {
try { video.pause(); } catch {} try { video.pause(); } catch {}
@ -128,6 +139,7 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
const MICRO_DRIFT = 0.05; const MICRO_DRIFT = 0.05;
const SYNC_INTERVAL_MS = 250; const SYNC_INTERVAL_MS = 250;
// MDN/WHATWG: buffered regions are TimeRanges; we pad slightly for tolerance
const EPS = 0.15; const EPS = 0.15;
function timeInBuffered(media, t) { function timeInBuffered(media, t) {
try { try {
@ -215,13 +227,10 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
if (syncing || restarting || seekingInProgress) return; // FIX: don't start while seeking if (syncing || restarting || seekingInProgress) return; // FIX: don't start while seeking
syncing = true; syncing = true;
try { try {
// line up clocks first // align clocks first
const t = Number(video.currentTime()); const t = Number(video.currentTime());
if (isFinite(t) && Math.abs(Number(audio.currentTime) - t) > 0.05) safeSetCT(audio, t); if (isFinite(t) && Math.abs(Number(audio.currentTime) - t) > 0.05) safeSetCT(audio, t);
// Silence arbiter/bridging briefly while we spin both up in tandem
silenceBridging(800);
// first attempt: keep existing mute states // first attempt: keep existing mute states
let vOk = true, aOk = true; let vOk = true, aOk = true;
try { const p = video.play(); if (p && p.then) await p; } catch { vOk = false; } try { const p = video.play(); if (p && p.then) await p; } catch { vOk = false; }
@ -241,6 +250,9 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
} }
if (!syncInterval) startSyncLoop(); if (!syncInterval) startSyncLoop();
// NEW: after we coordinate a play, let things settle—keep arbiter hands-off briefly
arbiterCooldownUntil = now() + ACTION_COOLDOWN_MS;
} finally { } finally {
syncing = false; syncing = false;
} }
@ -253,6 +265,8 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
try { video.pause(); } catch {} try { video.pause(); } catch {}
try { audio.pause(); } catch {} try { audio.pause(); } catch {}
clearSyncLoop(); clearSyncLoop();
// NEW: also cool down arbiter to avoid immediate re-pauses
arbiterCooldownUntil = now() + ACTION_COOLDOWN_MS;
} finally { } finally {
syncing = false; syncing = false;
} }
@ -263,7 +277,6 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
const t = Number(video.currentTime()); const t = Number(video.currentTime());
if (isFinite(t) && Math.abs(Number(audio.currentTime) - t) > 0.1) safeSetCT(audio, t); if (isFinite(t) && Math.abs(Number(audio.currentTime) - t) > 0.1) safeSetCT(audio, t);
if (bothPlayableAt(t)) { if (bothPlayableAt(t)) {
silenceBridging(700); // NEW: brief grace on very first start
playTogether({ allowMutedRetry: true }); playTogether({ allowMutedRetry: true });
} else { } else {
pauseTogether(); pauseTogether();
@ -378,31 +391,37 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
video.on('ratechange', () => { try { audio.playbackRate = video.playbackRate(); } catch {} }); video.on('ratechange', () => { try { audio.playbackRate = video.playbackRate(); } catch {} });
// sync-safe event bridging using the coordinators (no ping-pong) // NEW: only bridge plays when *not* in quiesce/cooldown AND both are playable at T
video.on('play', () => { video.on('play', () => {
if (seekingInProgress || bridgingSilenced()) return; // FIX if (restarting || seekingInProgress || inQuiesce()) return; // FIX
vIsPlaying = true; vIsPlaying = true;
if (!aIsPlaying) playTogether({ allowMutedRetry: true }); const t = Number(video.currentTime());
if (!aIsPlaying && bothPlayableAt(t)) {
queueMicrotask(() => playTogether({ allowMutedRetry: true }));
}
}); });
audio.addEventListener('play', () => { audio.addEventListener('play', () => {
if (seekingInProgress || bridgingSilenced()) return; // FIX if (restarting || seekingInProgress || inQuiesce()) return; // FIX
aIsPlaying = true; aIsPlaying = true;
if (!vIsPlaying) playTogether({ allowMutedRetry: true }); const t = Number(video.currentTime());
if (!vIsPlaying && bothPlayableAt(t)) {
queueMicrotask(() => playTogether({ allowMutedRetry: true }));
}
}); });
video.on('pause', () => { video.on('pause', () => {
if (restarting || seekingInProgress || bridgingSilenced()) return; // FIX if (restarting || seekingInProgress || inQuiesce()) return; // FIX
vIsPlaying = false; vIsPlaying = false;
pauseTogether(); pauseTogether();
}); });
audio.addEventListener('pause', () => { audio.addEventListener('pause', () => {
if (restarting || seekingInProgress || bridgingSilenced()) return; // FIX if (restarting || seekingInProgress || inQuiesce()) return; // FIX
aIsPlaying = false; aIsPlaying = false;
pauseTogether(); pauseTogether();
}); });
video.on('waiting', () => { video.on('waiting', () => {
if (restarting || seekingInProgress || bridgingSilenced()) return; // FIX if (restarting || seekingInProgress || inQuiesce()) return; // FIX
vIsPlaying = false; vIsPlaying = false;
try { audio.pause(); } catch{}; try { audio.pause(); } catch{};
clearSyncLoop(); clearSyncLoop();
@ -441,37 +460,42 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
// suppress spurious 'ended' right after seeks (mobile/browser quirk guard) // suppress spurious 'ended' right after seeks (mobile/browser quirk guard)
let wasPlayingBeforeSeek = false; let wasPlayingBeforeSeek = false;
// NEW: also track audio seeking to keep state tight
audio.addEventListener('seeking', () => { markANotPlaying(); });
audio.addEventListener('seeked', () => { /* noop; video 'seeked' handles alignment */ });
video.on('seeking', () => { video.on('seeking', () => {
if (restarting) return; if (restarting) return;
seekingInProgress = true; // FIX seekingInProgress = true; // FIX
wasPlayingBeforeSeek = !video.paused(); wasPlayingBeforeSeek = !video.paused();
resumeAfterSeek = wasPlayingBeforeSeek; // FIX resumeAfterSeek = wasPlayingBeforeSeek; // FIX
// Silence arbiter/bridging *immediately* as the seek begins // NEW: quiesce event storm around first seek
silenceBridging(1200); quiesceUntil = now() + SEEK_QUIESCE_MS;
try { audio.pause(); } catch {} try { audio.pause(); } catch {}
clearSyncLoop(); clearSyncLoop();
const vt = Number(video.currentTime()); const vt = Number(video.currentTime());
if (Math.abs(vt - Number(audio.currentTime)) > 0.1) safeSetCT(audio, vt); if (Math.abs(vt - Number(audio.currentTime)) > 0.1) safeSetCT(audio, vt);
vIsPlaying = false; aIsPlaying = false; // FIX vIsPlaying = false; aIsPlaying = false; // FIX
}); });
video.on('seeked', async () => { video.on('seeked', async () => {
if (restarting) return; if (restarting) return;
// NEW: extend quiesce a bit into post-seek stabilization window
quiesceUntil = now() + SEEK_QUIESCE_MS;
const vt = Number(video.currentTime()); const vt = Number(video.currentTime());
if (Math.abs(vt - Number(audio.currentTime)) > 0.05) safeSetCT(audio, vt); if (Math.abs(vt - Number(audio.currentTime)) > 0.05) safeSetCT(audio, vt);
// FIX: only resume once the new point is playable; avoid first-load ping-pong // FIX: only resume once the new point is playable; avoid first-load ping-pong
if (resumeAfterSeek) { if (resumeAfterSeek) {
// keep silenced while we wait, then a touch more while starting // NEW: give first seek more headroom on slow devices
silenceBridging(1100); const ok = await waitUntilPlayable(vt, 1200);
await waitUntilPlayable(vt, 1200); if (ok) {
playTogether({ allowMutedRetry: false }); playTogether({ allowMutedRetry: false });
} else {
pauseTogether();
}
} else { } else {
pauseTogether(); pauseTogether();
} }
@ -501,14 +525,15 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
// tiny offset so 'ended' doesn't immediately refire // tiny offset so 'ended' doesn't immediately refire
const startAt = 0.001; const startAt = 0.001;
suppressEndedUntil = nowPerf() + 800; suppressEndedUntil = performance.now() + 800;
// NEW: silence bridge while we reset to head
silenceBridging(900);
video.currentTime(startAt); video.currentTime(startAt);
safeSetCT(audio, startAt); safeSetCT(audio, startAt);
// NEW: suppress arbiter and other bridges briefly as we restart
quiesceUntil = now() + SEEK_QUIESCE_MS;
arbiterCooldownUntil = now() + ACTION_COOLDOWN_MS;
await waitUntilPlayable(startAt, 1000); await waitUntilPlayable(startAt, 1000);
await playTogether({ allowMutedRetry: true }); await playTogether({ allowMutedRetry: true });
} finally { } finally {
@ -518,13 +543,13 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
video.on('ended', () => { video.on('ended', () => {
if (restarting) return; if (restarting) return;
if (nowPerf() < suppressEndedUntil) return; if (performance.now() < suppressEndedUntil) return;
if (desiredLoop) restartLoop(); if (desiredLoop) restartLoop();
else { pauseTogether(); } else { pauseTogether(); }
}); });
audio.addEventListener('ended', () => { audio.addEventListener('ended', () => {
if (restarting) return; if (restarting) return;
if (nowPerf() < suppressEndedUntil) return; if (performance.now() < suppressEndedUntil) return;
if (desiredLoop) restartLoop(); if (desiredLoop) restartLoop();
else { pauseTogether(); } else { pauseTogether(); }
}); });
@ -540,7 +565,6 @@ var versionclient = "youtube.player.web_20250917_22_RC00"
} }
}); });
// https://codeberg.org/ashley/poke/src/branch/main/src/libpoketube/libpoketube-youtubei-objects.json // https://codeberg.org/ashley/poke/src/branch/main/src/libpoketube/libpoketube-youtubei-objects.json