mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-03-10 12:05:51 -04:00
Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com> Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
using System.Collections.Concurrent;
|
|
using Kavita.Common.Extensions;
|
|
using Kavita.Models.Entities.Enums;
|
|
using Kavita.Models.Parser;
|
|
|
|
namespace Kavita.Services.Tests.Helpers;
|
|
|
|
public static class ParserInfoFactory
|
|
{
|
|
public static ParserInfo CreateParsedInfo(string series, string volumes, string chapters, string filename, bool isSpecial)
|
|
{
|
|
return new ParserInfo()
|
|
{
|
|
Chapters = chapters,
|
|
Edition = "",
|
|
Format = MangaFormat.Archive,
|
|
FullFilePath = Path.Join(@"/manga/", filename),
|
|
Filename = filename,
|
|
IsSpecial = isSpecial,
|
|
Title = Path.GetFileNameWithoutExtension(filename),
|
|
Series = series,
|
|
Volumes = volumes
|
|
};
|
|
}
|
|
|
|
public static void AddToParsedInfo(IDictionary<ParsedSeries, IList<ParserInfo>> collectedSeries, ParserInfo info)
|
|
{
|
|
var existingKey = collectedSeries.Keys.FirstOrDefault(ps =>
|
|
ps.Format == info.Format && ps.NormalizedName == info.Series.ToNormalized());
|
|
existingKey ??= new ParsedSeries()
|
|
{
|
|
Format = info.Format,
|
|
Name = info.Series,
|
|
NormalizedName = info.Series.ToNormalized()
|
|
};
|
|
if (collectedSeries.GetType() == typeof(ConcurrentDictionary<,>))
|
|
{
|
|
((ConcurrentDictionary<ParsedSeries, IList<ParserInfo>>) collectedSeries).AddOrUpdate(existingKey, new List<ParserInfo>() {info}, (_, oldValue) =>
|
|
{
|
|
oldValue ??= new List<ParserInfo>();
|
|
if (!oldValue.Contains(info))
|
|
{
|
|
oldValue.Add(info);
|
|
}
|
|
|
|
return oldValue;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
if (!collectedSeries.ContainsKey(existingKey))
|
|
{
|
|
collectedSeries.Add(existingKey, new List<ParserInfo>() {info});
|
|
}
|
|
else
|
|
{
|
|
var list = collectedSeries[existingKey];
|
|
if (!list.Contains(info))
|
|
{
|
|
list.Add(info);
|
|
}
|
|
|
|
collectedSeries[existingKey] = list;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|