mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
Do not import episodes with the same filename and size
This commit is contained in:
parent
89b43836d0
commit
8dacd076d8
7 changed files with 178 additions and 11 deletions
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
@ -21,12 +22,17 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
{
|
||||
private readonly IEnumerable<IRejectWithReason> _specifications;
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ImportDecisionMaker(IEnumerable<IRejectWithReason> specifications, IParsingService parsingService, Logger logger)
|
||||
public ImportDecisionMaker(IEnumerable<IRejectWithReason> specifications,
|
||||
IParsingService parsingService,
|
||||
IDiskProvider diskProvider,
|
||||
Logger logger)
|
||||
{
|
||||
_specifications = specifications;
|
||||
_parsingService = parsingService;
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
@ -44,9 +50,10 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
try
|
||||
{
|
||||
var parsedEpisode = _parsingService.GetEpisodes(file, series);
|
||||
|
||||
|
||||
if (parsedEpisode != null)
|
||||
{
|
||||
parsedEpisode.Size = _diskProvider.GetFileSize(file);
|
||||
decision = GetDecision(parsedEpisode);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
||||
{
|
||||
public class NotExistingFileSpecification : IImportDecisionEngineSpecification
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public NotExistingFileSpecification(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string RejectionReason { get { return "Existing File"; } }
|
||||
|
||||
public bool IsSatisfiedBy(LocalEpisode localEpisode)
|
||||
{
|
||||
var episodeFiles = localEpisode.Episodes.Where(e => e.EpisodeFileId > 0).Select(e => e.EpisodeFile.Value);
|
||||
|
||||
foreach (var episodeFile in episodeFiles)
|
||||
{
|
||||
if (Path.GetFileName(episodeFile.Path) == Path.GetFileName(localEpisode.Path) &&
|
||||
episodeFile.Size == localEpisode.Size)
|
||||
{
|
||||
_logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,10 +39,9 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|||
return true;
|
||||
}
|
||||
|
||||
var size = _diskProvider.GetFileSize(localEpisode.Path);
|
||||
var runTime = _videoFileInfoReader.GetRunTime(localEpisode.Path);
|
||||
|
||||
if (size < Constants.IgnoreFileSize && runTime.TotalMinutes < 3)
|
||||
if (localEpisode.Size < Constants.IgnoreFileSize && runTime.TotalMinutes < 3)
|
||||
{
|
||||
_logger.Trace("[{0}] appears to be a sample.", localEpisode.Path);
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue