New: Show warning in queue if download contains executable or archive file and no audio file was detected (#5106)

* Improve handling of releases without audio files

New: Show warning in queue if download contains executable or archive file and no audio file was detected

(cherry picked from commit b15b6a079846b21cac8476820fce9cde81732291)

* New: Add additional archive exentions

(cherry picked from commit 750a9353f82da4e016bee25e0c625cd6d8613b57)

---------

Co-authored-by: Mark McDowall <mark@mcdowall.ca>
pull/5116/head
Bogdan 2 months ago committed by GitHub
parent 5947b4642c
commit ccce4f5cc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -336,6 +336,74 @@ namespace NzbDrone.Core.Test.MediaFiles
DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue();
}
[Test]
public void should_return_rejection_if_nothing_imported_and_contains_rar_file()
{
GivenValidArtist();
var path = @"C:\Test\Unsorted\Artist.Title-Album.Title.2017-Lidarr".AsOsAgnostic();
var imported = new List<ImportDecision<LocalTrack>>();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(path))
.Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectoryInfo(It.IsAny<string>()))
.Returns(DiskProvider.GetDirectoryInfo(path));
Mocker.GetMock<IMakeImportDecision>()
.Setup(v => v.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<IdentificationOverrides>(), It.IsAny<ImportDecisionMakerInfo>(), It.IsAny<ImportDecisionMakerConfig>()))
.Returns(imported);
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto))
.Returns(imported.Select(i => new ImportResult(i)).ToList());
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(new[] { _audioFiles.First().Replace(".ext", ".rar") });
var result = Subject.ProcessPath(path);
result.Count.Should().Be(1);
result.First().Result.Should().Be(ImportResultType.Rejected);
}
[Test]
public void should_return_rejection_if_nothing_imported_and_contains_executable_file()
{
GivenValidArtist();
var path = @"C:\Test\Unsorted\Artist.Title-Album.Title.2017-Lidarr".AsOsAgnostic();
var imported = new List<ImportDecision<LocalTrack>>();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(path))
.Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectoryInfo(It.IsAny<string>()))
.Returns(DiskProvider.GetDirectoryInfo(path));
Mocker.GetMock<IMakeImportDecision>()
.Setup(v => v.GetImportDecisions(It.IsAny<List<IFileInfo>>(), It.IsAny<IdentificationOverrides>(), It.IsAny<ImportDecisionMakerInfo>(), It.IsAny<ImportDecisionMakerConfig>()))
.Returns(imported);
Mocker.GetMock<IImportApprovedTracks>()
.Setup(s => s.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto))
.Returns(imported.Select(i => new ImportResult(i)).ToList());
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), true))
.Returns(new[] { _audioFiles.First().Replace(".ext", ".exe") });
var result = Subject.ProcessPath(path);
result.Count.Should().Be(1);
result.First().Result.Should().Be(ImportResultType.Rejected);
}
private void VerifyNoImport()
{
Mocker.GetMock<IImportApprovedTracks>().Verify(c => c.Import(It.IsAny<List<ImportDecision<LocalTrack>>>(), true, null, ImportMode.Auto),

@ -135,6 +135,18 @@ namespace NzbDrone.Core.Download
return;
}
if (importResults.Count == 1)
{
var firstResult = importResults.First();
if (firstResult.Result == ImportResultType.Rejected && firstResult.ImportDecision.Item == null)
{
trackedDownload.Warn(new TrackedDownloadStatusMessage(firstResult.Errors.First(), new List<string>()));
return;
}
}
var statusMessages = new List<TrackedDownloadStatusMessage>
{
new TrackedDownloadStatusMessage("One or more albums expected in this release were not imported or missing", new List<string>())

@ -177,10 +177,12 @@ namespace NzbDrone.Core.MediaFiles
if (_artistService.ArtistPathExists(directoryInfo.FullName))
{
_logger.Warn("Unable to process folder that is mapped to an existing artist");
return new List<ImportResult>();
return new List<ImportResult>
{
RejectionResult("Import path is mapped to an artist folder")
};
}
var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
var folderInfo = Parser.Parser.ParseAlbumTitle(directoryInfo.Name);
var audioFiles = _diskScanService.FilterFiles(directoryInfo.FullName, _diskScanService.GetAudioFiles(directoryInfo.FullName));
@ -240,6 +242,10 @@ namespace NzbDrone.Core.MediaFiles
_logger.Debug(e, "Unable to delete folder after importing: {0}", e.Message);
}
}
else if (importResults.Empty())
{
importResults.AddIfNotNull(CheckEmptyResultForIssue(directoryInfo.FullName));
}
return importResults;
}
@ -341,6 +347,28 @@ namespace NzbDrone.Core.MediaFiles
return new ImportResult(new ImportDecision<LocalTrack>(localTrack, new Rejection("Unknown Artist")), message);
}
private ImportResult RejectionResult(string message)
{
return new ImportResult(new ImportDecision<LocalTrack>(null, new Rejection(message)), message);
}
private ImportResult CheckEmptyResultForIssue(string folder)
{
var files = _diskProvider.GetFiles(folder, true).ToList();
if (files.Any(file => FileExtensions.ExecutableExtensions.Contains(Path.GetExtension(file))))
{
return RejectionResult("Caution: Found executable file");
}
if (files.Any(file => FileExtensions.ArchiveExtensions.Contains(Path.GetExtension(file))))
{
return RejectionResult("Found archive file, might need to be extracted");
}
return null;
}
private void LogInaccessiblePathError(string path)
{
if (_runtimeInfo.IsWindowsService)

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
namespace NzbDrone.Core.MediaFiles
{
internal static class FileExtensions
{
private static List<string> _archiveExtensions = new List<string>
{
".7z",
".bz2",
".gz",
".r00",
".rar",
".tar.bz2",
".tar.gz",
".tar",
".tb2",
".tbz2",
".tgz",
".zip",
".zipx"
};
private static List<string> _executableExtensions = new List<string>
{
".exe",
".bat",
".cmd",
".sh"
};
public static HashSet<string> ArchiveExtensions => new HashSet<string>(_archiveExtensions, StringComparer.OrdinalIgnoreCase);
public static HashSet<string> ExecutableExtensions => new HashSet<string>(_executableExtensions, StringComparer.OrdinalIgnoreCase);
}
}
Loading…
Cancel
Save