Adds music page play affordances and shuffle playback

Adds play and shuffle actions to music library, artist, and album cards.

Adds the library play context and the uniform shuffle endpoint.

Expands the player bar with queue covers, now playing details, and release type.

Updates the bundled themes, API documentation, and the user manual.
This commit is contained in:
BinaryAlley committed 2026-10-19 17:49:00 +03:00
1 parent 93821a2776
commit 067e9a21d0
132 files changed
+2935 -715

No files matched your search

@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
/// <summary>
/// Read model of a track returned by a randomized shuffle query, carrying everything the client needs to queue and play it.
/// </summary>
public sealed record ShuffleTrackRowDto
{
/// <summary>
/// Gets the Id of the track.
/// </summary>
public required Guid TrackId { get; init; }
/// <summary>
/// Gets the title of the track.
/// </summary>
public required string Title { get; init; }
/// <summary>
/// Gets the duration of the track in seconds.
/// </summary>
public int DurationInSeconds { get; init; }
/// <summary>
/// Gets the Id of the album the track belongs to.
/// </summary>
public required Guid AlbumId { get; init; }
/// <summary>
/// Gets the title of the album the track belongs to.
/// </summary>
public required string AlbumTitle { get; init; }
/// <summary>
/// Gets the Id of the artist the album belongs to.
/// </summary>
public required Guid ArtistId { get; init; }
/// <summary>
/// Gets the path of the cover of the album, if available.
/// </summary>
public string? CoverPath { get; init; }
}
@@ -49,6 +49,19 @@ public interface ITrackRepository : IRepository<TrackEntity>,
/// <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 a uniformly random selection of tracks of the library identified by <paramref name="libraryId"/>, optionally scoped to
/// an artist or an album, excluding the tracks in <paramref name="excludedTrackIds"/>.
/// </summary>
/// <param name="libraryId">The Id of the library whose tracks are sampled.</param>
/// <param name="artistId">The Id of the artist whose tracks are sampled, or <see langword="null"/> for every artist of the library.</param>
/// <param name="albumId">The Id of the album whose tracks are sampled, or <see langword="null"/> for every album of the scope.</param>
/// <param name="excludedTrackIds">The tracks that must not be returned.</param>
/// <param name="count">The maximum number of tracks to return.</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="ShuffleTrackRowDto"/>, or an error.</returns>
Task<Result<IReadOnlyList<ShuffleTrackRowDto>>> GetShuffleTracksLiteAsync(Guid libraryId, Guid? artistId, Guid? albumId, IReadOnlyCollection<Guid> excludedTrackIds, int count, CancellationToken cancellationToken);
/// <summary>
/// Gets the track of the library identified by <paramref name="libraryId"/> that is stored at the provided <paramref name="path"/>.
/// </summary>
@@ -170,7 +170,7 @@ public static class AlbumEntityMapping
repositoryEntity.ReleaseCountry,
repositoryEntity.ReleaseVersion
);
// language and original language make sense only if their subproperties have values
// Language and original language make sense only if their subproperties have values.
LanguageInfoDto? languageInfo = !string.IsNullOrWhiteSpace(repositoryEntity.LanguageCode) ||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageName) ||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageNativeName)
@@ -207,6 +207,7 @@ public static class AlbumEntityMapping
return new AlbumResponse(
repositoryEntity.Id,
repositoryEntity.ArtistId,
repositoryEntity.Artist?.Name ?? string.Empty,
repositoryEntity.LibraryId,
metadata,
repositoryEntity.MediaFormat,
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
/// <summary>
/// Extension methods for converting <see cref="ShuffleTrackRowDto"/>.
/// </summary>
public static class ShuffleTrackRowDtoMapping
{
/// <summary>
/// Converts <paramref name="readModel"/> to <see cref="ShuffleTrackResponse"/>.
/// </summary>
/// <param name="readModel">The read model to be converted.</param>
/// <returns>The converted response.</returns>
public static ShuffleTrackResponse ToResponse(this ShuffleTrackRowDto readModel)
{
return new ShuffleTrackResponse(
readModel.TrackId,
readModel.Title,
readModel.DurationInSeconds,
readModel.AlbumId,
readModel.AlbumTitle,
readModel.ArtistId,
readModel.CoverPath);
}
/// <summary>
/// Converts <paramref name="readModels"/> to a collection of <see cref="ShuffleTrackResponse"/>.
/// </summary>
/// <param name="readModels">The read models to be converted.</param>
/// <returns>The converted responses.</returns>
public static IReadOnlyList<ShuffleTrackResponse> ToResponses(this IEnumerable<ShuffleTrackRowDto> readModels)
{
return [.. readModels.Select(readModel => readModel.ToResponse())];
}
}
@@ -0,0 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.ShuffleTracks;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
/// <summary>
/// Extension methods for converting <see cref="ShuffleTracksRequest"/>.
/// </summary>
public static class ShuffleTracksRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="ShuffleTracksQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <param name="libraryId">The Id of the library the tracks are sampled from, taken from the route.</param>
/// <returns>The converted query.</returns>
public static ShuffleTracksQuery ToQuery(this ShuffleTracksRequest request, string? libraryId)
{
return new ShuffleTracksQuery(
libraryId,
request.Count,
request.ArtistId,
request.AlbumId,
request.ExcludedTrackIds);
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.ShuffleTracks;
/// <summary>
/// Query for getting a random selection of tracks from a media library, an artist or an album.
/// </summary>
/// <param name="LibraryId">The unique identifier of the media library the tracks are sampled from, taken from the route.</param>
/// <param name="Count">The maximum number of tracks to return.</param>
/// <param name="ArtistId">The unique identifier of the artist whose tracks are sampled, if applicable.</param>
/// <param name="AlbumId">The unique identifier of the album whose tracks are sampled, if applicable.</param>
/// <param name="ExcludedTrackIds">The tracks that must not be returned, if any.</param>
[DebuggerDisplay("LibraryId: {LibraryId} Count: {Count}")]
public record ShuffleTracksQuery(
string? LibraryId,
int Count,
Guid? ArtistId,
Guid? AlbumId,
IReadOnlyList<Guid>? ExcludedTrackIds
) : IQuery;
@@ -0,0 +1,85 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.ShuffleTracks;
/// <summary>
/// Handler for the query to draw a random selection of tracks from a media library, an artist or an album.
/// </summary>
public class ShuffleTracksQueryHandler : IQueryHandler<ShuffleTracksQuery, Result<IReadOnlyList<ShuffleTrackResponse>>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUserService _currentUserService;
private readonly IValidator<ShuffleTracksQuery> _validator;
/// <summary>
/// Initializes a new instance of the <see cref="ShuffleTracksQueryHandler"/> class.
/// </summary>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public ShuffleTracksQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<ShuffleTracksQuery> validator)
{
_unitOfWork = unitOfWork;
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_validator = validator;
}
/// <summary>
/// Handles the query to draw a random selection of tracks from a media library, an artist or an album.
/// </summary>
/// <param name="query">The query to be handled.</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="ShuffleTrackResponse"/>, or an error message.
/// </returns>
public async Task<Result<IReadOnlyList<ShuffleTrackResponse>>> HandleAsync(ShuffleTracksQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return validationResult;
// An authenticated request must always carry a user identity.
Guid? currentUserId = _currentUserService.UserId;
if (currentUserId is null)
return ApplicationErrors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
// The validator guarantees that the route identifier is a non-empty Guid before this point.
Guid libraryId = Guid.Parse(query.LibraryId!);
// Admins can shuffle all libraries; for everyone else, only the libraries they own.
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
IReadOnlyCollection<Guid> excludedTrackIds = query.ExcludedTrackIds is null
? []
: [.. query.ExcludedTrackIds.Where(trackId => trackId != Guid.Empty).Distinct()];
Result<IReadOnlyList<ShuffleTrackRowDto>> shuffleTracksResult = await _unitOfWork.TrackRepository.GetShuffleTracksLiteAsync(
libraryId, query.ArtistId, query.AlbumId, excludedTrackIds, query.Count, cancellationToken).ConfigureAwait(false);
return shuffleTracksResult.Match(value => Result.From(value.ToResponses()), errors => errors);
}
}
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Domain.Common.Errors;
using System;
#endregion
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.ShuffleTracks;
/// <summary>
/// Validates the needed validation rules for <see cref="ShuffleTracksQuery"/>.
/// </summary>
public class ShuffleTracksQueryValidator : AbstractValidator<ShuffleTracksQuery>
{
/// <summary>
/// Initializes a new instance of the <see cref="ShuffleTracksQueryValidator"/> class.
/// </summary>
public ShuffleTracksQueryValidator()
{
// Validates the identifier of the media library whose tracks are sampled, taken from the route.
RuleFor(query => query.LibraryId)
.Must(libraryId => !string.IsNullOrEmpty(libraryId))
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
RuleFor(query => query.LibraryId)
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
.When(query => !string.IsNullOrEmpty(query.LibraryId))
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
RuleFor(query => query.Count)
.Must(count => count > 0)
.WithError(Errors.Music.ShuffleTrackCountMustBeGreaterThanZero);
RuleFor(query => query.Count)
.Must(count => count <= 500)
.WithError(Errors.Music.ShuffleTrackCountMustBeAtMost500);
// The optional scoping identifiers must be real identifiers when they are present.
RuleFor(query => query.ArtistId)
.Must(artistId => !artistId.HasValue || artistId.Value != Guid.Empty)
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
RuleFor(query => query.AlbumId)
.Must(albumId => !albumId.HasValue || albumId.Value != Guid.Empty)
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
}
}