using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
///
/// Class ChapterImagesTask
///
class ChapterImagesTask : IScheduledTask
{
///
/// The _logger
///
private readonly ILogger _logger;
///
/// The _library manager
///
private readonly ILibraryManager _libraryManager;
///
/// The current new item timer
///
/// The new item timer.
private Timer NewItemTimer { get; set; }
private readonly IItemRepository _itemRepo;
private readonly IApplicationPaths _appPaths;
private readonly IEncodingManager _encodingManager;
private readonly IFileSystem _fileSystem;
///
/// Initializes a new instance of the class.
///
/// The log manager.
/// The library manager.
/// The item repo.
public ChapterImagesTask(ILogManager logManager, ILibraryManager libraryManager, IItemRepository itemRepo, IApplicationPaths appPaths, IEncodingManager encodingManager, IFileSystem fileSystem)
{
_logger = logManager.GetLogger(GetType().Name);
_libraryManager = libraryManager;
_itemRepo = itemRepo;
_appPaths = appPaths;
_encodingManager = encodingManager;
_fileSystem = fileSystem;
}
///
/// Creates the triggers that define when the task will run
///
/// IEnumerable{BaseTaskTrigger}.
public IEnumerable GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new DailyTrigger
{
TimeOfDay = TimeSpan.FromHours(1),
TaskOptions = new TaskExecutionOptions
{
MaxRuntimeMs = Convert.ToInt32(TimeSpan.FromHours(4).TotalMilliseconds)
}
}
};
}
///
/// Returns the task to be executed
///
/// The cancellation token.
/// The progress.
/// Task.
public async Task Execute(CancellationToken cancellationToken, IProgress progress)
{
var videos = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Video)
.Cast