Skip to content

Commit

Permalink
Merge branch 'jumoog:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rlauuzo authored Aug 3, 2024
2 parents 3539e07 + e8fcdf5 commit f37ab2f
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ jobs:
dotnet outdated -pre Always -u -inc Jellyfin
- name: Initialize CodeQL
uses: github/codeql-action/init@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
uses: github/codeql-action/init@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # v3.25.15
with:
languages: ${{ matrix.language }}
queries: +security-extended
- name: Autobuild
uses: github/codeql-action/autobuild@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
uses: github/codeql-action/autobuild@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # v3.25.15
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
uses: github/codeql-action/analyze@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # v3.25.15
11 changes: 5 additions & 6 deletions ConfusedPolarBear.Plugin.IntroSkipper/AutoSkip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,16 @@ private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e)
}

// Seek is unreliable if called at the very start of an episode.
var adjustedStart = Math.Max(5, intro.IntroStart);
var adjustedStart = Math.Max(5, intro.IntroStart + Plugin.Instance.Configuration.SecondsOfIntroStartToPlay);
var adjustedEnd = intro.IntroEnd - Plugin.Instance.Configuration.RemainingSecondsOfIntro;

_logger.LogTrace(
"Playback position is {Position}, intro runs from {Start} to {End}",
position,
adjustedStart,
intro.IntroEnd);
adjustedEnd);

if (position < adjustedStart || position > intro.IntroEnd)
if (position < adjustedStart || position > adjustedEnd)
{
continue;
}
Expand All @@ -164,16 +165,14 @@ private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e)

_logger.LogDebug("Sending seek command to {Session}", deviceId);

var introEnd = (long)intro.IntroEnd - Plugin.Instance.Configuration.SecondsOfIntroToPlay;

_sessionManager.SendPlaystateCommand(
session.Id,
session.Id,
new PlaystateRequest
{
Command = PlaystateCommand.Seek,
ControllingUserId = session.UserId.ToString(),
SeekPositionTicks = introEnd * TimeSpan.TicksPerSecond,
SeekPositionTicks = (long)adjustedEnd * TimeSpan.TicksPerSecond,
},
CancellationToken.None);

Expand Down
13 changes: 6 additions & 7 deletions ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e)
continue;
}

// Seek is unreliable if called at the very start of an episode.
var adjustedStart = Math.Max(5, credit.IntroStart);
// Seek is unreliable if called at the very end of an episode.
var adjustedStart = credit.IntroStart + Plugin.Instance.Configuration.SecondsOfCreditsStartToPlay;
var adjustedEnd = credit.IntroEnd - Plugin.Instance.Configuration.RemainingSecondsOfIntro;

_logger.LogTrace(
"Playback position is {Position}, credits run from {Start} to {End}",
position,
adjustedStart,
credit.IntroEnd);
adjustedEnd);

if (position < adjustedStart || position > credit.IntroEnd)
if (position < adjustedStart || position > adjustedEnd)
{
continue;
}
Expand All @@ -164,16 +165,14 @@ private void PlaybackTimer_Elapsed(object? sender, ElapsedEventArgs e)

_logger.LogDebug("Sending seek command to {Session}", deviceId);

var creditEnd = (long)credit.IntroEnd;

_sessionManager.SendPlaystateCommand(
session.Id,
session.Id,
new PlaystateRequest
{
Command = PlaystateCommand.Seek,
ControllingUserId = session.UserId.ToString(),
SeekPositionTicks = creditEnd * TimeSpan.TicksPerSecond,
SeekPositionTicks = (long)adjustedEnd * TimeSpan.TicksPerSecond,
},
CancellationToken.None);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ public PluginConfiguration()
/// <summary>
/// Gets or sets the amount of intro to play (in seconds).
/// </summary>
public int SecondsOfIntroToPlay { get; set; } = 2;
public int RemainingSecondsOfIntro { get; set; } = 2;

/// <summary>
/// Gets or sets the amount of intro at start to play (in seconds).
/// </summary>
public int SecondsOfIntroStartToPlay { get; set; } = 0;

/// <summary>
/// Gets or sets the amount of credit at start to play (in seconds).
/// </summary>
public int SecondsOfCreditsStartToPlay { get; set; } = 0;

// ===== Internal algorithm settings =====

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@
<br />
</div>

