2013-07-19 03:47:55 +00:00
|
|
|
|
using System.IO;
|
2013-07-15 23:53:06 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|
|
|
|
{
|
|
|
|
|
public class NotExistingFileSpecification : IImportDecisionEngineSpecification
|
|
|
|
|
{
|
2013-07-22 06:31:51 +00:00
|
|
|
|
private readonly IMediaFileService _mediaFileService;
|
2013-07-15 23:53:06 +00:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2013-07-22 06:31:51 +00:00
|
|
|
|
public NotExistingFileSpecification(IMediaFileService mediaFileService, Logger logger)
|
2013-07-15 23:53:06 +00:00
|
|
|
|
{
|
2013-07-22 06:31:51 +00:00
|
|
|
|
_mediaFileService = mediaFileService;
|
2013-07-15 23:53:06 +00:00
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string RejectionReason { get { return "Existing File"; } }
|
|
|
|
|
|
|
|
|
|
public bool IsSatisfiedBy(LocalEpisode localEpisode)
|
|
|
|
|
{
|
2013-07-22 06:31:51 +00:00
|
|
|
|
// if (_mediaFileService.Exists(localEpisode.Path))
|
|
|
|
|
// {
|
|
|
|
|
// _logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
2013-07-15 23:53:06 +00:00
|
|
|
|
|
2013-07-22 06:31:51 +00:00
|
|
|
|
var existingFiles = localEpisode.Episodes.Where(e => e.EpisodeFileId > 0).Select(e => e.EpisodeFile.Value);
|
|
|
|
|
|
|
|
|
|
foreach (var existingFile in existingFiles)
|
2013-07-15 23:53:06 +00:00
|
|
|
|
{
|
2013-07-22 06:31:51 +00:00
|
|
|
|
if (Path.GetFileName(existingFile.Path) == Path.GetFileName(localEpisode.Path) &&
|
|
|
|
|
existingFile.Size == localEpisode.Size)
|
2013-07-15 23:53:06 +00:00
|
|
|
|
{
|
|
|
|
|
_logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-22 06:31:51 +00:00
|
|
|
|
|
|
|
|
|
_logger.Trace("Existing filename: {0} size: {1}", Path.GetFileName(existingFile.Path), existingFile.Size);
|
|
|
|
|
_logger.Trace("New filename: {0} size: {1}", Path.GetFileName(localEpisode.Path), localEpisode.Size);
|
2013-07-15 23:53:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|