using System.Collections.Generic; using System.IO; using System.Linq; using API.Entities; using API.Services.Tasks.Scanner.Parser; namespace API.Extensions; #nullable enable public static class ParserInfoListExtensions { /// /// Selects distinct volume numbers by the "Volumes" key on the ParserInfo /// /// /// public static IList DistinctVolumes(this IList infos) { return infos.Select(p => p.Volumes).Distinct().ToList(); } /// /// Checks if a list of ParserInfos has a given chapter or not. Lookup occurs on Range property. If a chapter is /// special, then the is matched, else the field is checked. /// /// /// /// public static bool HasInfo(this IList infos, Chapter chapter) { var chapterFiles = chapter.Files.Select(x => Parser.NormalizePath(x.FilePath)).ToList(); var infoFiles = infos.Select(x => Parser.NormalizePath(x.FullFilePath)).ToList(); return infoFiles.Intersect(chapterFiles).Any(); } }