You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.9 KiB
84 lines
2.9 KiB
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using NLog;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Extras.Files;
|
|
using NzbDrone.Core.Parser;
|
|
using NzbDrone.Core.Tv;
|
|
|
|
namespace NzbDrone.Core.Extras.Others
|
|
{
|
|
public class ExistingOtherExtraImporter : ImportExistingExtraFilesBase<OtherExtraFile>
|
|
{
|
|
private readonly IExtraFileService<OtherExtraFile> _otherExtraFileService;
|
|
private readonly IParsingService _parsingService;
|
|
private readonly Logger _logger;
|
|
|
|
public ExistingOtherExtraImporter(IExtraFileService<OtherExtraFile> otherExtraFileService,
|
|
IParsingService parsingService,
|
|
Logger logger)
|
|
: base(otherExtraFileService)
|
|
{
|
|
_otherExtraFileService = otherExtraFileService;
|
|
_parsingService = parsingService;
|
|
_logger = logger;
|
|
}
|
|
|
|
public override int Order
|
|
{
|
|
get
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
public override IEnumerable<ExtraFile> ProcessFiles(Series series, List<string> filesOnDisk, List<string> importedFiles)
|
|
{
|
|
_logger.Debug("Looking for existing extra files in {0}", series.Path);
|
|
|
|
var extraFiles = new List<OtherExtraFile>();
|
|
var filteredFiles = FilterAndClean(series, filesOnDisk, importedFiles);
|
|
|
|
foreach (var possibleExtraFile in filteredFiles)
|
|
{
|
|
var localEpisode = _parsingService.GetLocalEpisode(possibleExtraFile, series);
|
|
|
|
if (localEpisode == null)
|
|
{
|
|
_logger.Debug("Unable to parse extra file: {0}", possibleExtraFile);
|
|
continue;
|
|
}
|
|
|
|
if (localEpisode.Episodes.Empty())
|
|
{
|
|
_logger.Debug("Cannot find related episodes for: {0}", possibleExtraFile);
|
|
continue;
|
|
}
|
|
|
|
if (localEpisode.Episodes.DistinctBy(e => e.EpisodeFileId).Count() > 1)
|
|
{
|
|
_logger.Debug("Extra file: {0} does not match existing files.", possibleExtraFile);
|
|
continue;
|
|
}
|
|
|
|
var extraFile = new OtherExtraFile
|
|
{
|
|
SeriesId = series.Id,
|
|
SeasonNumber = localEpisode.SeasonNumber,
|
|
EpisodeFileId = localEpisode.Episodes.First().EpisodeFileId,
|
|
RelativePath = series.Path.GetRelativePath(possibleExtraFile),
|
|
Extension = Path.GetExtension(possibleExtraFile)
|
|
};
|
|
|
|
extraFiles.Add(extraFile);
|
|
}
|
|
|
|
_logger.Info("Found {0} existing other extra files", extraFiles.Count);
|
|
_otherExtraFileService.Upsert(extraFiles);
|
|
|
|
return extraFiles;
|
|
}
|
|
}
|
|
}
|