Skip to content

Commit

Permalink
Auto-Detection Configuration (#106)
Browse files Browse the repository at this point in the history
* Update Entrypoint.cs

* Update Entrypoint.cs

* Update Entrypoint.cs

* Update Entrypoint.cs
  • Loading branch information
rlauuzo authored and AbandonedCart committed Apr 10, 2024
1 parent 6c30244 commit d5ac3ab
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ public class Entrypoint : IServerEntryPoint
/// <returns>Task.</returns>
public Task RunAsync()
{
if (Plugin.Instance!.Configuration.AutoDetectIntros || Plugin.Instance!.Configuration.AutoDetectCredits)
{
_libraryManager.ItemAdded += OnItemAdded;
_libraryManager.ItemUpdated += OnItemModified;
_taskManager.TaskCompleted += OnLibraryRefresh;
}
_libraryManager.ItemAdded += OnItemAdded;
_libraryManager.ItemUpdated += OnItemModified;
_taskManager.TaskCompleted += OnLibraryRefresh;

FFmpegWrapper.Logger = _logger;

Expand Down Expand Up @@ -97,6 +94,12 @@ public Task RunAsync()
/// <param name="itemChangeEventArgs">The <see cref="ItemChangeEventArgs"/>.</param>
private void OnItemAdded(object? sender, ItemChangeEventArgs itemChangeEventArgs)
{
// Don't do anything if auto detection is disabled
if (!Plugin.Instance!.Configuration.AutoDetectIntros && !Plugin.Instance!.Configuration.AutoDetectCredits)
{
return;
}

// Don't do anything if it's not a supported media type
if (itemChangeEventArgs.Item is not Episode)
{
Expand All @@ -118,6 +121,12 @@ private void OnItemAdded(object? sender, ItemChangeEventArgs itemChangeEventArgs
/// <param name="itemChangeEventArgs">The <see cref="ItemChangeEventArgs"/>.</param>
private void OnItemModified(object? sender, ItemChangeEventArgs itemChangeEventArgs)
{
// Don't do anything if auto detection is disabled
if (!Plugin.Instance!.Configuration.AutoDetectIntros && !Plugin.Instance!.Configuration.AutoDetectCredits)
{
return;
}

// Don't do anything if it's not a supported media type
if (itemChangeEventArgs.Item is not Episode)
{
Expand All @@ -139,6 +148,12 @@ private void OnItemModified(object? sender, ItemChangeEventArgs itemChangeEventA
/// <param name="eventArgs">The <see cref="TaskCompletionEventArgs"/>.</param>
private void OnLibraryRefresh(object? sender, TaskCompletionEventArgs eventArgs)
{
// Don't do anything if auto detection is disabled
if (!Plugin.Instance!.Configuration.AutoDetectIntros && !Plugin.Instance!.Configuration.AutoDetectCredits)
{
return;
}

var result = eventArgs.Result;

if (result.Key != "RefreshLibrary")
Expand Down

0 comments on commit d5ac3ab

Please sign in to comment.