diff --git a/src/Chaptarr.Core.Test/Download/CompletedDownloadWaitingFixture.cs b/src/Chaptarr.Core.Test/Download/CompletedDownloadWaitingFixture.cs index c833d77c4..7bc46e5d8 100644 --- a/src/Chaptarr.Core.Test/Download/CompletedDownloadWaitingFixture.cs +++ b/src/Chaptarr.Core.Test/Download/CompletedDownloadWaitingFixture.cs @@ -570,7 +570,7 @@ private static void Run(bool postgres, int sources, int imported, Action((method, args) => method.Name == "get_IsWindowsService" ? false : throw new InvalidOperationException("Missing-source check attempted " + method.Name)); var importer = new DownloadedBooksImportService(disk, null, null, null, null, null, null, null, null, null, - null, null, history, events, runtime, null, logger, queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + null, null, history, events, runtime, null, logger, queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var snapshots = new DownloadClientFileSnapshotService(new DownloadClientFileSnapshotRepository(database, events), disk, logger); var item = new DownloadClientItem { DownloadId = "waiting", Title = "Dune", Status = DownloadItemStatus.Completed, OutputPath = new OsPath(directory), FilePaths = paths, FileListConfidence = DownloadClientFileListConfidence.Authoritative, diff --git a/src/Chaptarr.Core.Test/MediaFiles/BookImport/AlternativeCopyImportProofFixture.cs b/src/Chaptarr.Core.Test/MediaFiles/BookImport/AlternativeCopyImportProofFixture.cs index a8c9daba7..093797bf2 100644 --- a/src/Chaptarr.Core.Test/MediaFiles/BookImport/AlternativeCopyImportProofFixture.cs +++ b/src/Chaptarr.Core.Test/MediaFiles/BookImport/AlternativeCopyImportProofFixture.cs @@ -211,7 +211,7 @@ DiscoveredFileWithMetadata File(string suffix, string identifiers, string cast, Assert.That(result.MatchedFiles.All(match => match.EditionId == captured[match.BookId]), Is.True); var remote = new RemoteBook { Author = author, Books = new() { a,b }, AlternativeCopies = true, TargetEditionIds = captured, AlternativeCopyGrabDate = DateTime.UtcNow }; var disk = Proxy((method,args) => method.Name == nameof(IDiskProvider.GetFileSize) ? 1L : (object)DateTime.UtcNow); - var importer = new DownloadedBooksImportService(disk,null,matcher,null,null,bookService,authorService,editionService,null,null,null,null,null,events,null,null,logger, queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + var importer = new DownloadedBooksImportService(disk,null,matcher,null,null,bookService,authorService,editionService,null,null,null,null,null,events,null,null,logger, queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var decisionBuilder = typeof(DownloadedBooksImportService).GetMethod("CreateDecisionForMatch", BindingFlags.NonPublic|BindingFlags.Instance); var tagsByPath = files.ToDictionary(file=>file.Path,file=>file.AllTags); var bookCache = new Dictionary(); var authorCache = new Dictionary(); diff --git a/src/Chaptarr.Core.Test/MediaFiles/DownloadedBooksImportServiceFixture.cs b/src/Chaptarr.Core.Test/MediaFiles/DownloadedBooksImportServiceFixture.cs index b5dc84643..af1bc032d 100644 --- a/src/Chaptarr.Core.Test/MediaFiles/DownloadedBooksImportServiceFixture.cs +++ b/src/Chaptarr.Core.Test/MediaFiles/DownloadedBooksImportServiceFixture.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using NLog; using NUnit.Framework; +using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Core.Books; using NzbDrone.Core.Books.Services; @@ -191,7 +192,7 @@ private sealed class StubDiskProvider : IDiskProvider public bool FolderWritable(string path) => throw new NotImplementedException(); public bool FolderEmpty(string path) => throw new NotImplementedException(); public IEnumerable GetDirectories(string path) => throw new NotImplementedException(); - public IEnumerable GetFiles(string path, bool recursive) => throw new NotImplementedException(); + public IEnumerable GetFiles(string path, bool recursive) => Directory.Exists(path) ? Directory.GetFiles(path, "*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) : Array.Empty(); public long GetFolderSize(string path) => throw new NotImplementedException(); public void CreateFolder(string path) => throw new NotImplementedException(); public void DeleteFile(string path) => throw new NotImplementedException(); @@ -525,7 +526,7 @@ Book Seed(string slug) AlternativeCopies = alternative, AlternativeCopyGrabDate = grabbed, TargetEditionIds = captured }; if (extras == "disabled-unscoped") client.FilePaths = null; var importer = new DownloadedBooksImportService(disk, scan, matching, new StubMetadataTagService(), writer, bookService, authorService, - editionService, null, null, null, config, history, events, null, null, logger, queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + editionService, null, null, null, config, history, events, null, null, logger, queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var results = importer.ProcessPath(source, mode, author, client, remote); TestContext.WriteLine(string.Join("; ", results.SelectMany(result => result.Errors))); var expectedCount = media == BookMediaType.Audiobook ? 3 : 1; @@ -648,7 +649,7 @@ public void should_classify_downloads_without_target_media(string extension, boo DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var results = service.ProcessPath(singleFile ? filePath : tempDir, ImportMode.Auto, remoteBook: new RemoteBook { Books = new List { new Book { MediaType = BookMediaType.Audiobook } } }); @@ -709,7 +710,7 @@ public void should_keep_waiting_when_supported_media_is_not_available() Chaptarr.Core.Test.Common.InterfaceProxy.Proxy((method, args) => null), Chaptarr.Core.Test.Common.InterfaceProxy.Proxy((method, args) => false), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); RejectionType Classify(DownloadClientItem downloadClientItem, string path = null) { @@ -811,7 +812,7 @@ public void should_reject_locked_media_before_matching_a_manually_imported_folde DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var result = service.ProcessPath(tempDir, ImportMode.Auto, author: null, downloadClientItem: null).Single(); @@ -947,7 +948,7 @@ public void should_auto_add_suggested_author_and_rematch_during_manual_download_ eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(filePath, ImportMode.Auto, author: null, downloadClientItem: null); @@ -1058,7 +1059,7 @@ public void should_hydrate_matched_book_and_author_once_per_download_import() DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(tempDir, ImportMode.Auto, author: null, downloadClientItem: null); @@ -1148,7 +1149,7 @@ public void should_not_auto_add_manual_import_when_strict_default_roots_required DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(filePath, ImportMode.Auto, author: null, downloadClientItem: null, requireDefaultRootFolderForMissingAuthors: true); @@ -1238,7 +1239,7 @@ public void should_not_auto_add_suggested_author_for_completed_download_when_dis DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(filePath, ImportMode.Auto, author: null, downloadClientItem: new DownloadClientItem { DownloadId = "external-grab" }); @@ -1364,7 +1365,7 @@ public void should_auto_add_completed_download_using_only_compatible_root_when_d DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(filePath, ImportMode.Auto, author: null, downloadClientItem: new DownloadClientItem { DownloadId = "external-grab" }); @@ -1465,7 +1466,7 @@ public void should_not_auto_add_completed_download_when_multiple_compatible_root DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(filePath, ImportMode.Auto, author: null, downloadClientItem: new DownloadClientItem { DownloadId = "external-grab" }); @@ -1597,7 +1598,7 @@ public void should_auto_add_suggested_author_and_rematch_completed_download_when DispatchProxy.Create>(), DispatchProxy.Create>(), DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(filePath, ImportMode.Auto, author: null, downloadClientItem: new DownloadClientItem { DownloadId = "external-grab" }); @@ -1686,7 +1687,7 @@ public void should_reject_unmatched_files_in_download_import() eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath(filePath, ImportMode.Auto, author: null, downloadClientItem: null); @@ -1784,7 +1785,7 @@ public void should_allow_path_fallback_for_single_target_completed_download_fold eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); _ = service.ProcessPath( tempDir, @@ -1895,7 +1896,7 @@ public void should_reject_completed_download_match_that_does_not_belong_to_grabb eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -1992,7 +1993,7 @@ public void should_allow_completed_download_match_when_it_belongs_to_grabbed_tar eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2128,7 +2129,7 @@ public void should_retarget_same_work_sibling_match_to_grabbed_book_without_clon eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2239,7 +2240,7 @@ public void should_reject_same_work_sibling_match_when_grabbed_book_has_no_equiv eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2344,7 +2345,7 @@ public void should_reject_completed_download_when_latest_grabbed_edition_is_stri eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2455,7 +2456,7 @@ public void should_keep_matcher_edition_when_flexible_book_has_no_embedded_metad eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2565,7 +2566,7 @@ public void should_allow_flexible_book_to_keep_sibling_match_when_identity_metad eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2675,7 +2676,7 @@ public void should_not_repair_tracked_multipart_audio_download_when_two_parts_sh eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2782,7 +2783,7 @@ public void should_not_repair_tracked_multipart_audio_download_when_only_one_see eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -2893,7 +2894,7 @@ public void should_not_absorb_bare_numeric_sibling_title_into_tracked_multipart_ eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -3004,7 +3005,7 @@ public void should_not_strip_literal_part_word_without_adjacent_number_when_repa eventAggregator, runtimeInfo, DispatchProxy.Create>(), - LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs()); + LogManager.GetCurrentClassLogger(), queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var remoteBook = new RemoteBook { @@ -3080,5 +3081,167 @@ private static Dictionary> CreateAudioTags(string album, st ["TITLE"] = new List { title } }; } + + private sealed class RecordingArchiveService : IArchiveService + { + public List<(string CompressedFile, string Destination)> Extractions { get; } = new(); + + public void Extract(string compressedFile, string destination) + { + Extractions.Add((compressedFile, destination)); + } + + public void ExtractZip(string compressedFile, string destination, long maximumBytes) => throw new NotImplementedException(); + + public void CreateZip(string path, IEnumerable files) => throw new NotImplementedException(); + } + + [Test] + public void should_extract_archives_when_folder_has_no_direct_importable_files() + { + var tempDir = Path.Combine(Path.GetTempPath(), "chaptarr-tests", Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(tempDir); + var zipPath = Path.Combine(tempDir, "Book.zip"); + File.WriteAllBytes(zipPath, new byte[] { 1, 2, 3, 4 }); + + var archiveService = new RecordingArchiveService(); + + try + { + var service = new DownloadedBooksImportService( + new StubDiskProvider(), + new StubDiskScanService(), + new StubFileMatchingService(), + new StubMetadataTagService(), + new RecordingImportApprovedBooks(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + new StubAuthorLibraryService(), + new StubRootFolderService(), + ConfigServiceTestProxy.Create(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + LogManager.GetCurrentClassLogger(), + queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), + conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), + archiveService: archiveService); + + service.ProcessPath(tempDir, ImportMode.Auto, author: null, downloadClientItem: null); + + Assert.That(archiveService.Extractions, Has.Count.EqualTo(1)); + Assert.That(archiveService.Extractions[0].CompressedFile, Is.EqualTo(zipPath)); + Assert.That(archiveService.Extractions[0].Destination, Is.EqualTo(tempDir)); + } + finally + { + Directory.Delete(tempDir, true); + } + } + + [Test] + public void should_extract_archive_when_download_client_item_has_scoped_archive_file() + { + var tempDir = Path.Combine(Path.GetTempPath(), "chaptarr-tests", Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(tempDir); + var zipPath = Path.Combine(tempDir, "Book.zip"); + File.WriteAllBytes(zipPath, new byte[] { 1, 2, 3, 4 }); + + var archiveService = new RecordingArchiveService(); + + try + { + var service = new DownloadedBooksImportService( + new StubDiskProvider(), + new StubDiskScanService(), + new StubFileMatchingService(), + new StubMetadataTagService(), + new RecordingImportApprovedBooks(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + new StubAuthorLibraryService(), + new StubRootFolderService(), + ConfigServiceTestProxy.Create(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + LogManager.GetCurrentClassLogger(), + queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), + conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), + archiveService: archiveService); + + var downloadClientItem = new DownloadClientItem + { + FilePaths = new List { zipPath } + }; + + service.ProcessPath(tempDir, ImportMode.Auto, author: null, downloadClientItem: downloadClientItem); + + Assert.That(archiveService.Extractions, Has.Count.EqualTo(1)); + Assert.That(archiveService.Extractions[0].CompressedFile, Is.EqualTo(zipPath)); + Assert.That(archiveService.Extractions[0].Destination, Is.EqualTo(tempDir)); + } + finally + { + Directory.Delete(tempDir, true); + } + } + + [Test] + public void should_not_extract_archive_when_download_client_item_scope_excludes_archive() + { + var tempDir = Path.Combine(Path.GetTempPath(), "chaptarr-tests", Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(tempDir); + var zipPath = Path.Combine(tempDir, "Book.zip"); + var nfoPath = Path.Combine(tempDir, "Book.nfo"); + File.WriteAllBytes(zipPath, new byte[] { 1, 2, 3, 4 }); + File.WriteAllBytes(nfoPath, new byte[] { 1, 2, 3, 4 }); + + var archiveService = new RecordingArchiveService(); + + try + { + var service = new DownloadedBooksImportService( + new StubDiskProvider(), + new StubDiskScanService(), + new StubFileMatchingService(), + new StubMetadataTagService(), + new RecordingImportApprovedBooks(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + new StubAuthorLibraryService(), + new StubRootFolderService(), + ConfigServiceTestProxy.Create(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + DispatchProxy.Create>(), + LogManager.GetCurrentClassLogger(), + queueService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.EmptyQueue(), + conversionJobService: global::Chaptarr.Core.Test.Common.ImportLifecycleStubs.NoConversionJobs(), + archiveService: archiveService); + + var downloadClientItem = new DownloadClientItem + { + FilePaths = new List { nfoPath } + }; + + service.ProcessPath(tempDir, ImportMode.Auto, author: null, downloadClientItem: downloadClientItem); + + Assert.That(archiveService.Extractions, Is.Empty); + } + finally + { + Directory.Delete(tempDir, true); + } + } } } diff --git a/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.AcceptedIncludedMedia.cs b/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.AcceptedIncludedMedia.cs index faab63401..002c14552 100644 --- a/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.AcceptedIncludedMedia.cs +++ b/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.AcceptedIncludedMedia.cs @@ -92,7 +92,7 @@ public void bonus_requires_saved_edition_before_resuming_despite_paused_format_a InterfaceProxy.Proxy((method, _) => { Assert.That(method.Name, Is.EqualTo("GetBooksForLookup")); return new List { book }; }), InterfaceProxy.Proxy((method, _) => { Assert.That(method.Name, Is.EqualTo("GetAuthor")); return author; }), null, null, null, null, null, null, null, null, null, LogManager.GetCurrentClassLogger(), - ImportLifecycleStubs.EmptyQueue(), jobs); + ImportLifecycleStubs.EmptyQueue(), jobs, archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var item = new DownloadClientItem { DownloadId = "bonus-boundary", FilePaths = paths.ToList() }; var remote = new RemoteBook { Author = author, Books = new() { new Book { Id = 4, MediaType = BookMediaType.Ebook, GoodreadsWorkId = "gr:123" } }, ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.EPUB) } }; diff --git a/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.BonusBoundary.cs b/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.BonusBoundary.cs index 712a63613..0a4407408 100644 --- a/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.BonusBoundary.cs +++ b/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.BonusBoundary.cs @@ -188,7 +188,7 @@ private void RunIncludedBoundary(bool cleanupThrows, bool partialRefusal, bool i InterfaceProxy.Proxy((method, _) => { Assert.That(method.Name, Is.EqualTo("GetBooksForLookup")); return new List { book }; }), InterfaceProxy.Proxy((method, _) => { Assert.That(method.Name, Is.EqualTo("GetAuthor")); return author; }), null, null, null, null, null, null, null, null, null, LogManager.GetCurrentClassLogger(), - ImportLifecycleStubs.EmptyQueue(), jobs); + ImportLifecycleStubs.EmptyQueue(), jobs, archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var item = new DownloadClientItem { DownloadId = "bonus-boundary", FilePaths = paths.ToList() }; var remote = new RemoteBook { Author = author, Books = new() { new Book { Id = 4, MediaType = BookMediaType.Audiobook, GoodreadsWorkId = "gr:123" } }, ParsedBookInfo = new ParsedBookInfo { Quality = new QualityModel(Quality.M4B) } }; diff --git a/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.IncludedMedia.cs b/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.IncludedMedia.cs index 09c28f94a..0729d0f2d 100644 --- a/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.IncludedMedia.cs +++ b/src/Chaptarr.Core.Test/MediaFiles/ImportApprovedBooksAdditionalCopyFixture.IncludedMedia.cs @@ -473,7 +473,7 @@ object SaveFiles(object[] args) return queued; }); var importer = new DownloadedBooksImportService(disk, diskScan, matcher, tags, approved, bookService, authorService, editionService, - null, null, null, config, history, events, InterfaceProxy.Proxy((_, _) => false), new StubMediaInfoExtractor(), logger, queueService: queue, conversionJobService: jobs ?? ImportLifecycleStubs.NoConversionJobs()); + null, null, null, config, history, events, InterfaceProxy.Proxy((_, _) => false), new StubMediaInfoExtractor(), logger, queueService: queue, conversionJobService: jobs ?? ImportLifecycleStubs.NoConversionJobs(), archiveService: new global::NzbDrone.Common.ArchiveService(global::NLog.LogManager.GetCurrentClassLogger())); var item = new DownloadClientItem { DownloadId = "MIXED-DOWNLOAD", Title = "Frank Herbert - Dune", OutputPath = new OsPath(source), Status = DownloadItemStatus.Completed, FilePaths = new() { PathFor(requested), PathFor(other) }, DownloadForced = !requestedConversionOnly && !requestedSource, FileListConfidence = DownloadClientFileListConfidence.Authoritative, diff --git a/src/NzbDrone.Core/MediaFiles/DownloadedBooksImportService.cs b/src/NzbDrone.Core/MediaFiles/DownloadedBooksImportService.cs index 2a9a6ac61..7df9670ec 100644 --- a/src/NzbDrone.Core/MediaFiles/DownloadedBooksImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/DownloadedBooksImportService.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using NLog; +using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Common.EnvironmentInfo; @@ -54,6 +55,7 @@ public partial class DownloadedBooksImportService : IDownloadedBooksImportServic private readonly IEventAggregator _eventAggregator; private readonly IRuntimeInfo _runtimeInfo; private readonly IMediaInfoExtractor _mediaInfoExtractor; + private readonly IArchiveService _archiveService; private readonly Logger _logger; private readonly NzbDrone.Core.Queue.IQueueService _queueService; private readonly IConversionJobService _conversionJobService; @@ -77,7 +79,8 @@ public DownloadedBooksImportService( IMediaInfoExtractor mediaInfoExtractor, Logger logger, NzbDrone.Core.Queue.IQueueService queueService, - IConversionJobService conversionJobService) + IConversionJobService conversionJobService, + IArchiveService archiveService) { _diskProvider = diskProvider; _diskScanService = diskScanService; @@ -98,6 +101,7 @@ public DownloadedBooksImportService( _logger = logger; _queueService = queueService ?? throw new ArgumentNullException(nameof(queueService)); _conversionJobService = conversionJobService ?? throw new ArgumentNullException(nameof(conversionJobService)); + _archiveService = archiveService; } public List ProcessRootFolder(IDirectoryInfo directoryInfo) @@ -194,6 +198,23 @@ private List ProcessFolder(IDirectoryInfo directoryInfo, ImportMod (!targetMedia.HasValue || QualityMediaTypeHelper.GetMediaTypeFromPath(f.FullName) == targetMedia)) .ToList(); + if (!mediaFiles.Any()) + { + var archives = fileListScoped + ? visibleFiles.Where(f => IsSupportedArchive(f.FullName)).Select(f => f.FullName).ToList() + : _diskProvider.GetFiles(directoryInfo.FullName, true).Where(IsSupportedArchive).ToList(); + + if (archives.Any() && ExtractArchives(directoryInfo, archives)) + { + visibleFiles = _diskProvider.GetFileInfos(directoryInfo.FullName, true); + mediaFiles = visibleFiles + .Where(f => MediaFileExtensions.AllExtensions.Contains(f.Extension) && + !DiskScanService.IsExcludedFile(f.FullName) && + (!targetMedia.HasValue || QualityMediaTypeHelper.GetMediaTypeFromPath(f.FullName) == targetMedia)) + .ToList(); + } + } + if (!mediaFiles.Any()) { _logger.Debug("[DOWNLOAD-IMPORT] No media files found in: {0}", directoryInfo.FullName); @@ -1579,5 +1600,32 @@ public List ProcessFile(string path, ImportMode importMode = Impor var fileInfo = _diskProvider.GetFileInfo(path); return ProcessFile(fileInfo, importMode, author, downloadClientItem, remoteBook, requireDefaultRootFolderForMissingAuthors: requireDefaultRootFolderForMissingAuthors); } + + private bool ExtractArchives(IDirectoryInfo directoryInfo, IEnumerable archives) + { + var extractedAny = false; + + foreach (var archive in archives) + { + try + { + _archiveService.Extract(archive, directoryInfo.FullName); + extractedAny = true; + } + catch (Exception e) + { + _logger.Warn(e, "Failed to extract archive during import: {0}", archive); + } + } + + return extractedAny; + } + + private static bool IsSupportedArchive(string path) + { + return path.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) || + path.EndsWith(".tgz", StringComparison.OrdinalIgnoreCase) || + path.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase); + } } }