From ce3bd92244aa1a8cb560a209b9403863e0fbd052 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sun, 16 Jan 2022 15:48:15 -0800 Subject: [PATCH] Scanner not merging with series that has LocalizedName match (#950) * When performing a scan, series should group if they share the same localized name as a pre-existing series. * Fixed a bug where a series with a different name and localized name weren't merging with a different set of files with the same naming as localized name. --- API.Tests/Helpers/SeriesHelperTests.cs | 35 +++++++++++++++++++ API/Helpers/SeriesHelper.cs | 4 ++- .../Tasks/Scanner/ParseScannedFiles.cs | 15 +++++--- API/Services/Tasks/ScannerService.cs | 4 ++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/API.Tests/Helpers/SeriesHelperTests.cs b/API.Tests/Helpers/SeriesHelperTests.cs index df31a9446..8acd4bb85 100644 --- a/API.Tests/Helpers/SeriesHelperTests.cs +++ b/API.Tests/Helpers/SeriesHelperTests.cs @@ -102,6 +102,41 @@ public class SeriesHelperTests NormalizedName = API.Parser.Parser.Normalize("SomethingRandom") })); } + + [Fact] + public void FindSeries_ShouldFind_UsingLocalizedName() + { + var series = DbFactory.Series("Darker than Black"); + series.LocalizedName = "Something Random"; + series.Format = MangaFormat.Image; + Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries() + { + Format = MangaFormat.Image, + Name = "Something Random", + NormalizedName = API.Parser.Parser.Normalize("Something Random") + })); + + Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries() + { + Format = MangaFormat.Image, + Name = "Something Random".ToLower(), + NormalizedName = API.Parser.Parser.Normalize("Something Random") + })); + + Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries() + { + Format = MangaFormat.Image, + Name = "Something Random".ToUpper(), + NormalizedName = API.Parser.Parser.Normalize("Something Random") + })); + + Assert.True(SeriesHelper.FindSeries(series, new ParsedSeries() + { + Format = MangaFormat.Image, + Name = "SomethingRandom".ToUpper(), + NormalizedName = API.Parser.Parser.Normalize("SomethingRandom") + })); + } #endregion [Fact] diff --git a/API/Helpers/SeriesHelper.cs b/API/Helpers/SeriesHelper.cs index 7aee8bc89..b03ebad18 100644 --- a/API/Helpers/SeriesHelper.cs +++ b/API/Helpers/SeriesHelper.cs @@ -16,7 +16,9 @@ public static class SeriesHelper /// public static bool FindSeries(Series series, ParsedSeries parsedInfoKey) { - return (series.NormalizedName.Equals(parsedInfoKey.NormalizedName) || Parser.Parser.Normalize(series.OriginalName).Equals(parsedInfoKey.NormalizedName)) + return (series.NormalizedName.Equals(parsedInfoKey.NormalizedName) + || Parser.Parser.Normalize(series.OriginalName).Equals(parsedInfoKey.NormalizedName) + || Parser.Parser.Normalize(series.LocalizedName).Equals(parsedInfoKey.NormalizedName)) && (series.Format == parsedInfoKey.Format || series.Format == MangaFormat.Unknown); } diff --git a/API/Services/Tasks/Scanner/ParseScannedFiles.cs b/API/Services/Tasks/Scanner/ParseScannedFiles.cs index 7ccb9232a..50cb98da9 100644 --- a/API/Services/Tasks/Scanner/ParseScannedFiles.cs +++ b/API/Services/Tasks/Scanner/ParseScannedFiles.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using API.Entities; using API.Entities.Enums; +using API.Helpers; using API.Parser; using Microsoft.Extensions.Logging; @@ -45,17 +46,23 @@ namespace API.Services.Tasks.Scanner } /// - /// Gets the list of parserInfos given a Series. If the series does not exist within, return empty list. + /// Gets the list of all parserInfos given a Series (Will match on Name, LocalizedName, OriginalName). If the series does not exist within, return empty list. /// /// /// /// public static IList GetInfosByName(Dictionary> parsedSeries, Series series) { - var existingKey = parsedSeries.Keys.FirstOrDefault(ps => - ps.Format == series.Format && ps.NormalizedName.Equals(Parser.Parser.Normalize(series.OriginalName))); + var allKeys = parsedSeries.Keys.Where(ps => + SeriesHelper.FindSeries(series, ps)); - return existingKey != null ? parsedSeries[existingKey] : new List(); + var infos = new List(); + foreach (var key in allKeys) + { + infos.AddRange(parsedSeries[key]); + } + + return infos; } /// diff --git a/API/Services/Tasks/ScannerService.cs b/API/Services/Tasks/ScannerService.cs index f2daee1b5..c44d9b98f 100644 --- a/API/Services/Tasks/ScannerService.cs +++ b/API/Services/Tasks/ScannerService.cs @@ -145,6 +145,7 @@ public class ScannerService : IScannerService // At this point, parsedSeries will have at least one key and we can perform the update. If it still doesn't, just return and don't do anything if (parsedSeries.Count == 0) return; + // Merge any series together that might have different ParsedSeries but belong to another group of ParsedSeries try { UpdateSeries(series, parsedSeries, allPeople, allTags, allGenres, library.Type); @@ -167,7 +168,7 @@ public class ScannerService : IScannerService { var keys = parsedSeries.Keys; foreach (var key in keys.Where(key => - !series.NameInParserInfo(parsedSeries[key].FirstOrDefault()) || series.Format != key.Format)) + series.Format != key.Format || !SeriesHelper.FindSeries(series, key))) { parsedSeries.Remove(key); } @@ -460,6 +461,7 @@ public class ScannerService : IScannerService { _logger.LogInformation("[ScannerService] Processing series {SeriesName}", series.OriginalName); + // Get all associated ParsedInfos to the series. This includes infos that use a different filename that matches Series LocalizedName var parsedInfos = ParseScannedFiles.GetInfosByName(parsedSeries, series); UpdateVolumes(series, parsedInfos, allPeople, allTags, allGenres); series.Pages = series.Volumes.Sum(v => v.Pages);