| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.ComponentModel.DataAnnotations; |
| | | 4 | | using System.Linq; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using Jellyfin.Api.Extensions; |
| | | 7 | | using Jellyfin.Database.Implementations.Enums; |
| | | 8 | | using MediaBrowser.Controller.Entities; |
| | | 9 | | using MediaBrowser.Controller.Library; |
| | | 10 | | using MediaBrowser.Controller.MediaSegments; |
| | | 11 | | using MediaBrowser.Model.MediaSegments; |
| | | 12 | | using MediaBrowser.Model.Querying; |
| | | 13 | | using Microsoft.AspNetCore.Authorization; |
| | | 14 | | using Microsoft.AspNetCore.Http; |
| | | 15 | | using Microsoft.AspNetCore.Mvc; |
| | | 16 | | |
| | | 17 | | namespace Jellyfin.Api.Controllers; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Media Segments api. |
| | | 21 | | /// </summary> |
| | | 22 | | [Authorize] |
| | | 23 | | public class MediaSegmentsController : BaseJellyfinApiController |
| | | 24 | | { |
| | | 25 | | private readonly IMediaSegmentManager _mediaSegmentManager; |
| | | 26 | | private readonly ILibraryManager _libraryManager; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Initializes a new instance of the <see cref="MediaSegmentsController"/> class. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="mediaSegmentManager">MediaSegments Manager.</param> |
| | | 32 | | /// <param name="libraryManager">The Library manager.</param> |
| | 0 | 33 | | public MediaSegmentsController(IMediaSegmentManager mediaSegmentManager, ILibraryManager libraryManager) |
| | | 34 | | { |
| | 0 | 35 | | _mediaSegmentManager = mediaSegmentManager; |
| | 0 | 36 | | _libraryManager = libraryManager; |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets all media segments based on an itemId. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <param name="itemId">The ItemId.</param> |
| | | 43 | | /// <param name="includeSegmentTypes">Optional filter of requested segment types.</param> |
| | | 44 | | /// <returns>A list of media segment objects related to the requested itemId.</returns> |
| | | 45 | | [HttpGet("{itemId}")] |
| | | 46 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 47 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 48 | | public async Task<ActionResult<QueryResult<MediaSegmentDto>>> GetItemSegments( |
| | | 49 | | [FromRoute, Required] Guid itemId, |
| | | 50 | | [FromQuery] IEnumerable<MediaSegmentType>? includeSegmentTypes = null) |
| | | 51 | | { |
| | | 52 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, User.GetUserId()); |
| | | 53 | | if (item is null) |
| | | 54 | | { |
| | | 55 | | return NotFound(); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | var libraryOptions = _libraryManager.GetLibraryOptions(item); |
| | | 59 | | var items = await _mediaSegmentManager.GetSegmentsAsync(item, includeSegmentTypes, libraryOptions).ConfigureAwai |
| | | 60 | | return Ok(new QueryResult<MediaSegmentDto>(items.ToArray())); |
| | | 61 | | } |
| | | 62 | | } |