mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-12 11:15:43 +02:00
New: Add recycle bin path for deleted episodes to webhook/custom script
Closes #6114
This commit is contained in:
parent
9ba5850fca
commit
a71d40edba
@ -176,7 +176,7 @@ public void should_return_docker_path_mapping_error_if_on_docker_and_root_missin
|
||||
public void should_return_ok_on_episode_imported_event()
|
||||
{
|
||||
GivenFolderExists(_downloadRootPath);
|
||||
var importEvent = new EpisodeImportedEvent(new LocalEpisode(), new EpisodeFile(), new List<EpisodeFile>(), true, new DownloadClientItem());
|
||||
var importEvent = new EpisodeImportedEvent(new LocalEpisode(), new EpisodeFile(), new List<DeletedEpisodeFile>(), true, new DownloadClientItem());
|
||||
|
||||
Subject.Check(importEvent).ShouldBeOk();
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public void should_use_file_name_for_source_title_if_scene_name_is_null()
|
||||
DownloadId = "abcd"
|
||||
};
|
||||
|
||||
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, new List<EpisodeFile>(), true, downloadClientItem));
|
||||
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, new List<DeletedEpisodeFile>(), true, downloadClientItem));
|
||||
|
||||
Mocker.GetMock<IHistoryRepository>()
|
||||
.Verify(v => v.Insert(It.Is<EpisodeHistory>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path))));
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
@ -33,16 +33,16 @@ public void SetUp()
|
||||
RelativePath = "file1.S01E01E02.mkv"
|
||||
},
|
||||
|
||||
OldFiles = new List<EpisodeFile>
|
||||
OldFiles = new List<DeletedEpisodeFile>
|
||||
{
|
||||
new EpisodeFile
|
||||
new DeletedEpisodeFile(new EpisodeFile
|
||||
{
|
||||
RelativePath = "file1.S01E01.mkv"
|
||||
},
|
||||
new EpisodeFile
|
||||
}, null),
|
||||
new DeletedEpisodeFile(new EpisodeFile
|
||||
{
|
||||
RelativePath = "file1.S01E02.mkv"
|
||||
}
|
||||
}, null)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
@ -28,7 +28,7 @@ public void Setup()
|
||||
_downloadMessage = Builder<DownloadMessage>.CreateNew()
|
||||
.With(d => d.Series = series)
|
||||
.With(d => d.EpisodeFile = episodeFile)
|
||||
.With(d => d.OldFiles = new List<EpisodeFile>())
|
||||
.With(d => d.OldFiles = new List<DeletedEpisodeFile>())
|
||||
.Build();
|
||||
|
||||
Subject.Definition = new NotificationDefinition();
|
||||
@ -40,9 +40,12 @@ public void Setup()
|
||||
|
||||
private void GivenOldFiles()
|
||||
{
|
||||
_downloadMessage.OldFiles = Builder<EpisodeFile>.CreateListOfSize(1)
|
||||
.Build()
|
||||
.ToList();
|
||||
_downloadMessage.OldFiles = Builder<DeletedEpisodeFile>
|
||||
.CreateListOfSize(1)
|
||||
.All()
|
||||
.WithFactory(() => new DeletedEpisodeFile(Builder<EpisodeFile>.CreateNew().Build(), null))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.Definition.Settings = new XbmcSettings
|
||||
{
|
||||
|
14
src/NzbDrone.Core/MediaFiles/DeletedEpisodeFile.cs
Normal file
14
src/NzbDrone.Core/MediaFiles/DeletedEpisodeFile.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public class DeletedEpisodeFile
|
||||
{
|
||||
public string RecycleBinPath { get; set; }
|
||||
public EpisodeFile EpisodeFile { get; set; }
|
||||
|
||||
public DeletedEpisodeFile(EpisodeFile episodeFile, string recycleBinPath)
|
||||
{
|
||||
EpisodeFile = episodeFile;
|
||||
RecycleBinPath = recycleBinPath;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
@ -6,10 +6,10 @@ public class EpisodeFileMoveResult
|
||||
{
|
||||
public EpisodeFileMoveResult()
|
||||
{
|
||||
OldFiles = new List<EpisodeFile>();
|
||||
OldFiles = new List<DeletedEpisodeFile>();
|
||||
}
|
||||
|
||||
public EpisodeFile EpisodeFile { get; set; }
|
||||
public List<EpisodeFile> OldFiles { get; set; }
|
||||
public List<DeletedEpisodeFile> OldFiles { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
||||
.ThenByDescending(e => e.LocalEpisode.Size))
|
||||
{
|
||||
var localEpisode = importDecision.LocalEpisode;
|
||||
var oldFiles = new List<EpisodeFile>();
|
||||
var oldFiles = new List<DeletedEpisodeFile>();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -9,12 +9,12 @@ public class EpisodeImportedEvent : IEvent
|
||||
{
|
||||
public LocalEpisode EpisodeInfo { get; private set; }
|
||||
public EpisodeFile ImportedEpisode { get; private set; }
|
||||
public List<EpisodeFile> OldFiles { get; private set; }
|
||||
public List<DeletedEpisodeFile> OldFiles { get; private set; }
|
||||
public bool NewDownload { get; private set; }
|
||||
public DownloadClientItemClientInfo DownloadClientInfo { get; set; }
|
||||
public string DownloadId { get; private set; }
|
||||
|
||||
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, List<EpisodeFile> oldFiles, bool newDownload, DownloadClientItem downloadClientItem)
|
||||
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, List<DeletedEpisodeFile> oldFiles, bool newDownload, DownloadClientItem downloadClientItem)
|
||||
{
|
||||
EpisodeInfo = episodeInfo;
|
||||
ImportedEpisode = importedEpisode;
|
||||
|
@ -14,7 +14,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||
public interface IRecycleBinProvider
|
||||
{
|
||||
void DeleteFolder(string path);
|
||||
void DeleteFile(string path, string subfolder = "");
|
||||
string DeleteFile(string path, string subfolder = "");
|
||||
void Empty();
|
||||
void Cleanup();
|
||||
}
|
||||
@ -66,7 +66,7 @@ public void DeleteFolder(string path)
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFile(string path, string subfolder = "")
|
||||
public string DeleteFile(string path, string subfolder = "")
|
||||
{
|
||||
_logger.Debug("Attempting to send '{0}' to recycling bin", path);
|
||||
var recyclingBin = _configService.RecycleBin;
|
||||
@ -82,6 +82,8 @@ public void DeleteFile(string path, string subfolder = "")
|
||||
|
||||
_diskProvider.DeleteFile(path);
|
||||
_logger.Debug("File has been permanently deleted: {0}", path);
|
||||
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -128,6 +130,8 @@ public void DeleteFile(string path, string subfolder = "")
|
||||
SetLastWriteTime(destination, DateTime.UtcNow);
|
||||
|
||||
_logger.Debug("File has been moved to the recycling bin: {0}", destination);
|
||||
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,9 +174,10 @@ public ScriptImportDecision TryImport(string sourcePath, string destinationFileP
|
||||
|
||||
if (oldFiles.Any())
|
||||
{
|
||||
environmentVariables.Add("Sonarr_DeletedRelativePaths", string.Join("|", oldFiles.Select(e => e.RelativePath)));
|
||||
environmentVariables.Add("Sonarr_DeletedPaths", string.Join("|", oldFiles.Select(e => Path.Combine(series.Path, e.RelativePath))));
|
||||
environmentVariables.Add("Sonarr_DeletedDateAdded", string.Join("|", oldFiles.Select(e => e.DateAdded)));
|
||||
environmentVariables.Add("Sonarr_DeletedRelativePaths", string.Join("|", oldFiles.Select(e => e.EpisodeFile.RelativePath)));
|
||||
environmentVariables.Add("Sonarr_DeletedPaths", string.Join("|", oldFiles.Select(e => Path.Combine(series.Path, e.EpisodeFile.RelativePath))));
|
||||
environmentVariables.Add("Sonarr_DeletedDateAdded", string.Join("|", oldFiles.Select(e => e.EpisodeFile.DateAdded)));
|
||||
environmentVariables.Add("Sonarr_DeletedRecycleBinPaths", string.Join("|", oldFiles.Select(e => e.RecycleBinPath ?? string.Empty)));
|
||||
}
|
||||
|
||||
_logger.Debug("Executing external script: {0}", _configService.ScriptImportPath);
|
||||
|
@ -57,14 +57,15 @@ public EpisodeFileMoveResult UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEp
|
||||
var file = existingFile.First();
|
||||
var episodeFilePath = Path.Combine(localEpisode.Series.Path, file.RelativePath);
|
||||
var subfolder = rootFolder.GetRelativePath(_diskProvider.GetParentFolder(episodeFilePath));
|
||||
string recycleBinPath = null;
|
||||
|
||||
if (_diskProvider.FileExists(episodeFilePath))
|
||||
{
|
||||
_logger.Debug("Removing existing episode file: {0}", file);
|
||||
_recycleBinProvider.DeleteFile(episodeFilePath, subfolder);
|
||||
recycleBinPath = _recycleBinProvider.DeleteFile(episodeFilePath, subfolder);
|
||||
}
|
||||
|
||||
moveFileResult.OldFiles.Add(file);
|
||||
moveFileResult.OldFiles.Add(new DeletedEpisodeFile(file, recycleBinPath));
|
||||
_mediaFileService.Delete(file, DeleteMediaFileReason.Upgrade);
|
||||
}
|
||||
|
||||
|
@ -158,9 +158,10 @@ public override void OnDownload(DownloadMessage message)
|
||||
|
||||
if (message.OldFiles.Any())
|
||||
{
|
||||
environmentVariables.Add("Sonarr_DeletedRelativePaths", string.Join("|", message.OldFiles.Select(e => e.RelativePath)));
|
||||
environmentVariables.Add("Sonarr_DeletedPaths", string.Join("|", message.OldFiles.Select(e => Path.Combine(series.Path, e.RelativePath))));
|
||||
environmentVariables.Add("Sonarr_DeletedDateAdded", string.Join("|", message.OldFiles.Select(e => e.DateAdded)));
|
||||
environmentVariables.Add("Sonarr_DeletedRelativePaths", string.Join("|", message.OldFiles.Select(e => e.EpisodeFile.RelativePath)));
|
||||
environmentVariables.Add("Sonarr_DeletedPaths", string.Join("|", message.OldFiles.Select(e => Path.Combine(series.Path, e.EpisodeFile.RelativePath))));
|
||||
environmentVariables.Add("Sonarr_DeletedDateAdded", string.Join("|", message.OldFiles.Select(e => e.EpisodeFile.DateAdded)));
|
||||
environmentVariables.Add("Sonarr_DeletedRecycleBinPaths", string.Join("|", message.OldFiles.Select(e => e.RecycleBinPath ?? string.Empty)));
|
||||
}
|
||||
|
||||
ExecuteScript(environmentVariables);
|
||||
|
@ -12,7 +12,7 @@ public class DownloadMessage
|
||||
public Series Series { get; set; }
|
||||
public LocalEpisode EpisodeInfo { get; set; }
|
||||
public EpisodeFile EpisodeFile { get; set; }
|
||||
public List<EpisodeFile> OldFiles { get; set; }
|
||||
public List<DeletedEpisodeFile> OldFiles { get; set; }
|
||||
public string SourcePath { get; set; }
|
||||
public DownloadClientItemClientInfo DownloadClientInfo { get; set; }
|
||||
public string DownloadId { get; set; }
|
||||
|
@ -29,7 +29,7 @@ public override void OnDownload(DownloadMessage message)
|
||||
{
|
||||
foreach (var oldFile in message.OldFiles)
|
||||
{
|
||||
var fullPath = Path.Combine(message.Series.Path, oldFile.RelativePath);
|
||||
var fullPath = Path.Combine(message.Series.Path, oldFile.EpisodeFile.RelativePath);
|
||||
|
||||
_indexerProxy.DeleteFile(fullPath);
|
||||
}
|
||||
|
@ -65,9 +65,10 @@ protected WebhookImportPayload BuildOnDownloadPayload(DownloadMessage message)
|
||||
|
||||
if (message.OldFiles.Any())
|
||||
{
|
||||
payload.DeletedFiles = message.OldFiles.ConvertAll(x => new WebhookEpisodeFile(x)
|
||||
payload.DeletedFiles = message.OldFiles.ConvertAll(x => new WebhookEpisodeFile(x.EpisodeFile)
|
||||
{
|
||||
Path = Path.Combine(message.Series.Path, x.RelativePath)
|
||||
Path = Path.Combine(message.Series.Path, x.EpisodeFile.RelativePath),
|
||||
RecycleBinPath = x.RecycleBinPath
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -37,5 +37,6 @@ public WebhookEpisodeFile(EpisodeFile episodeFile)
|
||||
public long Size { get; set; }
|
||||
public DateTime DateAdded { get; set; }
|
||||
public WebhookEpisodeFileMediaInfo MediaInfo { get; set; }
|
||||
public string RecycleBinPath { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public LocalEpisode()
|
||||
public ParsedEpisodeInfo FolderEpisodeInfo { get; set; }
|
||||
public Series Series { get; set; }
|
||||
public List<Episode> Episodes { get; set; }
|
||||
public List<EpisodeFile> OldFiles { get; set; }
|
||||
public List<DeletedEpisodeFile> OldFiles { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
public List<Language> Languages { get; set; }
|
||||
public MediaInfoModel MediaInfo { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user