mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Adds independent metadata and artwork enrichment
Splits the single combined enrichment phase of the media library scan into independent, modular jobs, so that the metadata and the artwork of a book are enriched separately and only when their respective triggers fire. - Adds the MediaContributorRoleCategory enum (Other first, then Author, Translator, Illustrator, Publisher and Narrator) and makes the role category canonical, so that roles describing the same kind of contribution are never treated as distinct. - Realizes the media contributor bounded context: a MediaContributor is a person, unique by display name, without a role. The role moves to the per-work participation (BookContributors), so that a single contributor can play multiple roles. Contributors are created and linked by the metadata enrichment job, and exposed to subsequent jobs. - Makes the Book aggregate pure: the enrichment tracking state (metadata status, providers, timestamps and covers) no longer lives on the domain aggregate, but stays in the Books table, managed directly by the jobs. - Models artwork generically as a BookArtwork child table (type, ordinal, content hash, status and provider), so that each piece of artwork is tracked independently and a change of one does not require the others to be re-fetched. - Splits the scan DAG into ResultsSave, ProviderConfigurationInvalidation, MetadataEnrichment and ArtworkEnrichment jobs. The invalidation job fingerprints the provider configuration of a library and resets the enrichment state of the affected channel when it changed. The artwork job resolves the missing artwork, hashing it to detect identical covers and skip re-copying. Content-changed books are reset by the results save job. - Deletes the book and its stored artwork when the file disappears from the library. - Adds the migration creating the new tables, backfilling the existing covers into the artwork table, and adding the configuration fingerprints. - Localizes the new scan job stages, and fixes the invalidation job wiping the library content locations by persisting the fingerprints through the change tracker instead of the repository update action.
This commit is contained in:
1 parent
4ee2976806
commit
565fe68239
98 files changed
+5845
-630
No files matched your search
+8
-55
@@ -38,21 +38,6 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// </summary>
|
||||
public string Path { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status of the metadata enrichment of the book.
|
||||
/// </summary>
|
||||
public MetadataStatus MetadataStatus { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the metadata of the book was last enriched, if applicable.
|
||||
/// </summary>
|
||||
public Optional<DateTime> LastMetadataUpdateUtc { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the plugin that enriched the metadata of the book, if applicable.
|
||||
/// </summary>
|
||||
public Optional<string> MetadataProvider { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the format of the book (e.g., Hardcover, Paperback), if applicable.
|
||||
/// </summary>
|
||||
@@ -118,11 +103,6 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// </summary>
|
||||
public Optional<string> AppleBooksId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file system path of the cover image of the book, if applicable.
|
||||
/// </summary>
|
||||
public Optional<string> CoverImagePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of ISBN (International Standard Book Number) of the book.
|
||||
/// </summary>
|
||||
@@ -191,9 +171,6 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
LibraryId = libraryId;
|
||||
Path = path;
|
||||
Metadata = metadata;
|
||||
MetadataStatus = MetadataStatus.Pending;
|
||||
LastMetadataUpdateUtc = Optional<DateTime>.None();
|
||||
MetadataProvider = Optional<string>.None();
|
||||
Format = format;
|
||||
Edition = edition;
|
||||
VolumeNumber = volumeNumber;
|
||||
@@ -207,7 +184,6 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
GoogleBooksId = googleBooksId;
|
||||
BarnesAndNobleId = barnesAndNobleId;
|
||||
AppleBooksId = appleBooksId;
|
||||
CoverImagePath = Optional<string>.None();
|
||||
CreatedOnUtc = createdOnUtc;
|
||||
UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
|
||||
_isbns = isbns;
|
||||
@@ -368,36 +344,18 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the metadata of the book as enriched by the provided <paramref name="providerName"/>.
|
||||
/// Replaces the media contributors of the book with the provided <paramref name="contributors"/>, identified by their unique identifiers.
|
||||
/// </summary>
|
||||
/// <param name="providerName">The name of the metadata provider that enriched the book.</param>
|
||||
/// <param name="lastUpdateUtc">The date and time when the metadata of the book was enriched.</param>
|
||||
public void MarkMetadataAsEnriched(string providerName, DateTime lastUpdateUtc)
|
||||
/// <param name="contributors">The unique identifiers of the media contributors of the book.</param>
|
||||
public void UpdateContributors(IReadOnlyCollection<MediaContributorId> contributors)
|
||||
{
|
||||
MetadataProvider = providerName;
|
||||
LastMetadataUpdateUtc = lastUpdateUtc;
|
||||
MetadataStatus = MetadataStatus.Enriched;
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the aggregate
|
||||
_contributors.Clear();
|
||||
_contributors.AddRange(contributors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the metadata enrichment of the book as failed.
|
||||
/// </summary>
|
||||
public void MarkMetadataAsFailed()
|
||||
{
|
||||
MetadataStatus = MetadataStatus.Failed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the file system path of the cover image of the book.
|
||||
/// </summary>
|
||||
/// <param name="coverImagePath">The file system path of the cover image of the book.</param>
|
||||
public void SetBookCoverImagePath(string coverImagePath)
|
||||
{
|
||||
CoverImagePath = coverImagePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the enriched <paramref name="metadata"/> and the related fields to the book, marking its metadata as enriched by the provided <paramref name="providerName"/>.
|
||||
/// Applies the enriched <paramref name="metadata"/> and the related fields to the book.
|
||||
/// </summary>
|
||||
/// <param name="metadata">The enriched metadata of the book.</param>
|
||||
/// <param name="format">The optional format of the book.</param>
|
||||
@@ -415,8 +373,6 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// <param name="appleBooksId">The optional Apple Books ID of the book.</param>
|
||||
/// <param name="isbns">The list of ISBNs of the book.</param>
|
||||
/// <param name="ratings">The list of ratings for the book.</param>
|
||||
/// <param name="providerName">The name of the metadata provider that enriched the book.</param>
|
||||
/// <param name="lastUpdateUtc">The date and time when the metadata was enriched.</param>
|
||||
public void ApplyEnrichedMetadata(
|
||||
WrittenContentMetadata metadata,
|
||||
Optional<BookFormat> format,
|
||||
@@ -433,9 +389,7 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
Optional<string> barnesAndNobleId,
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<BookRating> ratings,
|
||||
string providerName,
|
||||
DateTime lastUpdateUtc)
|
||||
List<BookRating> ratings)
|
||||
{
|
||||
Metadata = metadata;
|
||||
Format = format;
|
||||
@@ -456,6 +410,5 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
_isbns.AddRange(isbns);
|
||||
_ratings.Clear();
|
||||
_ratings.AddRange(ratings);
|
||||
MarkMetadataAsEnriched(providerName, lastUpdateUtc);
|
||||
}
|
||||
}
|
||||
+16
-5
@@ -52,12 +52,23 @@ internal class BookLibraryTypeScanner : IBookLibraryTypeScanner
|
||||
mediaLibraryScanHashJob.AddChild(mediaLibraryScanResultsSaveJob);
|
||||
mediaLibraryScanResultsSaveJob.AddParent(mediaLibraryScanHashJob);
|
||||
|
||||
// the metadata enrichment job is always the last job in the directed acyclic job graph, running after the scan results save job,
|
||||
// so that the books are materialized before their metadata is enriched. The job itself is the host-side gate that skips the providers
|
||||
// requiring access to the web when the media library does not permit downloading data from the web, so that the local providers still run offline
|
||||
// the enrichment of the media library items is split into independent, modular jobs that run sequentially: the provider configuration
|
||||
// invalidation job invalidates the enrichment state of the items whose metadata or artwork providers changed since the last scan, the
|
||||
// metadata enrichment job enriches the metadata and links the media contributors, and the artwork enrichment job resolves the artwork.
|
||||
// The artwork enrichment job is always the last job in the directed acyclic job graph, running after the metadata enrichment job, so that
|
||||
// the artwork is resolved after the metadata, and thus after the contributors that provide the author names used to build the artwork directories.
|
||||
IMediaLibraryScanProviderConfigurationInvalidationJob mediaLibraryScanProviderConfigurationInvalidationJob = _mediaScanJobFactory.CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>(libraryId);
|
||||
IMediaLibraryScanMetadataEnrichmentJob mediaLibraryScanMetadataEnrichmentJob = _mediaScanJobFactory.CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
mediaLibraryScanResultsSaveJob.AddChild(mediaLibraryScanMetadataEnrichmentJob);
|
||||
mediaLibraryScanMetadataEnrichmentJob.AddParent(mediaLibraryScanResultsSaveJob);
|
||||
IMediaLibraryScanArtworkEnrichmentJob mediaLibraryScanArtworkEnrichmentJob = _mediaScanJobFactory.CreateJob<IMediaLibraryScanArtworkEnrichmentJob>(libraryId);
|
||||
|
||||
mediaLibraryScanResultsSaveJob.AddChild(mediaLibraryScanProviderConfigurationInvalidationJob);
|
||||
mediaLibraryScanProviderConfigurationInvalidationJob.AddParent(mediaLibraryScanResultsSaveJob);
|
||||
|
||||
mediaLibraryScanProviderConfigurationInvalidationJob.AddChild(mediaLibraryScanMetadataEnrichmentJob);
|
||||
mediaLibraryScanMetadataEnrichmentJob.AddParent(mediaLibraryScanProviderConfigurationInvalidationJob);
|
||||
|
||||
mediaLibraryScanMetadataEnrichmentJob.AddChild(mediaLibraryScanArtworkEnrichmentJob);
|
||||
mediaLibraryScanArtworkEnrichmentJob.AddParent(mediaLibraryScanMetadataEnrichmentJob);
|
||||
|
||||
// return the top level jobs that will be triggered when the scan will be started
|
||||
yield return fileSystemDiscoveryJob;
|
||||
|
||||
Reference in new issue
Block a user