<div id="divSecondsOfIntroStartToPlay" class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SecondsOfIntroStartToPlay">
Intro playback duration (in seconds)
</label>
<input id="SecondsOfIntroStartToPlay" type="number" is="emby-input" min="0" />
<div class="fieldDescription">
Seconds of introduction start that should be played. Defaults to 0.
</div>
<br />
</div>

<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="AutoSkipCredits" type="checkbox" is="emby-checkbox" />
Expand All @@ -378,6 +389,17 @@
</div>
</div>

<div id="divSecondsOfCreditsStartToPlay" class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SecondsOfCreditsStartToPlay">
Credit playback duration (in seconds)
</label>
<input id="SecondsOfCreditsStartToPlay" type="number" is="emby-input" min="0" />
<div class="fieldDescription">
Seconds of credits start that should be played. Defaults to 0.
</div>
<br />
</div>

<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="SkipButtonVisible" type="checkbox" is="emby-checkbox" />
Expand Down Expand Up @@ -427,10 +449,10 @@
<br />

<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SecondsOfIntroToPlay">
<label class="inputLabel inputLabelUnfocused" for="RemainingSecondsOfIntro">
Intro playback duration (in seconds)
</label>
<input id="SecondsOfIntroToPlay" type="number" is="emby-input" min="0" />
<input id="RemainingSecondsOfIntro" type="number" is="emby-input" min="0" />
<div class="fieldDescription">
Seconds of introduction ending that should be played. Defaults to 2.
</div>
Expand Down Expand Up @@ -511,7 +533,7 @@

<label class="inputLabel" for="troubleshooterEpisode1">Select the first episode</label>
<select is="emby-select" id="troubleshooterEpisode1" class="emby-select-withcolor emby-select"></select>
<label class="inputLabel" for="troubleshooterEpisode1">Select the seconds epsisode</label>
<label class="inputLabel" for="troubleshooterEpisode1">Select the second episode</label>
<select is="emby-select" id="troubleshooterEpisode2" class="emby-select-withcolor emby-select"></select>
<br />

Expand Down Expand Up @@ -681,7 +703,9 @@ <h3>Fingerprint Visualizer</h3>
// playback
"ShowPromptAdjustment",
"HidePromptAdjustment",
"SecondsOfIntroToPlay",
"RemainingSecondsOfIntro",
"SecondsOfIntroStartToPlay",
"SecondsOfCreditsStartToPlay",
// internals
"SilenceDetectionMaximumNoise",
"SilenceDetectionMinimumDuration",
Expand Down Expand Up @@ -725,6 +749,8 @@ <h3>Fingerprint Visualizer</h3>

var autoSkip = document.querySelector("input#AutoSkip");
var skipFirstEpisode = document.querySelector("div#divSkipFirstEpisode");
var secondsOfIntroStartToPlay = document.querySelector("div#divSecondsOfIntroStartToPlay");
var secondsOfCreditsStartToPlay = document.querySelector("div#divSecondsOfCreditsStartToPlay");
var autoSkipNotificationText = document.querySelector("div#divAutoSkipNotificationText");
var autoSkipCredits = document.querySelector("input#AutoSkipCredits");
var autoSkipCreditsNotificationText = document.querySelector("div#divAutoSkipCreditsNotificationText");
Expand All @@ -733,9 +759,11 @@ <h3>Fingerprint Visualizer</h3>
if (autoSkip.checked) {
skipFirstEpisode.style.display = 'unset';
autoSkipNotificationText.style.display = 'unset';
secondsOfIntroStartToPlay.style.display = 'unset';
} else {
skipFirstEpisode.style.display = 'none';
autoSkipNotificationText.style.display = 'none';
secondsOfIntroStartToPlay.style.display = 'none';
}
}

Expand All @@ -744,8 +772,10 @@ <h3>Fingerprint Visualizer</h3>
async function autoSkipCreditsChanged() {
if (autoSkipCredits.checked) {
autoSkipCreditsNotificationText.style.display = 'unset';
secondsOfCreditsStartToPlay.style.display = 'unset';
} else {
autoSkipCreditsNotificationText.style.display = 'none';
secondsOfCreditsStartToPlay.style.display = 'none';
}
}

