Skip to content

Commit

Permalink
Support erasing times for intros and end credits
Browse files Browse the repository at this point in the history
  • Loading branch information
ConfusedPolarBear committed Nov 29, 2022
1 parent 94bd2a0 commit 16251f0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
61 changes: 42 additions & 19 deletions ConfusedPolarBear.Plugin.IntroSkipper/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@
</label>

<div class="fieldDescription">
If checked, intros will be automatically skipped. If you access Jellyfin through a reverse proxy, it must be configured to proxy web
If checked, intros will be automatically skipped. If you access Jellyfin through a
reverse proxy, it must be configured to proxy web
sockets.<br />
</div>
</div>
Expand Down Expand Up @@ -253,10 +254,6 @@
<span>Save</span>
</button>
<br />

<button id="btnEraseTimestamps" is="emby-button" class="raised block emby-button">
<span>Erase introduction timestamps</span>
</button>
</div>
</form>
</div>
Expand Down Expand Up @@ -302,7 +299,17 @@ <h3 style="margin:0">Introduction timestamp editor</h3>
<button id="btnEraseSeasonTimestamps" type="button">
Erase all timestamps for this season
</button>
<hr />
</div>

<button id="btnEraseIntroTimestamps">
Erase all introduction timestamps (globally)
</button>
<br />

<button id="btnEraseCreditTimestamps">
Erase all end credits timestamps (globally)
</button>
<br />
<br />

Expand Down Expand Up @@ -376,7 +383,8 @@ <h3>Fingerprint Visualizer</h3>
// settings elements
var visualizer = document.querySelector("details#visualizer");
var support = document.querySelector("details#support");
var btnEraseTimestamps = document.querySelector("button#btnEraseTimestamps");
var btnEraseIntroTimestamps = document.querySelector("button#btnEraseIntroTimestamps");
var btnEraseCreditTimestamps = document.querySelector("button#btnEraseCreditTimestamps");

// all plugin configuration fields that can be get or set with .value (i.e. strings or numbers).
var configurationFields = [
Expand Down Expand Up @@ -662,6 +670,28 @@ <h3>Fingerprint Visualizer</h3>
return new Date(seconds * 1000).toISOString().substr(14, 5);
}

// erase all intro/credits timestamps
function eraseTimestamps(mode) {
const lower = mode.toLocaleLowerCase();
const title = "Confirm timestamp erasure";
const body = "Are you sure you want to erase all previously discovered " +
mode.toLocaleLowerCase() +
" timestamps?";

Dashboard.confirm(
body,
title,
(result) => {
if (!result) {
return;
}

fetchWithAuth("Intros/EraseTimestamps?mode=" + mode, "POST", null);

Dashboard.alert(mode + " timestamps erased");
});
}

document.querySelector('#TemplateConfigPage')
.addEventListener('pageshow', function () {
Dashboard.showLoadingMsg();
Expand Down Expand Up @@ -707,19 +737,12 @@ <h3>Fingerprint Visualizer</h3>
selectSeason.addEventListener("change", seasonChanged);
selectEpisode1.addEventListener("change", episodeChanged);
selectEpisode2.addEventListener("change", episodeChanged);
btnEraseTimestamps.addEventListener("click", (e) => {
Dashboard.confirm(
"Are you sure you want to erase all previously discovered introduction timestamps?",
"Confirm timestamp erasure",
(result) => {
if (!result) {
return;
}

// reset all intro timestamps on the server so a new fingerprint comparison algorithm can be tested
fetchWithAuth("Intros/EraseTimestamps", "POST", null);
});

btnEraseIntroTimestamps.addEventListener("click", (e) => {
eraseTimestamps("Introduction");
e.preventDefault();
});
btnEraseCreditTimestamps.addEventListener("click", (e) => {
eraseTimestamps("Credits");
e.preventDefault();
});
btnSeasonEraseTimestamps.addEventListener("click", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,22 @@ public ActionResult<Intro> GetIntroTimestamps(
/// <summary>
/// Erases all previously discovered introduction timestamps.
/// </summary>
/// <param name="mode">Mode.</param>
/// <response code="204">Operation successful.</response>
/// <returns>No content.</returns>
[Authorize(Policy = "RequiresElevation")]
[HttpPost("Intros/EraseTimestamps")]
public ActionResult ResetIntroTimestamps()
public ActionResult ResetIntroTimestamps([FromQuery] AnalysisMode mode)
{
Plugin.Instance!.Intros.Clear();
if (mode == AnalysisMode.Introduction)
{
Plugin.Instance!.Intros.Clear();
}
else if (mode == AnalysisMode.Credits)
{
Plugin.Instance!.Credits.Clear();
}

Plugin.Instance!.SaveTimestamps();
return NoContent();
}
Expand Down

0 comments on commit 16251f0

Please sign in to comment.