using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using Jellyfin.Api.Extensions; using Jellyfin.Data.Enums; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Model.MediaSegments; using MediaBrowser.Model.Querying; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Jellyfin.Api.Controllers; /// /// Media Segments api. /// [Authorize] public class MediaSegmentsController : BaseJellyfinApiController { private readonly IMediaSegmentManager _mediaSegmentManager; private readonly ILibraryManager _libraryManager; /// /// Initializes a new instance of the class. /// /// MediaSegments Manager. /// The Library manager. public MediaSegmentsController(IMediaSegmentManager mediaSegmentManager, ILibraryManager libraryManager) { _mediaSegmentManager = mediaSegmentManager; _libraryManager = libraryManager; } /// /// Gets all media segments based on an itemId. /// /// The ItemId. /// Optional filter of requested segment types. /// A list of media segment objects related to the requested itemId. [HttpGet("{itemId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task>> GetItemSegments( [FromRoute, Required] Guid itemId, [FromQuery] IEnumerable? includeSegmentTypes = null) { var item = _libraryManager.GetItemById(itemId, User.GetUserId()); if (item is null) { return NotFound(); } var items = await _mediaSegmentManager.GetSegmentsAsync(item.Id, includeSegmentTypes).ConfigureAwait(false); return Ok(new QueryResult(items.ToArray())); } }