Expand Down
4 changes: 2 additions & 2 deletions ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const introSkipper = {
this.skipButton.innerHTML = `
<button is="emby-button" type="button" class="btnSkipIntro injected">
<span id="btnSkipSegmentText"></span>
<span class="material-icons">skip_next</span>
<span class="material-icons skip_next"></span>
</button>
`;
this.skipButton.dataset.Introduction = config.SkipButtonIntroText;
Expand Down Expand Up @@ -195,7 +195,7 @@ const introSkipper = {
videoPositionChanged() {
if (!this.skipButton) return;
const embyButton = this.skipButton.querySelector(".emby-button");
const segmentType = introSkipper.getCurrentSegment(this.videoPlayer.currentTime).SegmentType;
const segmentType = this.getCurrentSegment(this.videoPlayer.currentTime).SegmentType;
if (segmentType === "None") {
if (!this.skipButton.classList.contains('show')) return;
this.skipButton.classList.remove('show');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>ConfusedPolarBear.Plugin.IntroSkipper</RootNamespace>
<AssemblyVersion>0.2.0.13</AssemblyVersion>
<FileVersion>0.2.0.13</FileVersion>
<AssemblyVersion>0.2.0.14</AssemblyVersion>
<FileVersion>0.2.0.14</FileVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public ActionResult<Dictionary<AnalysisMode, Intro>> GetSkippableSegments([FromR
var segment = new Intro(timestamp);

var config = Plugin.Instance.Configuration;
segment.IntroEnd -= config.SecondsOfIntroToPlay;
segment.IntroEnd -= config.RemainingSecondsOfIntro;
if (config.PersistSkipButton)
{
segment.ShowSkipPromptAt = segment.IntroStart;
Expand Down
25 changes: 7 additions & 18 deletions ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,7 @@ public Plugin(
{
WarningManager.SetFlag(PluginWarning.UnableToAddSkipButton);

if (ex is UnauthorizedAccessException)
{
var suggestion = OperatingSystem.IsLinux() ?
"running `sudo chown jellyfin PATH` (if this is a native installation)" :
"changing the permissions of PATH";

suggestion = suggestion.Replace("PATH", indexPath, StringComparison.Ordinal);

_logger.LogError(
"Failed to add skip button to web interface. Try {Suggestion} and restarting the server. Error: {Error}",
suggestion,
ex);
}
else
{
_logger.LogError("Unknown error encountered while adding skip button: {Error}", ex);
}
_logger.LogError("Failed to add skip button to web interface. See https://github.com/jumoog/intro-skipper?tab=readme-ov-file#skip-button-is-not-visible for the most common issues. Error: {Error}", ex);
}

FFmpegWrapper.CheckFFmpegVersion();
Expand Down Expand Up @@ -429,7 +413,8 @@ private void InjectSkipButton(string indexPath)
_logger.LogDebug("Reading index.html from {Path}", indexPath);
var contents = File.ReadAllText(indexPath);

var scriptTag = "<script src=\"configurationpage?name=skip-intro-button.js\"></script>";
// change URL with every relase to prevent the Browers from caching
var scriptTag = "<script src=\"configurationpage?name=skip-intro-button.js&release=" + GetType().Assembly.GetName().Version + "\"></script>";

// Only inject the script tag once
if (contents.Contains(scriptTag, StringComparison.OrdinalIgnoreCase))
Expand All @@ -438,6 +423,10 @@ private void InjectSkipButton(string indexPath)
return;
}

// remove old version if necessary
string pattern = @"<script src=""configurationpage\?name=skip-intro-button\.js.*<\/script>";
contents = Regex.Replace(contents, pattern, string.Empty, RegexOptions.IgnoreCase);

// Inject a link to the script at the end of the <head> section.
// A regex is used here to ensure the replacement is only done once.
var headEnd = new Regex("</head>", RegexOptions.IgnoreCase);
Expand Down
8 changes: 8 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"category": "General",
"imageUrl": "https://raw.githubusercontent.com/jumoog/intro-skipper/master/images/logo.png",
"versions": [
{
"version": "0.2.0.14",
"changelog": "- See the full changelog at [GitHub](https://github.com/jumoog/intro-skipper/blob/master/CHANGELOG.md)\n",
"targetAbi": "10.9.8.0",
"sourceUrl": "https://github.com/jumoog/intro-skipper/releases/download/10.9/v0.2.0.14/intro-skipper-v0.2.0.14.zip",
"checksum": "1d0b5cdc89030551599e9af4643cb3b5",
"timestamp": "2024-07-30T19:46:35Z"
},
{
"version": "0.2.0.13",
"changelog": "- See the full changelog at [GitHub](https://github.com/jumoog/intro-skipper/blob/master/CHANGELOG.md)\n",
Expand Down

0 comments on commit f37ab2f

Please sign in to comment.