2016-10-29 18:46:56 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-01-20 16:09:53 +00:00
|
|
|
|
using MediaBrowser.Controller.FileOrganization;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-20 04:53:15 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-07-31 02:09:23 +00:00
|
|
|
|
using MediaBrowser.Model.FileOrganization;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-05-26 06:48:54 +00:00
|
|
|
|
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-10-23 19:14:57 +00:00
|
|
|
|
using MediaBrowser.Model.Tasks;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
|
2016-11-03 06:37:52 +00:00
|
|
|
|
namespace Emby.Server.Implementations.FileOrganization
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
2016-10-23 19:14:57 +00:00
|
|
|
|
public class OrganizerScheduledTask : IScheduledTask, IConfigurableScheduledTask
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
2014-01-28 21:25:10 +00:00
|
|
|
|
private readonly ILibraryMonitor _libraryMonitor;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-01-22 17:05:06 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2014-01-19 16:33:36 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-01-22 17:05:06 +00:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly IFileOrganizationService _organizationService;
|
2014-02-20 04:53:15 +00:00
|
|
|
|
private readonly IProviderManager _providerManager;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
|
2014-02-20 04:53:15 +00:00
|
|
|
|
public OrganizerScheduledTask(ILibraryMonitor libraryMonitor, ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem, IServerConfigurationManager config, IFileOrganizationService organizationService, IProviderManager providerManager)
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
2014-01-28 21:25:10 +00:00
|
|
|
|
_libraryMonitor = libraryMonitor;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2014-01-22 17:05:06 +00:00
|
|
|
|
_logger = logger;
|
2014-01-19 16:33:36 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-01-22 17:05:06 +00:00
|
|
|
|
_config = config;
|
|
|
|
|
_organizationService = organizationService;
|
2014-02-20 04:53:15 +00:00
|
|
|
|
_providerManager = providerManager;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
2014-01-20 16:09:53 +00:00
|
|
|
|
get { return "Organize new media files"; }
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Description
|
|
|
|
|
{
|
2014-01-20 16:09:53 +00:00
|
|
|
|
get { return "Processes new files available in the configured watch folder."; }
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Category
|
|
|
|
|
{
|
|
|
|
|
get { return "Library"; }
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-23 04:12:46 +00:00
|
|
|
|
private AutoOrganizeOptions GetAutoOrganizeOptions()
|
2014-07-31 02:09:23 +00:00
|
|
|
|
{
|
2015-09-23 04:12:46 +00:00
|
|
|
|
return _config.GetAutoOrganizeOptions();
|
2014-07-31 02:09:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-20 21:32:48 +00:00
|
|
|
|
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
2015-09-23 04:12:46 +00:00
|
|
|
|
if (GetAutoOrganizeOptions().TvOptions.IsEnabled)
|
2015-01-20 21:32:48 +00:00
|
|
|
|
{
|
|
|
|
|
await new TvFolderOrganizer(_libraryManager, _logger, _fileSystem, _libraryMonitor, _organizationService, _config, _providerManager)
|
2015-09-23 04:12:46 +00:00
|
|
|
|
.Organize(GetAutoOrganizeOptions(), cancellationToken, progress).ConfigureAwait(false);
|
2015-01-20 21:32:48 +00:00
|
|
|
|
}
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-23 19:14:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates the triggers that define when the task will run
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
|
|
|
|
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
2016-10-23 19:14:57 +00:00
|
|
|
|
return new[] {
|
|
|
|
|
|
|
|
|
|
// Every so often
|
2016-11-20 20:20:01 +00:00
|
|
|
|
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(5).Ticks}
|
2016-10-23 19:14:57 +00:00
|
|
|
|
};
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsHidden
|
|
|
|
|
{
|
2015-09-23 04:12:46 +00:00
|
|
|
|
get { return !GetAutoOrganizeOptions().TvOptions.IsEnabled; }
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEnabled
|
|
|
|
|
{
|
2015-09-23 04:12:46 +00:00
|
|
|
|
get { return GetAutoOrganizeOptions().TvOptions.IsEnabled; }
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
2014-08-10 22:13:17 +00:00
|
|
|
|
|
2016-10-23 19:14:57 +00:00
|
|
|
|
public bool IsLogged
|
2014-08-10 22:13:17 +00:00
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
2015-01-20 20:19:54 +00:00
|
|
|
|
|
|
|
|
|
public string Key
|
|
|
|
|
{
|
|
|
|
|
get { return "AutoOrganize"; }
|
|
|
|
|
}
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|