parent
2bf1ce1763
commit
f26540cdc7
|
@ -12,6 +12,7 @@ using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.MediaFiles.Commands;
|
using NzbDrone.Core.MediaFiles.Commands;
|
||||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||||
using NzbDrone.Core.MediaFiles.Events;
|
using NzbDrone.Core.MediaFiles.Events;
|
||||||
|
using NzbDrone.Core.MediaFiles.MediaInfo;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.RootFolders;
|
using NzbDrone.Core.RootFolders;
|
||||||
|
@ -36,8 +37,10 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
private readonly IImportApprovedEpisodes _importApprovedEpisodes;
|
private readonly IImportApprovedEpisodes _importApprovedEpisodes;
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
private readonly ISeriesService _seriesService;
|
private readonly ISeriesService _seriesService;
|
||||||
|
private readonly IMediaFileService _mediaFileService;
|
||||||
private readonly IMediaFileTableCleanupService _mediaFileTableCleanupService;
|
private readonly IMediaFileTableCleanupService _mediaFileTableCleanupService;
|
||||||
private readonly IRootFolderService _rootFolderService;
|
private readonly IRootFolderService _rootFolderService;
|
||||||
|
private readonly IUpdateMediaInfo _updateMediaInfoService;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
@ -46,8 +49,10 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
IImportApprovedEpisodes importApprovedEpisodes,
|
IImportApprovedEpisodes importApprovedEpisodes,
|
||||||
IConfigService configService,
|
IConfigService configService,
|
||||||
ISeriesService seriesService,
|
ISeriesService seriesService,
|
||||||
|
IMediaFileService mediaFileService,
|
||||||
IMediaFileTableCleanupService mediaFileTableCleanupService,
|
IMediaFileTableCleanupService mediaFileTableCleanupService,
|
||||||
IRootFolderService rootFolderService,
|
IRootFolderService rootFolderService,
|
||||||
|
IUpdateMediaInfo updateMediaInfoService,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
|
@ -56,8 +61,10 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
_importApprovedEpisodes = importApprovedEpisodes;
|
_importApprovedEpisodes = importApprovedEpisodes;
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
_seriesService = seriesService;
|
_seriesService = seriesService;
|
||||||
|
_mediaFileService = mediaFileService;
|
||||||
_mediaFileTableCleanupService = mediaFileTableCleanupService;
|
_mediaFileTableCleanupService = mediaFileTableCleanupService;
|
||||||
_rootFolderService = rootFolderService;
|
_rootFolderService = rootFolderService;
|
||||||
|
_updateMediaInfoService = updateMediaInfoService;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
@ -124,12 +131,44 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
|
|
||||||
CleanMediaFiles(series, mediaFileList);
|
CleanMediaFiles(series, mediaFileList);
|
||||||
|
|
||||||
|
var seriesFiles = _mediaFileService.GetFilesBySeries(series.Id);
|
||||||
|
var unmappedFiles = MediaFileService.FilterExistingFiles(mediaFileList, seriesFiles, series);
|
||||||
|
|
||||||
var decisionsStopwatch = Stopwatch.StartNew();
|
var decisionsStopwatch = Stopwatch.StartNew();
|
||||||
var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, series);
|
var decisions = _importDecisionMaker.GetImportDecisions(unmappedFiles, series, false);
|
||||||
decisionsStopwatch.Stop();
|
decisionsStopwatch.Stop();
|
||||||
_logger.Trace("Import decisions complete for: {0} [{1}]", series, decisionsStopwatch.Elapsed);
|
_logger.Trace("Import decisions complete for: {0} [{1}]", series, decisionsStopwatch.Elapsed);
|
||||||
_importApprovedEpisodes.Import(decisions, false);
|
_importApprovedEpisodes.Import(decisions, false);
|
||||||
|
|
||||||
|
// Update existing files that have a different file size
|
||||||
|
|
||||||
|
var fileInfoStopwatch = Stopwatch.StartNew();
|
||||||
|
var filesToUpdate = new List<EpisodeFile>();
|
||||||
|
|
||||||
|
foreach (var file in seriesFiles)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(series.Path, file.RelativePath);
|
||||||
|
var fileSize = _diskProvider.GetFileSize(path);
|
||||||
|
|
||||||
|
if (file.Size == fileSize) continue;
|
||||||
|
|
||||||
|
file.Size = fileSize;
|
||||||
|
|
||||||
|
if (!_updateMediaInfoService.Update(file, series))
|
||||||
|
{
|
||||||
|
filesToUpdate.Add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update any files that had a file size change, but didn't get media info updated.
|
||||||
|
if (filesToUpdate.Any())
|
||||||
|
{
|
||||||
|
_mediaFileService.Update(filesToUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileInfoStopwatch.Stop();
|
||||||
|
_logger.Trace("Reprocessing existing files complete for: {0} [{1}]", series, decisionsStopwatch.Elapsed);
|
||||||
|
|
||||||
RemoveEmptySeriesFolder(series.Path);
|
RemoveEmptySeriesFolder(series.Path);
|
||||||
CompletedScanning(series);
|
CompletedScanning(series);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
||||||
public interface IMakeImportDecision
|
public interface IMakeImportDecision
|
||||||
{
|
{
|
||||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series);
|
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series);
|
||||||
|
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, bool filterExistingFiles);
|
||||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, DownloadClientItem downloadClientItem, ParsedEpisodeInfo folderInfo, bool sceneSource);
|
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, DownloadClientItem downloadClientItem, ParsedEpisodeInfo folderInfo, bool sceneSource);
|
||||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, DownloadClientItem downloadClientItem, ParsedEpisodeInfo folderInfo, bool sceneSource, bool filterExistingFiles);
|
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, DownloadClientItem downloadClientItem, ParsedEpisodeInfo folderInfo, bool sceneSource, bool filterExistingFiles);
|
||||||
ImportDecision GetDecision(LocalEpisode localEpisode, DownloadClientItem downloadClientItem);
|
ImportDecision GetDecision(LocalEpisode localEpisode, DownloadClientItem downloadClientItem);
|
||||||
|
@ -46,7 +47,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
||||||
|
|
||||||
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series)
|
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series)
|
||||||
{
|
{
|
||||||
return GetImportDecisions(videoFiles, series, null, null, false);
|
return GetImportDecisions(videoFiles, series, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, bool filterExistingFiles)
|
||||||
|
{
|
||||||
|
return GetImportDecisions(videoFiles, series, null, null, false, filterExistingFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, DownloadClientItem downloadClientItem, ParsedEpisodeInfo folderInfo, bool sceneSource)
|
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, DownloadClientItem downloadClientItem, ParsedEpisodeInfo folderInfo, bool sceneSource)
|
||||||
|
|
|
@ -12,10 +12,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
||||||
{
|
{
|
||||||
public interface IUpdateMediaInfo
|
public interface IUpdateMediaInfo
|
||||||
{
|
{
|
||||||
void Update(EpisodeFile episodeFile, Series series);
|
bool Update(EpisodeFile episodeFile, Series series);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpdateMediaInfoService : IHandle<SeriesScannedEvent>, IUpdateMediaInfo
|
public class UpdateMediaInfoService : IUpdateMediaInfo, IHandle<SeriesScannedEvent>
|
||||||
{
|
{
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
private readonly IMediaFileService _mediaFileService;
|
private readonly IMediaFileService _mediaFileService;
|
||||||
|
@ -55,34 +55,37 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(EpisodeFile episodeFile, Series series)
|
public bool Update(EpisodeFile episodeFile, Series series)
|
||||||
{
|
{
|
||||||
if (!_configService.EnableMediaInfo)
|
if (!_configService.EnableMediaInfo)
|
||||||
{
|
{
|
||||||
_logger.Debug("MediaInfo is disabled");
|
_logger.Debug("MediaInfo is disabled");
|
||||||
return;
|
return false;
|
||||||
}
|
|
||||||
UpdateMediaInfo(episodeFile, series);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateMediaInfo(EpisodeFile episodeFile, Series series)
|
return UpdateMediaInfo(episodeFile, series);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool UpdateMediaInfo(EpisodeFile episodeFile, Series series)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(series.Path, episodeFile.RelativePath);
|
var path = Path.Combine(series.Path, episodeFile.RelativePath);
|
||||||
|
|
||||||
if (!_diskProvider.FileExists(path))
|
if (!_diskProvider.FileExists(path))
|
||||||
{
|
{
|
||||||
_logger.Debug("Can't update MediaInfo because '{0}' does not exist", path);
|
_logger.Debug("Can't update MediaInfo because '{0}' does not exist", path);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var updatedMediaInfo = _videoFileInfoReader.GetMediaInfo(path);
|
var updatedMediaInfo = _videoFileInfoReader.GetMediaInfo(path);
|
||||||
|
|
||||||
if (updatedMediaInfo != null)
|
if (updatedMediaInfo == null) return false;
|
||||||
{
|
|
||||||
episodeFile.MediaInfo = updatedMediaInfo;
|
episodeFile.MediaInfo = updatedMediaInfo;
|
||||||
_mediaFileService.Update(episodeFile);
|
_mediaFileService.Update(episodeFile);
|
||||||
_logger.Debug("Updated MediaInfo for '{0}'", path);
|
_logger.Debug("Updated MediaInfo for '{0}'", path);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue