Fixed a bug where Genre/Tags read in from ComicInfo were being normalized when they shouldn't.
This commit is contained in:
parent
d943c66bcf
commit
7fccabd479
5 changed files with 28 additions and 19 deletions
|
|
@ -18,9 +18,9 @@ public static class StringExtensions
|
|||
|
||||
// Remove all newline and control characters
|
||||
var sanitized = input
|
||||
.Replace(Environment.NewLine, "")
|
||||
.Replace("\n", "")
|
||||
.Replace("\r", "");
|
||||
.Replace(Environment.NewLine, string.Empty)
|
||||
.Replace("\n", string.Empty)
|
||||
.Replace("\r", string.Empty);
|
||||
|
||||
// Optionally remove other potentially unwanted characters
|
||||
sanitized = Regex.Replace(sanitized, @"[^\u0020-\u007E]", string.Empty); // Removes non-printable ASCII
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ public class GenreBuilder : IEntityBuilder<Genre>
|
|||
{
|
||||
Title = name.Trim().SentenceCase(),
|
||||
NormalizedTitle = name.ToNormalized(),
|
||||
Chapters = new List<Chapter>(),
|
||||
SeriesMetadatas = new List<SeriesMetadata>()
|
||||
Chapters = [],
|
||||
SeriesMetadatas = []
|
||||
};
|
||||
}
|
||||
|
||||
public GenreBuilder WithSeriesMetadata(SeriesMetadata seriesMetadata)
|
||||
{
|
||||
_genre.SeriesMetadatas ??= new List<SeriesMetadata>();
|
||||
_genre.SeriesMetadatas ??= [];
|
||||
_genre.SeriesMetadatas.Add(seriesMetadata);
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ public class TagBuilder : IEntityBuilder<Tag>
|
|||
{
|
||||
Title = name.Trim().SentenceCase(),
|
||||
NormalizedTitle = name.ToNormalized(),
|
||||
Chapters = new List<Chapter>(),
|
||||
SeriesMetadatas = new List<SeriesMetadata>()
|
||||
Chapters = [],
|
||||
SeriesMetadatas = []
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,12 @@ public static class GenreHelper
|
|||
public static async Task UpdateChapterGenres(Chapter chapter, IEnumerable<string> genreNames, IUnitOfWork unitOfWork)
|
||||
{
|
||||
// Normalize genre names once and store them in a hash set for quick lookups
|
||||
var normalizedGenresToAdd = new HashSet<string>(genreNames.Select(g => g.ToNormalized()));
|
||||
var normalizedToOriginal = genreNames
|
||||
.Select(g => new { Original = g, Normalized = g.ToNormalized() })
|
||||
.GroupBy(x => x.Normalized)
|
||||
.ToDictionary(g => g.Key, g => g.First().Original);
|
||||
|
||||
var normalizedGenresToAdd = new HashSet<string>(normalizedToOriginal.Keys);
|
||||
|
||||
// Remove genres that are no longer in the new list
|
||||
var genresToRemove = chapter.Genres
|
||||
|
|
@ -42,7 +47,7 @@ public static class GenreHelper
|
|||
// Find missing genres that are not in the database
|
||||
var missingGenres = normalizedGenresToAdd
|
||||
.Where(nt => !existingGenreTitles.ContainsKey(nt))
|
||||
.Select(title => new GenreBuilder(title).Build())
|
||||
.Select(nt => new GenreBuilder(normalizedToOriginal[nt]).Build())
|
||||
.ToList();
|
||||
|
||||
// Add missing genres to the database
|
||||
|
|
|
|||
|
|
@ -20,7 +20,13 @@ public static class TagHelper
|
|||
public static async Task UpdateChapterTags(Chapter chapter, IEnumerable<string> tagNames, IUnitOfWork unitOfWork)
|
||||
{
|
||||
// Normalize tag names once and store them in a hash set for quick lookups
|
||||
var normalizedTagsToAdd = new HashSet<string>(tagNames.Select(t => t.ToNormalized()));
|
||||
// Create a dictionary: normalized => original
|
||||
var normalizedToOriginal = tagNames
|
||||
.Select(t => new { Original = t, Normalized = t.ToNormalized() })
|
||||
.GroupBy(x => x.Normalized) // in case of duplicates
|
||||
.ToDictionary(g => g.Key, g => g.First().Original);
|
||||
|
||||
var normalizedTagsToAdd = new HashSet<string>(normalizedToOriginal.Keys);
|
||||
var existingTagsSet = new HashSet<string>(chapter.Tags.Select(t => t.NormalizedTitle));
|
||||
|
||||
var isModified = false;
|
||||
|
|
@ -30,7 +36,7 @@ public static class TagHelper
|
|||
.Where(t => !normalizedTagsToAdd.Contains(t.NormalizedTitle))
|
||||
.ToList();
|
||||
|
||||
if (tagsToRemove.Any())
|
||||
if (tagsToRemove.Count != 0)
|
||||
{
|
||||
foreach (var tagToRemove in tagsToRemove)
|
||||
{
|
||||
|
|
@ -47,7 +53,7 @@ public static class TagHelper
|
|||
// Find missing tags that are not already in the database
|
||||
var missingTags = normalizedTagsToAdd
|
||||
.Where(nt => !existingTagTitles.ContainsKey(nt))
|
||||
.Select(title => new TagBuilder(title).Build())
|
||||
.Select(nt => new TagBuilder(normalizedToOriginal[nt]).Build())
|
||||
.ToList();
|
||||
|
||||
// Add missing tags to the database if any
|
||||
|
|
@ -67,13 +73,11 @@ public static class TagHelper
|
|||
// Add the new or existing tags to the chapter
|
||||
foreach (var normalizedTitle in normalizedTagsToAdd)
|
||||
{
|
||||
var tag = existingTagTitles[normalizedTitle];
|
||||
if (existingTagsSet.Contains(normalizedTitle)) continue;
|
||||
|
||||
if (!existingTagsSet.Contains(normalizedTitle))
|
||||
{
|
||||
chapter.Tags.Add(tag);
|
||||
isModified = true;
|
||||
}
|
||||
var tag = existingTagTitles[normalizedTitle];
|
||||
chapter.Tags.Add(tag);
|
||||
isModified = true;
|
||||
}
|
||||
|
||||
// Commit changes if modifications were made to the chapter's tags
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue