mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
EpisodeFile cleanup and deletion fixes
Upgraded episodes will no longer be auto unmonitored EpsiodeFiles will be removed from db if parsing rules have changed EpisodeFiles will be removed from db if they are not in their series' folder (or subfolder)
This commit is contained in:
parent
19fc3bad6c
commit
4c1e6e14aa
11 changed files with 145 additions and 49 deletions
|
@ -20,11 +20,11 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|||
|
||||
public bool IsSatisfiedBy(LocalEpisode localEpisode)
|
||||
{
|
||||
// if (_mediaFileService.Exists(localEpisode.Path))
|
||||
// {
|
||||
// _logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
|
||||
// return false;
|
||||
// }
|
||||
if (_mediaFileService.Exists(localEpisode.Path))
|
||||
{
|
||||
_logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
|
||||
return false;
|
||||
}
|
||||
|
||||
var existingFiles = localEpisode.Episodes.Where(e => e.EpisodeFileId > 0).Select(e => e.EpisodeFile.Value);
|
||||
|
||||
|
@ -36,9 +36,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|||
_logger.Trace("File is a match for an existing episode file: {0}", localEpisode.Path);
|
||||
return false;
|
||||
}
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
using NzbDrone.Common.Messaging;
|
||||
using System;
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.Events
|
||||
{
|
||||
public class EpisodeFileDeletedEvent : IEvent
|
||||
{
|
||||
public EpisodeFile EpisodeFile { get; private set; }
|
||||
public Boolean ForUpgrade { get; private set; }
|
||||
|
||||
public EpisodeFileDeletedEvent(EpisodeFile episodeFile)
|
||||
public EpisodeFileDeletedEvent(EpisodeFile episodeFile, Boolean forUpgrade)
|
||||
{
|
||||
EpisodeFile = episodeFile;
|
||||
ForUpgrade = forUpgrade;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
{
|
||||
EpisodeFile Add(EpisodeFile episodeFile);
|
||||
void Update(EpisodeFile episodeFile);
|
||||
void Delete(EpisodeFile episodeFile);
|
||||
void Delete(EpisodeFile episodeFile, bool forUpgrade = false);
|
||||
bool Exists(string path);
|
||||
EpisodeFile GetFileByPath(string path);
|
||||
List<EpisodeFile> GetFilesBySeries(int seriesId);
|
||||
|
@ -46,10 +46,11 @@ namespace NzbDrone.Core.MediaFiles
|
|||
_mediaFileRepository.Update(episodeFile);
|
||||
}
|
||||
|
||||
public void Delete(EpisodeFile episodeFile)
|
||||
public void Delete(EpisodeFile episodeFile, bool forUpgrade = false)
|
||||
{
|
||||
_mediaFileRepository.Delete(episodeFile);
|
||||
_messageAggregator.PublishEvent(new EpisodeFileDeletedEvent(episodeFile));
|
||||
|
||||
_messageAggregator.PublishEvent(new EpisodeFileDeletedEvent(episodeFile, forUpgrade));
|
||||
}
|
||||
|
||||
public bool Exists(string path)
|
||||
|
|
|
@ -4,6 +4,7 @@ using NLog;
|
|||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
|
@ -14,19 +15,29 @@ namespace NzbDrone.Core.MediaFiles
|
|||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MediaFileTableCleanupService(IMediaFileService mediaFileService, IDiskProvider diskProvider, IEpisodeService episodeService, Logger logger)
|
||||
public MediaFileTableCleanupService(IMediaFileService mediaFileService,
|
||||
IDiskProvider diskProvider,
|
||||
IEpisodeService episodeService,
|
||||
ISeriesService seriesService,
|
||||
IParsingService parsingService,
|
||||
Logger logger)
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_diskProvider = diskProvider;
|
||||
_episodeService = episodeService;
|
||||
_seriesService = seriesService;
|
||||
_parsingService = parsingService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Execute(CleanMediaFileDb message)
|
||||
{
|
||||
var seriesFile = _mediaFileService.GetFilesBySeries(message.SeriesId);
|
||||
var series = _seriesService.GetSeries(message.SeriesId);
|
||||
|
||||
foreach (var episodeFile in seriesFile)
|
||||
{
|
||||
|
@ -34,14 +45,34 @@ namespace NzbDrone.Core.MediaFiles
|
|||
{
|
||||
if (!_diskProvider.FileExists(episodeFile.Path))
|
||||
{
|
||||
_logger.Trace("File [{0}] no longer exists on disk. removing from db", episodeFile.Path);
|
||||
_logger.Trace("File [{0}] no longer exists on disk, removing from db", episodeFile.Path);
|
||||
_mediaFileService.Delete(episodeFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_episodeService.GetEpisodesByFileId(episodeFile.Id).Any())
|
||||
if (!_diskProvider.IsParent(series.Path, episodeFile.Path))
|
||||
{
|
||||
_logger.Trace("File [{0}] is not assigned to any episodes. removing from db", episodeFile.Path);
|
||||
_logger.Trace("File [{0}] does not belong to this series, removing from db", episodeFile.Path);
|
||||
_mediaFileService.Delete(episodeFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
|
||||
|
||||
if (!episodes.Any())
|
||||
{
|
||||
_logger.Trace("File [{0}] is not assigned to any episodes, removing from db", episodeFile.Path);
|
||||
_mediaFileService.Delete(episodeFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
var localEpsiode = _parsingService.GetEpisodes(episodeFile.Path, series);
|
||||
|
||||
if (localEpsiode == null || episodes.Count != localEpsiode.Episodes.Count)
|
||||
{
|
||||
_logger.Trace("File [{0}] parsed episodes has changed, removing from db", episodeFile.Path);
|
||||
_mediaFileService.Delete(episodeFile);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
_logger.Trace("Removing existing episode file: {0}", file);
|
||||
|
||||
_recycleBinProvider.DeleteFile(file.Path);
|
||||
_mediaFileService.Delete(file);
|
||||
_mediaFileService.Delete(file, true);
|
||||
}
|
||||
|
||||
_logger.Trace("Moving episode file: {0}", episodeFile);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue