feat: update ebook scanner to normalize metadata
Update extractEPUBMetadata: - Normalize tags for display using NormalizeTags() - Normalize contributors for display using NormalizeContributors() - Preserves extracted metadata formatting while ensuring consistency Update processEbookFile: - Add normalization before database insert - Generate tags_search using NormalizeTagsSearch() - Generate contributors_search using NormalizeContributorsSearch() - Pass both display and search fields to CreateMediaItem Scanner now produces normalized metadata matching user input normalization, ensuring consistency between scanned and manually entered media items. Relates to Tags & Contributors Migration Phase 7
This commit is contained in:
@@ -452,6 +452,14 @@ func (s *EbookScanner) processEbookFile(ctx context.Context, path string) error
|
||||
return fmt.Errorf("no library found for file path: %s", path)
|
||||
}
|
||||
|
||||
// Normalize metadata fields for display
|
||||
metadata.Contributors = utils.NormalizeContributors(metadata.Contributors)
|
||||
metadata.Tags = utils.NormalizeTags(metadata.Tags)
|
||||
|
||||
// Normalize search fields
|
||||
contributorsSearch := utils.NormalizeContributorsSearch(metadata.Contributors)
|
||||
tagsSearch := utils.NormalizeTagsSearch(metadata.Tags)
|
||||
|
||||
// Create media item in database
|
||||
createdItem, err := s.db.CreateMediaItem(ctx, database.CreateMediaItemParams{
|
||||
LibraryID: libraryID,
|
||||
@@ -469,7 +477,9 @@ func (s *EbookScanner) processEbookFile(ctx context.Context, path string) error
|
||||
Publisher: pgtype.Text{String: metadata.Publisher, Valid: metadata.Publisher != ""},
|
||||
DatePublished: pgtype.Date{Time: metadata.PublishDate, Valid: !metadata.PublishDate.IsZero()},
|
||||
Contributors: metadata.Contributors,
|
||||
ContributorsSearch: contributorsSearch,
|
||||
Tags: metadata.Tags,
|
||||
TagsSearch: tagsSearch,
|
||||
AddedByAdminID: s.adminID,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -576,8 +586,8 @@ func (s *EbookScanner) extractEPUBMetadata(path string) (*EbookMetadata, error)
|
||||
|
||||
// Contributors
|
||||
if contributors, err := book.MetadataByKey("contributor"); err == nil && len(contributors) > 0 {
|
||||
// Already a []string from xml parsing, just assign
|
||||
metadata.Contributors = contributors
|
||||
// Normalize contributors for display
|
||||
metadata.Contributors = utils.NormalizeContributors(contributors)
|
||||
}
|
||||
|
||||
// ISBN
|
||||
@@ -603,8 +613,8 @@ func (s *EbookScanner) extractEPUBMetadata(path string) (*EbookMetadata, error)
|
||||
|
||||
// Tags
|
||||
if tags, err := book.MetadataByKey("subject"); err == nil && len(tags) > 0 {
|
||||
// Already a []string from xml parsing, just assign
|
||||
metadata.Tags = tags
|
||||
// Normalize tags for display
|
||||
metadata.Tags = utils.NormalizeTags(tags)
|
||||
}
|
||||
|
||||
return metadata, nil
|
||||
|
||||
Reference in New Issue
Block a user