Support erasing times for intros and end credits

This commit is contained in:
ConfusedPolarBear 2022-11-29 02:31:24 -06:00
parent 94bd2a059e
commit 16251f0735
2 changed files with 53 additions and 21 deletions

View File

@ -201,7 +201,8 @@
</label> </label>
<div class="fieldDescription"> <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 /> sockets.<br />
</div> </div>
</div> </div>
@ -253,10 +254,6 @@
<span>Save</span> <span>Save</span>
</button> </button>
<br /> <br />
<button id="btnEraseTimestamps" is="emby-button" class="raised block emby-button">
<span>Erase introduction timestamps</span>
</button>
</div> </div>
</form> </form>
</div> </div>
@ -302,7 +299,17 @@
<button id="btnEraseSeasonTimestamps" type="button"> <button id="btnEraseSeasonTimestamps" type="button">
Erase all timestamps for this season Erase all timestamps for this season
</button> </button>
<hr />
</div> </div>
<button id="btnEraseIntroTimestamps">
Erase all introduction timestamps (globally)
</button>
<br />
<button id="btnEraseCreditTimestamps">
Erase all end credits timestamps (globally)
</button>
<br /> <br />
<br /> <br />
@ -376,7 +383,8 @@
// settings elements // settings elements
var visualizer = document.querySelector("details#visualizer"); var visualizer = document.querySelector("details#visualizer");
var support = document.querySelector("details#support"); 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). // all plugin configuration fields that can be get or set with .value (i.e. strings or numbers).
var configurationFields = [ var configurationFields = [
@ -662,6 +670,28 @@
return new Date(seconds * 1000).toISOString().substr(14, 5); 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') document.querySelector('#TemplateConfigPage')
.addEventListener('pageshow', function () { .addEventListener('pageshow', function () {
Dashboard.showLoadingMsg(); Dashboard.showLoadingMsg();
@ -707,19 +737,12 @@
selectSeason.addEventListener("change", seasonChanged); selectSeason.addEventListener("change", seasonChanged);
selectEpisode1.addEventListener("change", episodeChanged); selectEpisode1.addEventListener("change", episodeChanged);
selectEpisode2.addEventListener("change", episodeChanged); selectEpisode2.addEventListener("change", episodeChanged);
btnEraseTimestamps.addEventListener("click", (e) => { btnEraseIntroTimestamps.addEventListener("click", (e) => {
Dashboard.confirm( eraseTimestamps("Introduction");
"Are you sure you want to erase all previously discovered introduction timestamps?", e.preventDefault();
"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);
}); });
btnEraseCreditTimestamps.addEventListener("click", (e) => {
eraseTimestamps("Credits");
e.preventDefault(); e.preventDefault();
}); });
btnSeasonEraseTimestamps.addEventListener("click", () => { btnSeasonEraseTimestamps.addEventListener("click", () => {

View File

@ -76,13 +76,22 @@ public class SkipIntroController : ControllerBase
/// <summary> /// <summary>
/// Erases all previously discovered introduction timestamps. /// Erases all previously discovered introduction timestamps.
/// </summary> /// </summary>
/// <param name="mode">Mode.</param>
/// <response code="204">Operation successful.</response> /// <response code="204">Operation successful.</response>
/// <returns>No content.</returns> /// <returns>No content.</returns>
[Authorize(Policy = "RequiresElevation")] [Authorize(Policy = "RequiresElevation")]
[HttpPost("Intros/EraseTimestamps")] [HttpPost("Intros/EraseTimestamps")]
public ActionResult ResetIntroTimestamps() public ActionResult ResetIntroTimestamps([FromQuery] AnalysisMode mode)
{
if (mode == AnalysisMode.Introduction)
{ {
Plugin.Instance!.Intros.Clear(); Plugin.Instance!.Intros.Clear();
}
else if (mode == AnalysisMode.Credits)
{
Plugin.Instance!.Credits.Clear();
}
Plugin.Instance!.SaveTimestamps(); Plugin.Instance!.SaveTimestamps();
return NoContent(); return NoContent();
} }