2014-01-19 16:33:36 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Common.ScheduledTasks;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-01-20 16:09:53 +00:00
|
|
|
|
using MediaBrowser.Controller.FileOrganization;
|
2014-01-20 18:46:08 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2014-01-20 16:09:53 +00:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.FileOrganization
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
2014-01-20 16:09:53 +00:00
|
|
|
|
public class OrganizerScheduledTask : IScheduledTask, IConfigurableScheduledTask
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-01-19 16:33:36 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-01-20 16:09:53 +00:00
|
|
|
|
private readonly IFileOrganizationService _iFileSortingRepository;
|
2014-01-20 18:46:08 +00:00
|
|
|
|
private readonly IDirectoryWatchers _directoryWatchers;
|
2014-01-19 06:36:21 +00:00
|
|
|
|
|
2014-01-20 18:46:08 +00:00
|
|
|
|
public OrganizerScheduledTask(IServerConfigurationManager config, ILogger logger, ILibraryManager libraryManager, IFileSystem fileSystem, IFileOrganizationService iFileSortingRepository, IDirectoryWatchers directoryWatchers)
|
2014-01-19 06:36:21 +00:00
|
|
|
|
{
|
|
|
|
|
_config = config;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_libraryManager = libraryManager;
|
2014-01-19 16:33:36 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-01-19 18:08:17 +00:00
|
|
|
|
_iFileSortingRepository = iFileSortingRepository;
|
2014-01-20 18:46:08 +00:00
|
|
|
|
_directoryWatchers = directoryWatchers;
|
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"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
|
|
|
|
{
|
2014-01-20 18:46:08 +00:00
|
|
|
|
return new TvFileSorter(_libraryManager, _logger, _fileSystem, _iFileSortingRepository, _directoryWatchers).Sort(_config.Configuration.TvFileOrganizationOptions, cancellationToken, progress);
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
|
|
|
|
{
|
|
|
|
|
return new ITaskTrigger[]
|
|
|
|
|
{
|
|
|
|
|
new IntervalTrigger{ Interval = TimeSpan.FromMinutes(5)}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsHidden
|
|
|
|
|
{
|
2014-01-20 16:09:53 +00:00
|
|
|
|
get { return !_config.Configuration.TvFileOrganizationOptions.IsEnabled; }
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEnabled
|
|
|
|
|
{
|
2014-01-20 16:09:53 +00:00
|
|
|
|
get { return _config.Configuration.TvFileOrganizationOptions.IsEnabled; }
|
2014-01-19 06:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|