From 07072d9f7bf269926a4d7aad580e2e78c444a2cd Mon Sep 17 00:00:00 2001 From: dkanada Date: Thu, 31 Jan 2019 15:12:18 +0900 Subject: move all scheduled tasks and triggers into folders --- .../ScheduledTasks/Tasks/ChapterImagesTask.cs | 182 +++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs new file mode 100644 index 000000000..5373b4392 --- /dev/null +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs @@ -0,0 +1,182 @@ +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.IO; +using MediaBrowser.Model.Tasks; +using Microsoft.Extensions.Logging; + +namespace Emby.Server.Implementations.ScheduledTasks +{ + /// + /// Class ChapterImagesTask + /// + class ChapterImagesTask : IScheduledTask + { + /// + /// The _logger + /// + private readonly ILogger _logger; + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + private readonly IItemRepository _itemRepo; + + private readonly IApplicationPaths _appPaths; + + private readonly IEncodingManager _encodingManager; + private readonly IFileSystem _fileSystem; + + /// + /// Initializes a new instance of the class. + /// + public ChapterImagesTask(ILoggerFactory loggerFactory, ILibraryManager libraryManager, IItemRepository itemRepo, IApplicationPaths appPaths, IEncodingManager encodingManager, IFileSystem fileSystem) + { + _logger = loggerFactory.CreateLogger(GetType().Name); + _libraryManager = libraryManager; + _itemRepo = itemRepo; + _appPaths = appPaths; + _encodingManager = encodingManager; + _fileSystem = fileSystem; + } + + /// + /// Creates the triggers that define when the task will run + /// + public IEnumerable GetDefaultTriggers() + { + return new[] { + + new TaskTriggerInfo + { + Type = TaskTriggerInfo.TriggerDaily, + TimeOfDayTicks = TimeSpan.FromHours(2).Ticks, + MaxRuntimeTicks = TimeSpan.FromHours(4).Ticks + } + }; + } + + public string Key => "RefreshChapterImages"; + + /// + /// 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