Adds the music library persistence model, its repositories, and the scanning migration

This commit is contained in:
BinaryAlley committed 2026-10-08 20:48:00 +03:00
1 parent 4f0526faa4
commit 00376c8313
63 files changed
+8679 -203

No files matched your search

@@ -40,6 +40,15 @@ public interface IBookRepository : IRepository<BookEntity>,
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="BookEntity"/> stored at the provided path, or an error.</returns>
Task<Result<BookEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken);
/// <summary>
/// Gets the subset of <paramref name="paths"/> that is already used by a book of the library identified by <paramref name="libraryId"/>.
/// </summary>
/// <param name="libraryId">The Id of the library whose books are searched.</param>
/// <param name="paths">The book paths to check.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the paths that are already used, or an error.</returns>
Task<Result<IReadOnlyCollection<string>>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection<string> paths, CancellationToken cancellationToken);
/// <summary>
/// Gets a page of the books of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet,
/// ordered by path, using keyset pagination.
@@ -55,6 +55,15 @@ public interface ILibraryScanStagingResultsRepository : IRepository<LibraryScanS
/// <returns>An <see cref="Result{TValue}"/> containing either the paths of the changed staging results, or an error.</returns>
Task<Result<IReadOnlyList<string>>> GetChangedPathsAsync(Guid scanId, CancellationToken cancellationToken);
/// <summary>
/// Gets the paths of the media library scan staging results of the current scan that are new or changed, meaning they need their content hashed
/// and their metadata extracted.
/// </summary>
/// <param name="scanId">The unique identifier of the media library scan whose staging result paths are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the paths of the staging results that need rehashing, or an error.</returns>
Task<Result<IReadOnlyList<string>>> GetPathsNeedingRehashAsync(Guid scanId, CancellationToken cancellationToken);
/// <summary>
/// Updates the content hashes of the provided media library scan staging results.
/// </summary>
@@ -20,7 +20,8 @@ public interface IAlbumRepository : IRepository<AlbumEntity>,
IInsertRepositoryAction<AlbumEntity>,
IUpdateRepositoryAction<AlbumEntity>,
IApplyUpdateRepositoryAction<AlbumEntity>,
IGetByIdRepositoryAction<AlbumEntity, Guid>
IGetByIdRepositoryAction<AlbumEntity, Guid>,
IDeleteByIdRepositoryAction<Guid>
{
/// <summary>
/// Gets all the albums of the artist identified by <paramref name="artistId"/>.
@@ -38,4 +39,67 @@ public interface IAlbumRepository : IRepository<AlbumEntity>,
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a paginated result of <see cref="AlbumLiteRow"/>, or an error.</returns>
Task<Result<PaginatedResultDto<AlbumLiteRow>>> GetAlbumsLiteByArtistIdAsync(Guid artistId, PaginationDataDto? paginationData, CancellationToken cancellationToken);
/// <summary>
/// Gets the album of the artist identified by <paramref name="artistId"/> that has the provided <paramref name="title"/>.
/// </summary>
/// <param name="artistId">The Id of the artist whose album is retrieved.</param>
/// <param name="title">The title of the album to retrieve.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="AlbumEntity"/> with the provided title, or an error.</returns>
Task<Result<AlbumEntity?>> GetByTitleAsync(Guid artistId, string title, CancellationToken cancellationToken);
/// <summary>
/// Gets the album of the artist identified by <paramref name="artistId"/> that owns a track stored in the provided <paramref name="directoryPath"/>.
/// </summary>
/// <param name="artistId">The Id of the artist whose album is retrieved.</param>
/// <param name="directoryPath">The file system path of the album directory the album owns.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="AlbumEntity"/> owning the directory, or an error.</returns>
Task<Result<AlbumEntity?>> GetByTrackDirectoryAsync(Guid artistId, string directoryPath, CancellationToken cancellationToken);
/// <summary>
/// Gets the number of albums of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet.
/// </summary>
/// <param name="libraryId">The Id of the media library whose albums are counted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the number of albums needing their metadata enriched, or an error.</returns>
Task<Result<int>> GetAlbumsNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets the number of albums of the media library identified by <paramref name="libraryId"/> whose artwork has not been resolved yet,
/// meaning they have no artwork that is either enriched or confirmed as unavailable.
/// </summary>
/// <param name="libraryId">The Id of the media library whose albums are counted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the number of albums needing their artwork resolved, or an error.</returns>
Task<Result<int>> GetAlbumsNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets a page of the albums of the media library identified by <paramref name="libraryId"/> whose artwork has not been resolved yet,
/// together with their artist, ordered by Id, excluding the provided albums.
/// </summary>
/// <param name="libraryId">The Id of the media library whose albums are retrieved.</param>
/// <param name="excludedAlbumIds">The Ids of the albums that were already processed in the current run and must not be retrieved again.</param>
/// <param name="pageSize">The maximum number of albums to retrieve.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a page of albums needing their artwork resolved, or an error.</returns>
Task<Result<IReadOnlyList<AlbumEntity>>> GetAlbumsNeedingArtworkAsync(Guid libraryId, IReadOnlyCollection<Guid> excludedAlbumIds, int pageSize, CancellationToken cancellationToken);
/// <summary>
/// Gets the file system path of one track of each of the albums identified by <paramref name="albumIds"/>, keyed by the Id of the album.
/// </summary>
/// <param name="albumIds">The Ids of the albums whose track path is retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the file system path of a track of each album, or an error.</returns>
Task<Result<IReadOnlyDictionary<Guid, string>>> GetFirstTrackPathsByAlbumIdsAsync(IReadOnlyCollection<Guid> albumIds, CancellationToken cancellationToken);
/// <summary>
/// Resets the metadata enrichment status of all the albums of the media library identified by <paramref name="libraryId"/>,
/// so that they are re-enriched, because the metadata provider configuration of the library changed.
/// </summary>
/// <param name="libraryId">The Id of the media library whose albums are reset.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
}
@@ -3,7 +3,11 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.Mu
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
@@ -19,4 +23,59 @@ public interface IArtistRepository : IRepository<ArtistEntity>,
IGetAllLiteRepositoryAction<ArtistEntity, ArtistLiteRow>,
IDeleteByIdRepositoryAction<Guid>
{
/// <summary>
/// Gets the artist of the library identified by <paramref name="libraryId"/> that has the provided <paramref name="name"/>.
/// </summary>
/// <param name="libraryId">The Id of the library whose artist is retrieved.</param>
/// <param name="name">The name of the artist to retrieve.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="ArtistEntity"/> with the provided name, or an error.</returns>
Task<Result<ArtistEntity?>> GetByNameAsync(Guid libraryId, string name, CancellationToken cancellationToken);
/// <summary>
/// Gets a page of the artists of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet,
/// together with their albums and tracks and the collections needed to enrich them, ordered by name, using keyset pagination.
/// </summary>
/// <param name="libraryId">The Id of the media library whose artists are retrieved.</param>
/// <param name="lastName">The name of the last retrieved artist, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
/// <param name="pageSize">The maximum number of artists to retrieve.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a page of artists needing their metadata enriched, or an error.</returns>
Task<Result<IReadOnlyList<ArtistEntity>>> GetArtistsNeedingMetadataAsync(Guid libraryId, string? lastName, int pageSize, CancellationToken cancellationToken);
/// <summary>
/// Gets the number of artists of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet.
/// </summary>
/// <param name="libraryId">The Id of the media library whose artists are counted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the number of artists needing their metadata enriched, or an error.</returns>
Task<Result<int>> GetArtistsNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets the number of artists of the media library identified by <paramref name="libraryId"/> whose artwork has not been resolved yet.
/// </summary>
/// <param name="libraryId">The Id of the media library whose artists are counted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the number of artists needing their artwork resolved, or an error.</returns>
Task<Result<int>> GetArtistsNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets a page of the artists of the media library identified by <paramref name="libraryId"/> whose artwork has not been resolved yet,
/// together with their albums and tracks, ordered by name, using keyset pagination.
/// </summary>
/// <param name="libraryId">The Id of the media library whose artists are retrieved.</param>
/// <param name="lastName">The name of the last retrieved artist, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
/// <param name="pageSize">The maximum number of artists to retrieve.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a page of artists needing their artwork resolved, or an error.</returns>
Task<Result<IReadOnlyList<ArtistEntity>>> GetArtistsNeedingArtworkAsync(Guid libraryId, string? lastName, int pageSize, CancellationToken cancellationToken);
/// <summary>
/// Resets the metadata enrichment status of all the artists of the media library identified by <paramref name="libraryId"/>,
/// so that they are re-enriched, because the metadata provider configuration of the library changed.
/// </summary>
/// <param name="libraryId">The Id of the media library whose artists are reset.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
}
@@ -0,0 +1,35 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
/// <summary>
/// Interface for the repository for the music metadata staged during a media library scan.
/// </summary>
public interface IMusicLibraryScanItemMetadataRepository : IRepository<MusicLibraryScanItemMetadataEntity>,
IInsertRangeRepositoryAction<MusicLibraryScanItemMetadataEntity>
{
/// <summary>
/// Gets all the staged music metadata items of the media library scan identified by <paramref name="scanId"/>.
/// </summary>
/// <param name="scanId">The Id of the media library scan whose staged music metadata is retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="MusicLibraryScanItemMetadataEntity"/>, or an error.</returns>
Task<Result<IReadOnlyList<MusicLibraryScanItemMetadataEntity>>> GetByScanIdAsync(Guid scanId, CancellationToken cancellationToken);
/// <summary>
/// Deletes all the staged music metadata items of the media library scan identified by <paramref name="scanId"/>.
/// </summary>
/// <param name="scanId">The Id of the media library scan whose staged music metadata is deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Deleted>> DeleteByScanIdAsync(Guid scanId, CancellationToken cancellationToken);
}
@@ -20,7 +20,8 @@ public interface ITrackRepository : IRepository<TrackEntity>,
IInsertRepositoryAction<TrackEntity>,
IUpdateRepositoryAction<TrackEntity>,
IApplyUpdateRepositoryAction<TrackEntity>,
IGetByIdRepositoryAction<TrackEntity, Guid>
IGetByIdRepositoryAction<TrackEntity, Guid>,
IDeleteByIdRepositoryAction<Guid>
{
/// <summary>
/// Gets the subset of <paramref name="paths"/> that is already used by a track of the library identified by <paramref name="libraryId"/>.
@@ -47,4 +48,40 @@ public interface ITrackRepository : IRepository<TrackEntity>,
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either a paginated result of <see cref="TrackLiteRow"/>, or an error.</returns>
Task<Result<PaginatedResultDto<TrackLiteRow>>> GetTracksLiteByAlbumIdAsync(Guid albumId, PaginationDataDto? paginationData, CancellationToken cancellationToken);
/// <summary>
/// Gets the track of the library identified by <paramref name="libraryId"/> that is stored at the provided <paramref name="path"/>.
/// </summary>
/// <param name="libraryId">The Id of the library whose track is retrieved.</param>
/// <param name="path">The file system path of the track to retrieve.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="TrackEntity"/> stored at the provided path, or an error.</returns>
Task<Result<TrackEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken);
/// <summary>
/// Resets the enrichment state of the tracks stored at the provided <paramref name="paths"/> in the media library identified by
/// <paramref name="libraryId"/>, together with their albums and artists, so that they are re-enriched, because their content changed since the last scan.
/// </summary>
/// <param name="libraryId">The Id of the media library whose tracks are reset.</param>
/// <param name="paths">The file system paths of the tracks whose enrichment state is reset.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> ResetEnrichmentStateForPathsAsync(Guid libraryId, IReadOnlyCollection<string> paths, CancellationToken cancellationToken);
/// <summary>
/// Gets the number of tracks of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet.
/// </summary>
/// <param name="libraryId">The Id of the media library whose tracks are counted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the number of tracks needing their metadata enriched, or an error.</returns>
Task<Result<int>> GetTracksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Resets the metadata enrichment status of all the tracks of the media library identified by <paramref name="libraryId"/>,
/// so that they are re-enriched, because the metadata provider configuration of the library changed.
/// </summary>
/// <param name="libraryId">The Id of the media library whose tracks are reset.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
}