jellyfin/MediaBrowser.Server.Implementations/FileOrganization/OrganizerScheduledTask.cs

95 lines
3.1 KiB
C#
Raw Normal View History

2016-03-27 14:11:27 -07:00
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.FileOrganization;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
2014-07-30 19:09:23 -07:00
using MediaBrowser.Model.FileOrganization;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
2015-10-03 21:23:11 -07:00
using CommonIO;
namespace MediaBrowser.Server.Implementations.FileOrganization
{
2015-01-20 13:19:54 -07:00
public class OrganizerScheduledTask : IScheduledTask, IConfigurableScheduledTask, IScheduledTaskActivityLog, IHasKey
{
private readonly ILibraryMonitor _libraryMonitor;
private readonly ILibraryManager _libraryManager;
2014-01-22 10:05:06 -07:00
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
2014-01-22 10:05:06 -07:00
private readonly IServerConfigurationManager _config;
private readonly IFileOrganizationService _organizationService;
private readonly IProviderManager _providerManager;
public OrganizerScheduledTask(ILibraryMonitor libraryMonitor, ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem, IServerConfigurationManager config, IFileOrganizationService organizationService, IProviderManager providerManager)
{
_libraryMonitor = libraryMonitor;
_libraryManager = libraryManager;
2014-01-22 10:05:06 -07:00
_logger = logger;
_fileSystem = fileSystem;
2014-01-22 10:05:06 -07:00
_config = config;
_organizationService = organizationService;
_providerManager = providerManager;
}
public string Name
{
get { return "Organize new media files"; }
}
public string Description
{
get { return "Processes new files available in the configured watch folder."; }
}
public string Category
{
get { return "Library"; }
}
private AutoOrganizeOptions GetAutoOrganizeOptions()
2014-07-30 19:09:23 -07:00
{
return _config.GetAutoOrganizeOptions();
2014-07-30 19:09:23 -07:00
}
2015-01-20 14:32:48 -07:00
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
if (GetAutoOrganizeOptions().TvOptions.IsEnabled)
2015-01-20 14:32:48 -07:00
{
await new TvFolderOrganizer(_libraryManager, _logger, _fileSystem, _libraryMonitor, _organizationService, _config, _providerManager)
.Organize(GetAutoOrganizeOptions(), cancellationToken, progress).ConfigureAwait(false);
2015-01-20 14:32:48 -07:00
}
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger{ Interval = TimeSpan.FromMinutes(5)}
};
}
public bool IsHidden
{
get { return !GetAutoOrganizeOptions().TvOptions.IsEnabled; }
}
public bool IsEnabled
{
get { return GetAutoOrganizeOptions().TvOptions.IsEnabled; }
}
2014-08-10 15:13:17 -07:00
public bool IsActivityLogged
{
get { return false; }
}
2015-01-20 13:19:54 -07:00
public string Key
{
get { return "AutoOrganize"; }
}
}
}