From 9c57984bff7f4f0fe9ed44a1a60e36292083e91c Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Tue, 10 Aug 2021 19:05:16 -0500 Subject: [PATCH] Scan Issues (#470) * Fixed an oversight where unique file extensions for KavitaStats wouldn't ignore case. * Fixed an issue where series were getting removed then re-added due to bad logic when comparing if the series from disk matched the series in DB based on format. --- API/Data/FileRepository.cs | 4 +-- API/Services/Tasks/ScannerService.cs | 42 ++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/API/Data/FileRepository.cs b/API/Data/FileRepository.cs index a90ff4df5..c3234abba 100644 --- a/API/Data/FileRepository.cs +++ b/API/Data/FileRepository.cs @@ -20,7 +20,7 @@ namespace API.Data { var fileExtensions = await _dbContext.MangaFile .AsNoTracking() - .Select(x => x.FilePath) + .Select(x => x.FilePath.ToLower()) .Distinct() .ToArrayAsync(); @@ -32,4 +32,4 @@ namespace API.Data return uniqueFileTypes; } } -} \ No newline at end of file +} diff --git a/API/Services/Tasks/ScannerService.cs b/API/Services/Tasks/ScannerService.cs index 33d2d8ea9..655529f60 100644 --- a/API/Services/Tasks/ScannerService.cs +++ b/API/Services/Tasks/ScannerService.cs @@ -260,13 +260,43 @@ namespace API.Services.Tasks public IEnumerable FindSeriesNotOnDisk(ICollection existingSeries, Dictionary> parsedSeries) { - // It is safe to check only first since Parser ensures that a Series only has one type - var format = MangaFormat.Unknown; - var firstPs = parsedSeries.Keys.DistinctBy(ps => ps.Format).FirstOrDefault(); - if (firstPs != null) format = firstPs.Format; - var foundSeries = parsedSeries.Select(s => s.Key.Name).ToList(); - return existingSeries.Where(es => !es.NameInList(foundSeries) || es.Format != format); + return existingSeries.Where(es => !es.NameInList(foundSeries) && !SeriesHasMatchingParserInfoFormat(es, parsedSeries)); + } + + /// + /// Checks each parser info to see if there is a name match and if so, checks if the format matches the Series object. + /// This accounts for if the Series has an Unknown type and if so, considers it matching. + /// + /// + /// + /// + private static bool SeriesHasMatchingParserInfoFormat(Series series, + Dictionary> parsedSeries) + { + var format = MangaFormat.Unknown; + foreach (var pSeries in parsedSeries.Keys) + { + var name = pSeries.Name; + var normalizedName = Parser.Parser.Normalize(name); + + if (normalizedName == series.NormalizedName || + normalizedName == Parser.Parser.Normalize(series.Name) || + name == series.Name || name == series.LocalizedName || + name == series.OriginalName || + normalizedName == Parser.Parser.Normalize(series.OriginalName)) + { + format = pSeries.Format; + break; + } + } + + if (series.Format == MangaFormat.Unknown && format != MangaFormat.Unknown) + { + return true; + } + + return format == series.Format; } ///