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; } ///