mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-27 20:41:54 +00:00
#680 - file organization
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
using MediaBrowser.Controller.FileOrganization;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.FileOrganization;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
return _repo.SaveResult(result, cancellationToken);
|
||||
}
|
||||
|
||||
public IEnumerable<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
|
||||
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
|
||||
{
|
||||
return _repo.GetResults(query);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.FileOrganization;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
@@ -18,14 +19,16 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IFileOrganizationService _iFileSortingRepository;
|
||||
private readonly IDirectoryWatchers _directoryWatchers;
|
||||
|
||||
public OrganizerScheduledTask(IServerConfigurationManager config, ILogger logger, ILibraryManager libraryManager, IFileSystem fileSystem, IFileOrganizationService iFileSortingRepository)
|
||||
public OrganizerScheduledTask(IServerConfigurationManager config, ILogger logger, ILibraryManager libraryManager, IFileSystem fileSystem, IFileOrganizationService iFileSortingRepository, IDirectoryWatchers directoryWatchers)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_libraryManager = libraryManager;
|
||||
_fileSystem = fileSystem;
|
||||
_iFileSortingRepository = iFileSortingRepository;
|
||||
_directoryWatchers = directoryWatchers;
|
||||
}
|
||||
|
||||
public string Name
|
||||
@@ -45,7 +48,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
|
||||
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
return new TvFileSorter(_libraryManager, _logger, _fileSystem, _iFileSortingRepository).Sort(_config.Configuration.TvFileOrganizationOptions, cancellationToken, progress);
|
||||
return new TvFileSorter(_libraryManager, _logger, _fileSystem, _iFileSortingRepository, _directoryWatchers).Sort(_config.Configuration.TvFileOrganizationOptions, cancellationToken, progress);
|
||||
}
|
||||
|
||||
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.FileOrganization;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
@@ -24,15 +25,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
private readonly ILogger _logger;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IFileOrganizationService _iFileSortingRepository;
|
||||
private readonly IDirectoryWatchers _directoryWatchers;
|
||||
|
||||
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
public TvFileSorter(ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem, IFileOrganizationService iFileSortingRepository)
|
||||
public TvFileSorter(ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem, IFileOrganizationService iFileSortingRepository, IDirectoryWatchers directoryWatchers)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_logger = logger;
|
||||
_fileSystem = fileSystem;
|
||||
_iFileSortingRepository = iFileSortingRepository;
|
||||
_directoryWatchers = directoryWatchers;
|
||||
}
|
||||
|
||||
public async Task Sort(TvFileOrganizationOptions options, CancellationToken cancellationToken, IProgress<double> progress)
|
||||
@@ -48,6 +51,8 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
|
||||
progress.Report(10);
|
||||
|
||||
var scanLibrary = false;
|
||||
|
||||
if (eligibleFiles.Count > 0)
|
||||
{
|
||||
var allSeries = _libraryManager.RootFolder
|
||||
@@ -59,7 +64,12 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
|
||||
foreach (var file in eligibleFiles)
|
||||
{
|
||||
await SortFile(file.FullName, options, allSeries).ConfigureAwait(false);
|
||||
var result = await SortFile(file.FullName, options, allSeries).ConfigureAwait(false);
|
||||
|
||||
if (result.Status == FileSortingStatus.Success)
|
||||
{
|
||||
scanLibrary = true;
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
@@ -88,6 +98,12 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
}
|
||||
}
|
||||
|
||||
if (scanLibrary)
|
||||
{
|
||||
await _libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
@@ -118,7 +134,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="options">The options.</param>
|
||||
/// <param name="allSeries">All series.</param>
|
||||
private Task SortFile(string path, TvFileOrganizationOptions options, IEnumerable<Series> allSeries)
|
||||
private async Task<FileOrganizationResult> SortFile(string path, TvFileOrganizationOptions options, IEnumerable<Series> allSeries)
|
||||
{
|
||||
_logger.Info("Sorting file {0}", path);
|
||||
|
||||
@@ -169,7 +185,9 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
_logger.Warn(msg);
|
||||
}
|
||||
|
||||
return LogResult(result);
|
||||
await LogResult(result).ConfigureAwait(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -236,6 +254,8 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
/// <param name="copy">if set to <c>true</c> [copy].</param>
|
||||
private void PerformFileSorting(TvFileOrganizationOptions options, FileOrganizationResult result, bool copy)
|
||||
{
|
||||
_directoryWatchers.TemporarilyIgnore(result.TargetPath);
|
||||
|
||||
try
|
||||
{
|
||||
if (copy)
|
||||
@@ -250,11 +270,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorMsg = string.Format("Failed to move file from {0} to {1}", result.OriginalPath, result.TargetPath);
|
||||
|
||||
result.Status = FileSortingStatus.Failure;
|
||||
result.ErrorMessage = errorMsg;
|
||||
_logger.ErrorException(errorMsg, ex);
|
||||
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_directoryWatchers.RemoveTempIgnore(result.TargetPath);
|
||||
}
|
||||
|
||||
if (copy)
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.FileOrganization;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -62,9 +62,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public IEnumerable<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
|
||||
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
|
||||
{
|
||||
return new List<FileOrganizationResult>();
|
||||
return new QueryResult<FileOrganizationResult>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user