mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
4c1e6e14aa
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)
51 lines
1.9 KiB
C#
51 lines
1.9 KiB
C#
using System.Linq;
|
|
using NLog;
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
namespace NzbDrone.Core.MediaFiles
|
|
{
|
|
public interface IUpgradeMediaFiles
|
|
{
|
|
EpisodeFile UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
|
|
}
|
|
|
|
public class UpgradeMediaFileService : IUpgradeMediaFiles
|
|
{
|
|
private readonly IRecycleBinProvider _recycleBinProvider;
|
|
private readonly IMediaFileService _mediaFileService;
|
|
private readonly IMoveEpisodeFiles _episodeFileMover;
|
|
private readonly Logger _logger;
|
|
|
|
public UpgradeMediaFileService(IRecycleBinProvider recycleBinProvider,
|
|
IMediaFileService mediaFileService,
|
|
IMoveEpisodeFiles episodeFileMover,
|
|
Logger logger)
|
|
{
|
|
_recycleBinProvider = recycleBinProvider;
|
|
_mediaFileService = mediaFileService;
|
|
_episodeFileMover = episodeFileMover;
|
|
_logger = logger;
|
|
}
|
|
|
|
public EpisodeFile UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
|
|
{
|
|
var existingFiles = localEpisode.Episodes
|
|
.Where(e => e.EpisodeFileId > 0)
|
|
.Select(e => e.EpisodeFile.Value)
|
|
.GroupBy(e => e.Id);
|
|
|
|
foreach (var existingFile in existingFiles)
|
|
{
|
|
var file = existingFile.First();
|
|
_logger.Trace("Removing existing episode file: {0}", file);
|
|
|
|
_recycleBinProvider.DeleteFile(file.Path);
|
|
_mediaFileService.Delete(file, true);
|
|
}
|
|
|
|
_logger.Trace("Moving episode file: {0}", episodeFile);
|
|
return _episodeFileMover.MoveEpisodeFile(episodeFile, localEpisode);
|
|
}
|
|
}
|
|
}
|