mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 08:11:10 +00:00
Adds seekable normalized audio track delivery
This commit is contained in:
1 parent
4e13b23f16
commit
45f9aa3bd5
57 files changed
+3452
-344
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -29,6 +30,20 @@ public static class MusicMimeTypes
|
||||
{ AudioFileFormat.MATROSKA, "audio/x-matroska" }
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
// Container names are mapped to the file format enumeration instead of to their own media type strings, so the media type table above stays the
|
||||
// single source of truth and a new format only needs one entry.
|
||||
private static readonly FrozenDictionary<string, AudioFileFormat> s_containerToAudioFileFormat = new Dictionary<string, AudioFileFormat>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "MP3", AudioFileFormat.MP3 },
|
||||
{ "FLAC", AudioFileFormat.FLAC },
|
||||
{ "MP4", AudioFileFormat.M4A },
|
||||
{ "M4A", AudioFileFormat.M4A },
|
||||
{ "AAC", AudioFileFormat.AAC },
|
||||
{ "OGG", AudioFileFormat.OGG },
|
||||
{ "OPUS", AudioFileFormat.OPUS },
|
||||
{ "WAV", AudioFileFormat.WAV }
|
||||
}.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the MIME content type of <paramref name="format"/>.
|
||||
/// </summary>
|
||||
@@ -38,4 +53,16 @@ public static class MusicMimeTypes
|
||||
{
|
||||
return s_audioFileFormatToMimeType.TryGetValue(format, out string? mimeType) ? mimeType : "application/octet-stream";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the MIME content type of an audio container, as named by the delivery decision of a playback manifest.
|
||||
/// </summary>
|
||||
/// <param name="container">The canonical container of the delivered audio, for example MP4, AAC, OGG, MP3, FLAC or WAV.</param>
|
||||
/// <returns>The MIME content type of <paramref name="container"/>, or <c>application/octet-stream</c> when the container is unknown.</returns>
|
||||
public static string GetContainerMimeType(string? container)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(container) && s_containerToAudioFileFormat.TryGetValue(container.Trim(), out AudioFileFormat format)
|
||||
? GetMimeType(format)
|
||||
: "application/octet-stream";
|
||||
}
|
||||
}
|
||||
+1
@@ -15,6 +15,7 @@ public static partial class ApiRoutes
|
||||
public const string UPDATE_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string DELETE_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string STREAM_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream";
|
||||
public const string STREAM_TRACK_SEGMENT = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream/deliveries/{deliveryId}/segments/{segmentIndex}";
|
||||
public const string GET_PLAYBACK_MANIFEST = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/playback-manifest";
|
||||
}
|
||||
}
|
||||
@@ -45,16 +45,20 @@ public abstract class BaseEndpoint<TRequest, TResponse> : Endpoint<TRequest, TRe
|
||||
protected IResult Problem(Error error)
|
||||
{
|
||||
Dictionary<string, object?> extensionsDictionary = [];
|
||||
int statusCode = error.Type switch
|
||||
{
|
||||
ErrorType.Validation => StatusCodes.Status400BadRequest,
|
||||
ErrorType.Unauthorized => StatusCodes.Status403Forbidden, // DO NOT return Status401Unauthorized, that actually means lack of valid authentication credentials (not logged in)
|
||||
ErrorType.Failure => StatusCodes.Status403Forbidden,
|
||||
ErrorType.Forbidden => StatusCodes.Status403Forbidden,
|
||||
ErrorType.NotFound => StatusCodes.Status404NotFound,
|
||||
ErrorType.Conflict => StatusCodes.Status409Conflict,
|
||||
_ => StatusCodes.Status500InternalServerError,
|
||||
};
|
||||
// A resource that is temporarily unavailable is a transient condition of the server, not an unexpected failure, so it is reported as
|
||||
// unavailable rather than as an internal error. A client can retry it, and the playback player does.
|
||||
int statusCode = error is ResourceUnavailableError
|
||||
? StatusCodes.Status503ServiceUnavailable
|
||||
: error.Type switch
|
||||
{
|
||||
ErrorType.Validation => StatusCodes.Status400BadRequest,
|
||||
ErrorType.Unauthorized => StatusCodes.Status403Forbidden, // DO NOT return Status401Unauthorized, that actually means lack of valid authentication credentials (not logged in)
|
||||
ErrorType.Failure => StatusCodes.Status403Forbidden,
|
||||
ErrorType.Forbidden => StatusCodes.Status403Forbidden,
|
||||
ErrorType.NotFound => StatusCodes.Status404NotFound,
|
||||
ErrorType.Conflict => StatusCodes.Status409Conflict,
|
||||
_ => StatusCodes.Status500InternalServerError,
|
||||
};
|
||||
|
||||
extensionsDictionary["traceId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
|
||||
@@ -79,15 +83,11 @@ public abstract class BaseEndpoint<TRequest, TResponse> : Endpoint<TRequest, TRe
|
||||
|
||||
// populate the errors dictionary with error codes and their descriptions
|
||||
foreach (Error error in errors)
|
||||
{
|
||||
if (!errorsDictionary.TryGetValue(error.Code, out string[]? value))
|
||||
errorsDictionary.Add(error.Code, [error.Description]);
|
||||
else
|
||||
{
|
||||
if (!errorsDictionary[error.Code].Contains(error.Description))
|
||||
errorsDictionary[error.Code] = [.. value, error.Description];
|
||||
}
|
||||
}
|
||||
|
||||
// add trace identifier to the extensions dictionary for tracing purposes
|
||||
extensionsDictionary["traceId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
|
||||
/// <summary>
|
||||
/// A response result that writes an owned stream to the response without buffering it and releases the stream once the response is complete.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The result owns the stream, so a lease protected resource that is served through it is always released, including when the client disconnects
|
||||
/// before the whole content was written. Unlike a result built from bytes, it never materializes the content in memory.
|
||||
/// </remarks>
|
||||
public sealed class DisposingStreamResult : IResult
|
||||
{
|
||||
private readonly Stream _content;
|
||||
private readonly string _contentType;
|
||||
private readonly long? _contentLength;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DisposingStreamResult"/> class.
|
||||
/// </summary>
|
||||
/// <param name="content">The stream to write, which this result owns and releases after the response is complete.</param>
|
||||
/// <param name="contentType">The media type of the content.</param>
|
||||
/// <param name="contentLength">The length of the content, in bytes, or <see langword="null"/> when it is not known in advance.</param>
|
||||
public DisposingStreamResult(Stream content, string contentType, long? contentLength)
|
||||
{
|
||||
_content = content;
|
||||
_contentType = contentType;
|
||||
_contentLength = contentLength;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the content stream to the response.
|
||||
/// </summary>
|
||||
/// <param name="httpContext">The HTTP context of the request being answered.</param>
|
||||
public async Task ExecuteAsync(HttpContext httpContext)
|
||||
{
|
||||
if (_contentLength.HasValue)
|
||||
httpContext.Response.ContentLength = _contentLength.Value;
|
||||
httpContext.Response.ContentType = _contentType;
|
||||
await using (_content)
|
||||
await _content.CopyToAsync(httpContext.Response.Body, httpContext.RequestAborted).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
+17
-2
@@ -62,8 +62,23 @@ public class GetPlaybackManifestEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
.Replace("{artistId}", artistId, StringComparison.Ordinal)
|
||||
.Replace("{albumId}", albumId, StringComparison.Ordinal)
|
||||
.Replace("{trackId}", trackId, StringComparison.Ordinal);
|
||||
GetPlaybackManifestQuery query = new(libraryId, artistId, albumId, trackId, capabilities, streamPath);
|
||||
// The segment route is filled in from the same route values, and its delivery handle and segment index placeholders are kept for the player
|
||||
// to expand, so the manifest and the segment route can never disagree on the shape of the path either. The delivery handle is what binds
|
||||
// the segments to the delivery this manifest declared; the capabilities are not repeated in the path.
|
||||
string segmentStreamPathTemplate = ApiRoutes.Tracks.STREAM_TRACK_SEGMENT
|
||||
.Replace("{libraryId}", libraryId, StringComparison.Ordinal)
|
||||
.Replace("{artistId}", artistId, StringComparison.Ordinal)
|
||||
.Replace("{albumId}", albumId, StringComparison.Ordinal)
|
||||
.Replace("{trackId}", trackId, StringComparison.Ordinal);
|
||||
GetPlaybackManifestQuery query = new(libraryId, artistId, albumId, trackId, capabilities, streamPath, segmentStreamPathTemplate);
|
||||
Result<PlaybackManifestResponse> result = await _getPlaybackManifestQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
return result.Match(success =>
|
||||
{
|
||||
// The manifest carries delivery metadata specific to the authenticated user, so no intermediary may store it and every response varies by
|
||||
// the bearer token that authorized it.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Authorization";
|
||||
return TypedResults.Ok(success);
|
||||
}, Problem);
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -34,13 +34,15 @@ public class GetPlaybackManifestEndpointSummary : Summary<GetPlaybackManifestEnd
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.ReplayGainTrackPeak, "The ReplayGain track peak of the track, if applicable.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.ReplayGainAlbumGain, "The ReplayGain album gain of the track, in decibels, if applicable.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.ReplayGainAlbumPeak, "The ReplayGain album peak of the track, if applicable.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.DirectPlay, "Whether the player can play the stored audio as it is, without the server changing its container or its codec.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.IsDirectPlay, "Whether the player can play the stored audio as it is, without the server changing its container or its codec.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.DeliveryContainer, "The container of the audio the server delivers, when the delivery is not a direct play.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.DeliveryCodec, "The codec of the audio the server delivers, when the delivery is not a direct play.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.DeliveryShape, "The shape the delivered audio is addressed and seeked by, when the delivery is not a direct play.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.SegmentDurationSeconds, "The duration of each segment of the delivered audio, in seconds, when the delivery is addressed as time addressed segments.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.Seekable, "Whether the delivered audio can be seeked by the player.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.IsSeekable, "Whether the delivered audio can be seeked by the player.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.StreamPath, "The path of the track stream, relative to the API, without a host or a scheme.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.DeliveryId, "The opaque handle of the normalized delivery, which the segment route accepts. Null for a direct play.");
|
||||
ResponseParam<PlaybackManifestResponse>(r => r.SegmentStreamPathTemplate, "The path template of the segment route of the normalized delivery, relative to the API, with {deliveryId} and {segmentIndex} placeholders. Null for a direct play.");
|
||||
|
||||
Response(200, "The playback manifest of the track is returned.",
|
||||
example: new PlaybackManifestResponse(
|
||||
@@ -55,13 +57,15 @@ public class GetPlaybackManifestEndpointSummary : Summary<GetPlaybackManifestEnd
|
||||
ReplayGainTrackPeak: 0.9877m,
|
||||
ReplayGainAlbumGain: -6.8m,
|
||||
ReplayGainAlbumPeak: 0.9999m,
|
||||
DirectPlay: false,
|
||||
IsDirectPlay: false,
|
||||
DeliveryContainer: "MP3",
|
||||
DeliveryCodec: "MP3",
|
||||
DeliveryShape: PlaybackDeliveryShape.TimeAddressedSegments,
|
||||
SegmentDurationSeconds: 6,
|
||||
Seekable: true,
|
||||
StreamPath: "/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/stream"
|
||||
IsSeekable: true,
|
||||
StreamPath: "/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/stream",
|
||||
DeliveryId: "8f14e45fceea167a5a36dedd4bea2543",
|
||||
SegmentStreamPathTemplate: "/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/stream/deliveries/{deliveryId}/segments/{segmentIndex}"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetTrackSegment;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.DependencyInjection;
|
||||
using Lumina.Presentation.Api.Common.Http;
|
||||
using Lumina.Presentation.Api.Common.MimeTypes;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetTrackSegment;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream/deliveries/{deliveryId}/segments/{segmentIndex}</c> route.
|
||||
/// </summary>
|
||||
public class GetTrackSegmentEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
// The name is repeated in the web client application, which is a separate project that keeps its own contracts, so both sides must change together.
|
||||
private const string SEGMENT_COUNT_HEADER_NAME = "X-Lumina-Segment-Count";
|
||||
private const string SEGMENT_START_SECONDS_HEADER_NAME = "X-Segment-Start-Seconds";
|
||||
private const string TRACK_DURATION_SECONDS_HEADER_NAME = "X-Lumina-Track-Duration-Seconds";
|
||||
|
||||
private readonly IQueryHandler<GetTrackSegmentQuery, Result<NormalizedTrackSegmentDataDto>> _getTrackSegmentQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTrackSegmentEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getTrackSegmentQueryHandler">Injected service for handling get track segment queries.</param>
|
||||
public GetTrackSegmentEndpoint(IQueryHandler<GetTrackSegmentQuery, Result<NormalizedTrackSegmentDataDto>> getTrackSegmentQueryHandler)
|
||||
{
|
||||
_getTrackSegmentQueryHandler = getTrackSegmentQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Tracks.STREAM_TRACK_SEGMENT);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
// The segment stream is limited per user with the same concurrency limiter as the track stream, and it is excluded from the eventual
|
||||
// consistency pipeline, because a long lived response would otherwise hold the request's database transaction open for its whole duration.
|
||||
Options(builder => builder
|
||||
.RequireRateLimiting(PresentationApiLayerServices.TRACK_STREAM_RATE_LIMIT_POLICY)
|
||||
.WithMetadata(new SkipEventualConsistencyMetadata()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Streams one segment of the normalized audio of the track identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take unique identifiers and the segment index from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
|
||||
string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString();
|
||||
string? trackId = HttpContext.Request.RouteValues["trackId"]?.ToString();
|
||||
string? deliveryId = HttpContext.Request.RouteValues["deliveryId"]?.ToString();
|
||||
string? segmentIndex = HttpContext.Request.RouteValues["segmentIndex"]?.ToString();
|
||||
GetTrackSegmentQuery query = new(libraryId, artistId, albumId, trackId, deliveryId, segmentIndex);
|
||||
Result<NormalizedTrackSegmentDataDto> result = await _getTrackSegmentQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
|
||||
if (result.IsFailure)
|
||||
return Problem(result.Errors);
|
||||
|
||||
// The produced segment is private to the authenticated user and is served from a temporary cache, so it must never be stored by an
|
||||
// intermediary, and content sniffing stays disabled, so a segment can never be interpreted as active content.
|
||||
HttpContext.Response.Headers["X-Content-Type-Options"] = "nosniff";
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Authorization";
|
||||
// The count lets the player stop at the end of the production instead of probing for it with a request that cannot be told apart
|
||||
// from a track that was deleted or moved. It is sent on every segment, because any segment can be the first one a player fetches.
|
||||
HttpContext.Response.Headers[SEGMENT_COUNT_HEADER_NAME] = result.Value.SegmentCount.ToString();
|
||||
// The real start of the segment, because ffmpeg cuts at the first packet at or after a segment boundary and a container can number its
|
||||
// frames from the start of the track. The player offsets the packets by this value instead of assuming an exact multiple of the duration.
|
||||
HttpContext.Response.Headers[SEGMENT_START_SECONDS_HEADER_NAME] = result.Value.StartSeconds.ToString(CultureInfo.InvariantCulture);
|
||||
// The produced duration can differ from the probed duration, so the player uses this value for its timeline and progress bar.
|
||||
HttpContext.Response.Headers[TRACK_DURATION_SECONDS_HEADER_NAME] = result.Value.DurationInSeconds.ToString(CultureInfo.InvariantCulture);
|
||||
// The length comes from the index of the production, so the response is length delimited without reading the segment into memory first.
|
||||
return new DisposingStreamResult(result.Value.Content, MusicMimeTypes.GetContainerMimeType(result.Value.Container), result.Value.Length);
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetTrackSegment;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetTrackSegmentEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTrackSegmentEndpointSummary : Summary<GetTrackSegmentEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTrackSegmentEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetTrackSegmentEndpointSummary()
|
||||
{
|
||||
Summary = "Streams one segment of the normalized audio of a track.";
|
||||
Description = "Streams a single fixed duration segment of the normalized audio of the track identified by the route. A track that is not a direct play is delivered as fixed duration, time addressed segments, so a player seeks by segment index and never maps a byte range to a time. The delivery handle is the opaque value the playback manifest reports in its deliveryId, and the segment index is zero based; together they name a segment of exactly the delivery the manifest declared, including its quality cap and the source file version it was declared for. Library ownership is re-evaluated on every request, while track membership and content locations are those captured at manifest time, so a deleted track row whose file remains can stay streamable until the handle expires. The first request for a track may wait for the whole normalized audio to be produced and cached. The segment is streamed to an Admin, who can stream the tracks of all libraries, or to the owner of the library of the track.";
|
||||
|
||||
Response(200, "The requested segment is streamed, with the media type of the delivered container, or application/octet-stream when the container is not an audio type, with the length of the segment as its content length, and with the segment count and its exact start time on the track timeline as the X-Lumina-Segment-Count and X-Segment-Start-Seconds headers.", "*/*");
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/0"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/0",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the delivery handle is unknown, expired, or was issued to another user or track, the track or its media library does not exist, the track does not belong to the library, album and artist named by the route, the audio file of the track is outside the content locations of its library, missing, or unreadable, or the requested segment does not exist. Only the NormalizedTrackSegmentNotFound detail means the end of the normalized audio; every other not found detail is a playback failure.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "TrackNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/0",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaybackDeliveryNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/0",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "NormalizedTrackSegmentNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/999",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "NormalizedTrackCacheEntryNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/999",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The delivery handle does not describe time addressed segments, or the source file changed since the manifest declared the delivery. The player must request the playback manifest again.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "PlaybackDeliveryChanged",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/0",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/not-a-handle/segments/-1",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty",
|
||||
"AlbumIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty",
|
||||
"DeliveryIdCannotBeEmpty",
|
||||
"DeliveryIdIsInvalid",
|
||||
"SegmentIndexMustBeValid"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(503, "Every normalization job slot, globally or for this user, is in use. The condition is transient and the request can be retried.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.6.4",
|
||||
title = "General.ResourceUnavailable",
|
||||
status = 503,
|
||||
detail = "NormalizationUnavailable",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/stream/deliveries/8f14e45fceea167a5a36dedd4bea2543/segments/0",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user