-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e67a4f
commit 3cc9a66
Showing
6 changed files
with
257 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediaBrowser.Controller.Library; | ||
using MediaBrowser.Model.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace ConfusedPolarBear.Plugin.IntroSkipper; | ||
|
||
/// <summary> | ||
/// Analyze all television episodes for credits. | ||
/// TODO: analyze all media files. | ||
/// </summary> | ||
public class DetectCreditsTask : IScheduledTask | ||
{ | ||
private readonly ILogger<DetectCreditsTask> _logger; | ||
|
||
private readonly ILoggerFactory _loggerFactory; | ||
|
||
private readonly ILibraryManager _libraryManager; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DetectCreditsTask"/> class. | ||
/// </summary> | ||
/// <param name="loggerFactory">Logger factory.</param> | ||
/// <param name="libraryManager">Library manager.</param> | ||
/// <param name="logger">Logger.</param> | ||
public DetectCreditsTask( | ||
ILogger<DetectCreditsTask> logger, | ||
ILoggerFactory loggerFactory, | ||
ILibraryManager libraryManager) | ||
{ | ||
_logger = logger; | ||
_loggerFactory = loggerFactory; | ||
_libraryManager = libraryManager; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the task name. | ||
/// </summary> | ||
public string Name => "Detect Credits"; | ||
|
||
/// <summary> | ||
/// Gets the task category. | ||
/// </summary> | ||
public string Category => "Intro Skipper"; | ||
|
||
/// <summary> | ||
/// Gets the task description. | ||
/// </summary> | ||
public string Description => "Analyzes the audio and video of all television episodes to find credits."; | ||
|
||
/// <summary> | ||
/// Gets the task key. | ||
/// </summary> | ||
public string Key => "CPBIntroSkipperDetectCredits"; | ||
|
||
/// <summary> | ||
/// Analyze all episodes in the queue. Only one instance of this task should be run at a time. | ||
/// </summary> | ||
/// <param name="progress">Task progress.</param> | ||
/// <param name="cancellationToken">Cancellation token.</param> | ||
/// <returns>Task.</returns> | ||
public Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken) | ||
{ | ||
if (_libraryManager is null) | ||
{ | ||
throw new InvalidOperationException("Library manager was null"); | ||
} | ||
|
||
// abort if analyzer is already running | ||
if (Plugin.Instance!.AnalyzerTaskIsRunning) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
else | ||
{ | ||
Plugin.Instance!.AnalyzerTaskIsRunning = true; | ||
} | ||
|
||
var baseCreditAnalyzer = new BaseItemAnalyzerTask( | ||
AnalysisMode.Credits, | ||
_loggerFactory.CreateLogger<DetectCreditsTask>(), | ||
_loggerFactory, | ||
_libraryManager); | ||
|
||
baseCreditAnalyzer.AnalyzeItems(progress, cancellationToken); | ||
|
||
Plugin.Instance!.AnalyzerTaskIsRunning = false; | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
/// <summary> | ||
/// Get task triggers. | ||
/// </summary> | ||
/// <returns>Task triggers.</returns> | ||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() | ||
{ | ||
return Array.Empty<TaskTriggerInfo>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.