Kavita/API/Helpers/SeriesHelper.cs
Joseph Milazzo ce3bd92244
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.
2022-01-16 15:48:15 -08:00

47 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using API.Entities;
using API.Entities.Enums;
using API.Services.Tasks.Scanner;
namespace API.Helpers;
public static class SeriesHelper
{
/// <summary>
/// Given a parsedSeries checks if any of the names match against said Series and the format matches
/// </summary>
/// <param name="series"></param>
/// <param name="parsedInfoKey"></param>
/// <returns></returns>
public static bool FindSeries(Series series, ParsedSeries parsedInfoKey)
{
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);
}
/// <summary>
/// Removes all instances of missingSeries' Series from existingSeries Collection. Existing series is updated by
/// reference and the removed element count is returned.
/// </summary>
/// <param name="existingSeries">Existing Series in DB</param>
/// <param name="missingSeries">Series not found on disk or can't be parsed</param>
/// <param name="removeCount"></param>
/// <returns>the updated existingSeries</returns>
public static IEnumerable<Series> RemoveMissingSeries(IList<Series> existingSeries, IEnumerable<Series> missingSeries, out int removeCount)
{
var existingCount = existingSeries.Count;
var missingList = missingSeries.ToList();
existingSeries = existingSeries.Where(
s => !missingList.Exists(
m => m.NormalizedName.Equals(s.NormalizedName) && m.Format == s.Format)).ToList();
removeCount = existingCount - existingSeries.Count;
return existingSeries;
}
}