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;
///
/// Analyze all television episodes for introduction sequences.
///
public class DetectIntroductionsTask : IScheduledTask
{
private readonly ILoggerFactory _loggerFactory;
private readonly ILibraryManager _libraryManager;
///
/// Initializes a new instance of the class.
///
/// Logger factory.
/// Library manager.
public DetectIntroductionsTask(
ILoggerFactory loggerFactory,
ILibraryManager libraryManager)
{
_loggerFactory = loggerFactory;
_libraryManager = libraryManager;
}
///
/// Gets the task name.
///
public string Name => "Detect Introductions";
///
/// Gets the task category.
///
public string Category => "Intro Skipper";
///
/// Gets the task description.
///
public string Description => "Analyzes the audio of all television episodes to find introduction sequences.";
///
/// Gets the task key.
///
public string Key => "CPBIntroSkipperDetectIntroductions";
///
/// Analyze all episodes in the queue. Only one instance of this task should be run at a time.
///
/// Task progress.
/// Cancellation token.
/// Task.
public Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken)
{
if (_libraryManager is null)
{
throw new InvalidOperationException("Library manager was null");
}
var baseAnalyzer = new BaseItemAnalyzerTask(
AnalysisMode.Introduction,
_loggerFactory.CreateLogger(),
_loggerFactory,
_libraryManager);
baseAnalyzer.AnalyzeItems(progress, cancellationToken);
return Task.CompletedTask;
}
///
/// Get task triggers.
///
/// Task triggers.
public IEnumerable GetDefaultTriggers()
{
return new[]
{
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerDaily,
TimeOfDayTicks = TimeSpan.FromHours(0).Ticks
}
};
}
}