Skip Applying RemainingSecondsOfIntro for Segments at the End of the Video

This commit is contained in:
rlauu 2024-10-23 15:10:37 +02:00
parent 299db8d77e
commit f282e51308
2 changed files with 48 additions and 39 deletions

View File

@ -228,10 +228,10 @@ const introSkipper = {
const segment = this.skipSegments[key]; const segment = this.skipSegments[key];
if ( if (
(position > segment.ShowSkipPromptAt && (position > segment.ShowSkipPromptAt &&
position < segment.HideSkipPromptAt - 1) || position < segment.HideSkipPromptAt) ||
(this.osdVisible() && (this.osdVisible() &&
position > segment.IntroStart && position > segment.IntroStart &&
position < segment.IntroEnd - 1) position < segment.IntroEnd - 3)
) { ) {
return { ...segment, SegmentType: key }; return { ...segment, SegmentType: key };
} }
@ -250,31 +250,13 @@ const introSkipper = {
}, },
/** Playback position changed, check if the skip button needs to be displayed. */ /** Playback position changed, check if the skip button needs to be displayed. */
videoPositionChanged() { videoPositionChanged() {
if (!this.skipButton) return; if (!this.skipButton || !this.allowEnter) return;
const embyButton = this.skipButton.querySelector(".emby-button"); const { SegmentType: segmentType } = this.getCurrentSegment(this.videoPlayer.currentTime);
const segmentType = this.getCurrentSegment(
this.videoPlayer.currentTime,
).SegmentType;
if ( if (
segmentType === "None" || segmentType === "None" ||
this.currentOption === "Off" || this.currentOption === "Off"
!this.allowEnter
) { ) {
if (this.skipButton.classList.contains("show")) { this.hideSkipButton();
this.skipButton.classList.remove("show");
embyButton.addEventListener(
"transitionend",
() => {
this.skipButton.classList.add("hide");
if (this.osdVisible()) {
this.osdElement.querySelector("button.btnPause").focus();
} else {
embyButton.originalBlur();
}
},
{ once: true },
);
}
return; return;
} }
if ( if (
@ -285,22 +267,42 @@ const introSkipper = {
this.doSkip(); this.doSkip();
return; return;
} }
const button = this.skipButton.querySelector(".emby-button");
this.skipButton.querySelector("#btnSkipSegmentText").textContent = this.skipButton.querySelector("#btnSkipSegmentText").textContent =
this.skipButton.dataset[segmentType]; this.skipButton.dataset[segmentType];
if (!this.skipButton.classList.contains("hide")) { if (!this.skipButton.classList.contains("hide")) {
if (!this.osdVisible() && !embyButton.contains(document.activeElement)) if (!this.osdVisible() && !button.contains(document.activeElement)) {
embyButton.focus(); button.focus();
return; }
return;
} }
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.skipButton.classList.remove("hide"); this.skipButton.classList.remove("hide");
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.skipButton.classList.add("show"); this.skipButton.classList.add("show");
this.overrideBlur(embyButton); this.overrideBlur(button);
embyButton.focus(); button.focus();
}); });
}); });
}, },
hideSkipButton() {
if (this.skipButton.classList.contains("show")) {
this.skipButton.classList.remove("show");
const button = this.skipButton.querySelector(".emby-button");
button.addEventListener(
"transitionend",
() => {
this.skipButton.classList.add("hide");
if (this.osdVisible()) {
this.osdElement.querySelector("button.btnPause").focus();
} else {
button.originalBlur();
}
},
{ once: true },
);
}
},
/** Seeks to the end of the intro. */ /** Seeks to the end of the intro. */
doSkip() { doSkip() {
if (!this.allowEnter) return; if (!this.allowEnter) return;
@ -310,19 +312,15 @@ const introSkipper = {
return; return;
} }
this.d(`Skipping ${segment.SegmentType}`); this.d(`Skipping ${segment.SegmentType}`);
this.allowEnter = false;
const seekedHandler = () => { const seekedHandler = () => {
this.videoPlayer.removeEventListener("seeked", seekedHandler); this.videoPlayer.removeEventListener("seeked", seekedHandler);
setTimeout(() => { setTimeout(() => {
this.allowEnter = true; this.allowEnter = true;
}, 500); }, 700);
}; };
this.videoPlayer.addEventListener("seeked", seekedHandler); this.videoPlayer.addEventListener("seeked", seekedHandler);
this.videoPlayer.currentTime = this.videoPlayer.currentTime = segment.IntroEnd;
segment.SegmentType === "Credits" && this.hideSkipButton();
this.videoPlayer.duration - segment.IntroEnd < 3
? this.videoPlayer.duration + 10
: segment.IntroEnd;
}, },
createButton(ref, id, innerHTML, clickHandler) { createButton(ref, id, innerHTML, clickHandler) {
const button = ref.cloneNode(true); const button = ref.cloneNode(true);

View File

@ -157,18 +157,21 @@ public class SkipIntroController : ControllerBase
var segment = new Intro(timestamp); var segment = new Intro(timestamp);
var config = Plugin.Instance!.Configuration; var config = Plugin.Instance!.Configuration;
segment.IntroEnd -= config.RemainingSecondsOfIntro; segment.IntroEnd = mode == AnalysisMode.Credits
? GetAdjustedIntroEnd(id, segment.IntroEnd, config)
: segment.IntroEnd - config.RemainingSecondsOfIntro;
if (config.PersistSkipButton) if (config.PersistSkipButton)
{ {
segment.ShowSkipPromptAt = segment.IntroStart; segment.ShowSkipPromptAt = segment.IntroStart;
segment.HideSkipPromptAt = segment.IntroEnd; segment.HideSkipPromptAt = segment.IntroEnd - 3;
} }
else else
{ {
segment.ShowSkipPromptAt = Math.Max(0, segment.IntroStart - config.ShowPromptAdjustment); segment.ShowSkipPromptAt = Math.Max(0, segment.IntroStart - config.ShowPromptAdjustment);
segment.HideSkipPromptAt = Math.Min( segment.HideSkipPromptAt = Math.Min(
segment.IntroStart + config.HidePromptAdjustment, segment.IntroStart + config.HidePromptAdjustment,
segment.IntroEnd); segment.IntroEnd - 3);
} }
return segment; return segment;
@ -179,6 +182,14 @@ public class SkipIntroController : ControllerBase
} }
} }
private static double GetAdjustedIntroEnd(Guid id, double segmentEnd, PluginConfiguration config)
{
var runTime = TimeSpan.FromTicks(Plugin.Instance!.GetItem(id)?.RunTimeTicks ?? 0).TotalSeconds;
return runTime > 0 && runTime < segmentEnd + 1
? runTime
: segmentEnd - config.RemainingSecondsOfIntro;
}
/// <summary> /// <summary>
/// Erases all previously discovered introduction timestamps. /// Erases all previously discovered introduction timestamps.
/// </summary> /// </summary>