diff --git a/Source/AzwConverter/AzwConverter.cs b/Source/AzwConverter/AzwConverter.cs index 031c7c3..700695d 100644 --- a/Source/AzwConverter/AzwConverter.cs +++ b/Source/AzwConverter/AzwConverter.cs @@ -77,8 +77,17 @@ public async Task ConvertOrScanAsync() var syncer = new TitleSyncer(); // Number of books is stable after title syncing. - var added = await syncer.SyncBooksToTitlesAsync(books, titles, archive); - Console.WriteLine($"Added {added} missing title{added.SIf1()}"); + var (added, skipped) = await syncer.SyncBooksToTitlesAsync(books, titles, archive); + + Console.Write($"Added {added} missing title{added.SIf1()}"); + if (!Settings.ConvertAllBookTypes) + { + Console.WriteLine($" (skipped {skipped})"); + } + else + { + Console.WriteLine(); + } var archived = syncer.SyncAndArchiveTitles(titles, convertedTitles, archive, books); Console.WriteLine($"Archived {archived} title{archived.SIf1()}"); diff --git a/Source/AzwConverter/AzwSettings.json b/Source/AzwConverter/AzwSettings.json index b60d069..1a73293 100644 --- a/Source/AzwConverter/AzwSettings.json +++ b/Source/AzwConverter/AzwSettings.json @@ -34,6 +34,11 @@ // Note: SaveCover must also be true for SaveCoverOnly to work. "SaveCoverOnly": false, + // Normally CbzMage only scans and converts books where the BookType is "comic". + // If you run into books that are ignored and you're sure they're comics try + // changing ConvertAllBookTypes to true. + "ConvertAllBookTypes": false, + // The converted titles directory is a subdirectory of TitlesDir. The default // name is "Converted Titles", you can change it to something else below. Don't // forget to rename the actual directory if you do. diff --git a/Source/AzwConverter/Settings.cs b/Source/AzwConverter/Settings.cs index df6e7df..11c602f 100644 --- a/Source/AzwConverter/Settings.cs +++ b/Source/AzwConverter/Settings.cs @@ -25,6 +25,8 @@ public static void SetConvertedTitlesDir(string dir) public static string CbzDir { get; set; } + public static bool ConvertAllBookTypes { get; set; } + public static bool SaveCover { get; set; } public static bool SaveCoverOnly { get; set; } public static string? SaveCoverDir { get; set; } diff --git a/Source/AzwConverter/TitleSyncer.cs b/Source/AzwConverter/TitleSyncer.cs index 6b7abf6..9f71d37 100644 --- a/Source/AzwConverter/TitleSyncer.cs +++ b/Source/AzwConverter/TitleSyncer.cs @@ -1,4 +1,5 @@ using AzwConverter.Engine; +using CbzMage.Shared.Extensions; using MobiMetadata; using System.Collections.Concurrent; @@ -6,11 +7,13 @@ namespace AzwConverter { public class TitleSyncer { - public async Task SyncBooksToTitlesAsync(IDictionary books, - IDictionary titles, ArchiveDb archive) + public async Task<(int skippedBooks, int ignoredBooks)> SyncBooksToTitlesAsync( + IDictionary books, IDictionary titles, ArchiveDb archive) { var booksWithErrors = new ConcurrentBag(); - var newOrArchivedTitles = new ConcurrentDictionary(); + var skippedBooks = new ConcurrentBag(); + + var addedTitles = new ConcurrentDictionary(); await Parallel.ForEachAsync(books, Settings.ParallelOptions, async (book, ct) => { @@ -36,6 +39,12 @@ await Parallel.ForEachAsync(books, Settings.ParallelOptions, async (book, ct) => var engine = new MetadataEngine(); (metadata, disposables) = await engine.ReadMetadataAsync(bookFiles); + if (!metadata.MobiHeader.ExthHeader.BookType.EqualsIgnoreCase("comic")) + { + skippedBooks.Add(bookId); + return; + } + MetadataManager.CacheMetadata(bookId, metadata, disposables); } catch (MobiMetadataException) @@ -63,7 +72,7 @@ async Task SyncAsync(string titleFile) await File.WriteAllTextAsync(file, bookId, CancellationToken.None); // Add archived/scanned title to list of current titles - newOrArchivedTitles[bookId] = new FileInfo(file); + addedTitles[bookId] = new FileInfo(file); } } }); @@ -73,12 +82,17 @@ async Task SyncAsync(string titleFile) books.Remove(bookId); } - foreach (var title in newOrArchivedTitles) + foreach (var bookId in skippedBooks) + { + books.Remove(bookId); + } + + foreach (var title in addedTitles) { - titles.Add(title); + titles.Add(title); } - return newOrArchivedTitles.Count; + return (skippedBooks: addedTitles.Count, ignoredBooks: skippedBooks.Count); } private static string TrimPublisher(string publisher) @@ -95,7 +109,7 @@ private static string TrimPublisher(string publisher) return publisher; } - public int SyncAndArchiveTitles(IDictionary titles, + public int SyncAndArchiveTitles(IDictionary titles, IDictionary convertedTitles, ArchiveDb archive, IDictionary books) { @@ -118,7 +132,7 @@ public int SyncAndArchiveTitles(IDictionary titles, // Sync title -> converted title if (convertedTitles.TryGetValue(bookId, out var convertedTitleFile) && convertedTitleFile.Name != titleFile.Name) - { + { var newConvertedTitleFile = Path.Combine(convertedTitleFile.DirectoryName!, titleFile.Name); convertedTitleFile.MoveTo(newConvertedTitleFile); }