2018-02-15 12:39:01 +00:00
|
|
|
using System.Collections.Generic;
|
2015-12-25 09:22:00 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.MediaFiles.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2023-11-19 18:52:37 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2015-12-25 09:22:00 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Extras
|
|
|
|
{
|
2023-11-19 18:52:37 +00:00
|
|
|
public interface IExistingExtraFiles
|
|
|
|
{
|
|
|
|
List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ExistingExtraFileService : IExistingExtraFiles, IHandle<MovieScannedEvent>
|
2015-12-25 09:22:00 +00:00
|
|
|
{
|
|
|
|
private readonly List<IImportExistingExtraFiles> _existingExtraFileImporters;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2023-11-19 18:52:37 +00:00
|
|
|
public ExistingExtraFileService(IEnumerable<IImportExistingExtraFiles> existingExtraFileImporters,
|
2015-12-25 09:22:00 +00:00
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
_existingExtraFileImporters = existingExtraFileImporters.OrderBy(e => e.Order).ToList();
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2023-11-19 18:52:37 +00:00
|
|
|
public List<string> ImportExtraFiles(Movie movie, List<string> possibleExtraFiles)
|
2015-12-25 09:22:00 +00:00
|
|
|
{
|
2018-02-15 12:39:01 +00:00
|
|
|
_logger.Debug("Looking for existing extra files in {0}", movie.Path);
|
2015-12-25 09:22:00 +00:00
|
|
|
|
|
|
|
var importedFiles = new List<string>();
|
|
|
|
|
|
|
|
foreach (var existingExtraFileImporter in _existingExtraFileImporters)
|
|
|
|
{
|
2022-04-12 01:18:02 +00:00
|
|
|
var imported = existingExtraFileImporter.ProcessFiles(movie, possibleExtraFiles, importedFiles);
|
2015-12-25 09:22:00 +00:00
|
|
|
|
2018-02-15 12:39:01 +00:00
|
|
|
importedFiles.AddRange(imported.Select(f => Path.Combine(movie.Path, f.RelativePath)));
|
2015-12-25 09:22:00 +00:00
|
|
|
}
|
|
|
|
|
2023-11-19 18:52:37 +00:00
|
|
|
return importedFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Handle(MovieScannedEvent message)
|
|
|
|
{
|
|
|
|
var movie = message.Movie;
|
|
|
|
var possibleExtraFiles = message.PossibleExtraFiles;
|
|
|
|
var importedFiles = ImportExtraFiles(movie, possibleExtraFiles);
|
|
|
|
|
2022-04-12 01:18:02 +00:00
|
|
|
_logger.Info("Found {0} possible extra files, imported {1} files.", possibleExtraFiles.Count, importedFiles.Count);
|
2015-12-25 09:22:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|