using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Tasks;
namespace Emby.Server.Implementations.ScheduledTasks
{
///
/// Class ChapterImagesTask.
///
public class ChapterImagesTask : IScheduledTask
{
///
/// The _library manager.
///
private readonly ILibraryManager _libraryManager;
private readonly IItemRepository _itemRepo;
private readonly IApplicationPaths _appPaths;
private readonly IEncodingManager _encodingManager;
private readonly IFileSystem _fileSystem;
private readonly ILocalizationManager _localization;
///
/// Initializes a new instance of the class.
///
/// The library manager..
/// The item repository.
/// The application paths.
/// The encoding manager.
/// The filesystem.
/// The localization manager.
public ChapterImagesTask(
ILibraryManager libraryManager,
IItemRepository itemRepo,
IApplicationPaths appPaths,
IEncodingManager encodingManager,
IFileSystem fileSystem,
ILocalizationManager localization)
{
_libraryManager = libraryManager;
_itemRepo = itemRepo;
_appPaths = appPaths;
_encodingManager = encodingManager;
_fileSystem = fileSystem;
_localization = localization;
}
///
public string Name => _localization.GetLocalizedString("TaskRefreshChapterImages");
///
public string Description => _localization.GetLocalizedString("TaskRefreshChapterImagesDescription");
///
public string Category => _localization.GetLocalizedString("TasksLibraryCategory");
///
public string Key => "RefreshChapterImages";
///
public IEnumerable GetDefaultTriggers()
{
return new[]
{
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerDaily,
TimeOfDayTicks = TimeSpan.FromHours(2).Ticks,
MaxRuntimeTicks = TimeSpan.FromHours(4).Ticks
}
};
}
///
/// Returns the task to be executed.
///
/// The cancellation token.
/// The progress.
/// Task.
public async Task Execute(CancellationToken cancellationToken, IProgress progress)
{
var videos = _libraryManager.GetItemList(new InternalItemsQuery
{
MediaTypes = new[] { MediaType.Video },
IsFolder = false,
Recursive = true,
DtoOptions = new DtoOptions(false)
{
EnableImages = false
},
SourceTypes = new SourceType[] { SourceType.Library },
HasChapterImages = false,
IsVirtualItem = false
})
.OfType