Skip to content

Commit

Permalink
Added optional time skipped to on screen message.
Browse files Browse the repository at this point in the history
  • Loading branch information
BillOatman committed Dec 24, 2022
1 parent b226d78 commit de70db2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ComSkipper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.4.0.0</Version>
<Version>1.5.0.0</Version>
<AssemblyName>ComSkipper</AssemblyName>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/BillOatmanWork/Emby.ComSkipper</RepositoryUrl>
Expand All @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediaBrowser.Server.Core" Version="4.7.3" />
<PackageReference Include="MediaBrowser.Server.Core" Version="4.7.9" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

Expand Down
16 changes: 16 additions & 0 deletions Configuration/ComSkipper.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ <h3 style="margin: .6em 0; vertical-align: middle; display: inline-block;">
</div>
</div>

<div class="inputContainer">
<label style="width: auto;" class="mdl-switch mdl-js-switch">
<input is="emby-toggle" type="checkbox" id="showTime" class="chkshowTime" data-embytoggle="">
<span class="toggleButtonLabel mdl-switch__label">Show Commercial Duration in On-Screen Message</span>
<div class="mdl-switch__trackContainer">
<div class="mdl-switch__track"></div>
<div class="mdl-switch__thumb">
<span class="mdl-switch__focus-helper"></span>
</div>
</div>
</label>
<div class="fieldDescription">
Show the commercial duration, in seconds, in the on-screen message when a commercial is skipped.
</div>
</div>

<div class="inputContainer">
<label style="width: auto;" class="mdl-switch mdl-js-switch">
<input is="emby-toggle" type="checkbox" id="enableRealtime" class="chkenableRealtime" data-embytoggle="">
Expand Down
15 changes: 15 additions & 0 deletions Configuration/ComSkipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
var chkEnableAutoSkip = view.querySelector('#autoSkipCommercials');
var chkEnableRealtime = view.querySelector('#enableRealtime');
var chkDisableMessage = view.querySelector('#disableMessage');
var chkShowTime = view.querySelector('#showTime');

ApiClient.getPluginConfiguration(pluginId).then((config) => {
chkEnableAutoSkip.checked = config.EnableComSkipper ?? false;
chkDisableMessage.checked = config.DisableMessage ?? false;
chkEnableRealtime.checked = config.RealTimeEnabled ?? false;
chkShowTime.checked = config.ShowTimeInMessage ?? false;
});

chkEnableAutoSkip.addEventListener('change', (elem) => {
Expand All @@ -28,6 +30,12 @@
enableDisableMessage(disMsg);
});

chkShowTime.addEventListener('change', (elem) => {
elem.preventDefault();
var showTime = chkShowTime.checked;
enableShowTime(showTime);
});

chkEnableRealtime.addEventListener('change', (elem) => {
elem.preventDefault();
var realTime = chkEnableRealtime.checked;
Expand All @@ -48,6 +56,13 @@
});
}

function enableShowTime(showTime) {
ApiClient.getPluginConfiguration(pluginId).then((config) => {
config.ShowTimeInMessage = showTime;
ApiClient.updatePluginConfiguration(pluginId, config).then(() => { });
});
}

function enableRealTime(realTime) {
ApiClient.getPluginConfiguration(pluginId).then((config) => {
config.RealTimeEnabled = realTime;
Expand Down
4 changes: 3 additions & 1 deletion Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class PluginConfiguration : BasePluginConfiguration

public bool DisableMessage { get; set; }

public bool RealTimeEnabled { get; set; }
public bool RealTimeEnabled { get; set; }

public bool ShowTimeInMessage { get; set; }
}
}
10 changes: 7 additions & 3 deletions ServerEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void PlaybackProgress(object sender, PlaybackProgressEventArgs e)
SkipCommercial(controlSession, found.endTicks);

if (Plugin.Instance.Configuration.DisableMessage == false && e.Session.Capabilities.SupportedCommands.Contains("DisplayMessage"))
SendMessageToClient(controlSession);
SendMessageToClient(controlSession, ((found.endTicks - found.startTicks) / TimeSpan.TicksPerSecond).ToString());

Log.Info("Skipping commercial. Session: " + session + " Start = " + found.startTicks.ToString() + " End = " + found.endTicks.ToString());
}
Expand Down Expand Up @@ -300,13 +300,17 @@ private void SkipCommercial(string sessionID, long seek)
/// Send Commercial Skipped message to client
/// </summary>
/// <param name="session"></param>
private async void SendMessageToClient(string sessionID)
private async void SendMessageToClient(string sessionID, string duration)
{
try
{
string message = "Commercial Skipped";
if (Plugin.Instance.Configuration.ShowTimeInMessage == true)
message = message + " {" + duration + " seconds)";

MessageCommand messageCommand = new MessageCommand();
messageCommand.Header = String.Empty;
messageCommand.Text = Localize.localize("Commercial Skipped", Locale);
messageCommand.Text = Localize.localize(message, Locale);
messageCommand.TimeoutMs = new long?(1000L);
await SessionManager.SendMessageCommand(sessionID, sessionID, messageCommand, CancellationToken.None);
}
Expand Down

0 comments on commit de70db2

Please sign in to comment.