Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Scan Issues (#470)

Joseph Milazzo9c57984bff7f
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<Series> FindSeriesNotOnDisk(ICollection<Series> existingSeries, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)
{
- // It is safe to check only first since Parser ensures that a Series only has one type
+ var foundSeries = parsedSeries.Select(s => s.Key.Name).ToList();
+ return existingSeries.Where(es => !es.NameInList(foundSeries) && !SeriesHasMatchingParserInfoFormat(es, parsedSeries));
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="series"></param>
+ /// <param name="parsedSeries"></param>
+ /// <returns></returns>
+ private static bool SeriesHasMatchingParserInfoFormat(Series series,
+ Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)
+ {
var format = MangaFormat.Unknown;
- var firstPs = parsedSeries.Keys.DistinctBy(ps => ps.Format).FirstOrDefault();
- if (firstPs != null) format = firstPs.Format;
+ 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;
+ }
+ }
- var foundSeries = parsedSeries.Select(s => s.Key.Name).ToList();
- return existingSeries.Where(es => !es.NameInList(foundSeries) || es.Format != format);
+ if (series.Format == MangaFormat.Unknown && format != MangaFormat.Unknown)
+ {
+ return true;
+ }
+
+ return format == series.Format;
}
/// <summary>