2023-02-23 07:13:55 +00:00
|
|
|
using System;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Net.Mime;
|
|
|
|
using System.Text;
|
|
|
|
using Jellyfin.Api.Attributes;
|
|
|
|
using Jellyfin.Api.Extensions;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Trickplay;
|
|
|
|
using MediaBrowser.Model;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Trickplay controller.
|
|
|
|
/// </summary>
|
|
|
|
[Route("")]
|
|
|
|
[Authorize]
|
|
|
|
public class TrickplayController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
private readonly ITrickplayManager _trickplayManager;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="TrickplayController"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="libraryManager">Instance of <see cref="ILibraryManager"/>.</param>
|
|
|
|
/// <param name="trickplayManager">Instance of <see cref="ITrickplayManager"/>.</param>
|
|
|
|
public TrickplayController(
|
|
|
|
ILibraryManager libraryManager,
|
|
|
|
ITrickplayManager trickplayManager)
|
|
|
|
{
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
_trickplayManager = trickplayManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets an image tiles playlist for trickplay.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="itemId">The item id.</param>
|
|
|
|
/// <param name="width">The width of a single tile.</param>
|
|
|
|
/// <param name="mediaSourceId">The media version id, if using an alternate version.</param>
|
|
|
|
/// <response code="200">Tiles stream returned.</response>
|
|
|
|
/// <returns>A <see cref="FileResult"/> containing the trickplay tiles file.</returns>
|
|
|
|
[HttpGet("Videos/{itemId}/Trickplay/{width}/tiles.m3u8")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2023-05-24 21:41:38 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-02-23 07:13:55 +00:00
|
|
|
[ProducesPlaylistFile]
|
|
|
|
public ActionResult GetTrickplayHlsPlaylist(
|
|
|
|
[FromRoute, Required] Guid itemId,
|
|
|
|
[FromRoute, Required] int width,
|
2023-05-18 06:25:52 +00:00
|
|
|
[FromQuery] Guid? mediaSourceId)
|
2023-02-23 07:13:55 +00:00
|
|
|
{
|
2023-06-23 21:22:00 +00:00
|
|
|
string? playlist = _trickplayManager.GetHlsPlaylist(mediaSourceId ?? itemId, width, User.GetToken());
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(playlist))
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new FileContentResult(Encoding.UTF8.GetBytes(playlist), MimeTypes.GetMimeType("playlist.m3u8"));
|
2023-02-23 07:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a trickplay tile grid image.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="itemId">The item id.</param>
|
|
|
|
/// <param name="width">The width of a single tile.</param>
|
|
|
|
/// <param name="index">The index of the desired tile grid.</param>
|
|
|
|
/// <param name="mediaSourceId">The media version id, if using an alternate version.</param>
|
|
|
|
/// <response code="200">Tiles image returned.</response>
|
|
|
|
/// <response code="200">Tiles image not found at specified index.</response>
|
|
|
|
/// <returns>A <see cref="FileResult"/> containing the trickplay tiles image.</returns>
|
|
|
|
[HttpGet("Videos/{itemId}/Trickplay/{width}/{index}.jpg")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
[ProducesImageFile]
|
2023-06-23 21:22:00 +00:00
|
|
|
public ActionResult GetTrickplayGridImage(
|
2023-02-23 07:13:55 +00:00
|
|
|
[FromRoute, Required] Guid itemId,
|
|
|
|
[FromRoute, Required] int width,
|
|
|
|
[FromRoute, Required] int index,
|
2023-05-18 06:25:52 +00:00
|
|
|
[FromQuery] Guid? mediaSourceId)
|
2023-02-23 07:13:55 +00:00
|
|
|
{
|
2023-05-18 06:25:52 +00:00
|
|
|
var item = _libraryManager.GetItemById(mediaSourceId ?? itemId);
|
2023-02-23 07:13:55 +00:00
|
|
|
if (item is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
var path = _trickplayManager.GetTrickplayTilePath(item, width, index);
|
|
|
|
if (System.IO.File.Exists(path))
|
|
|
|
{
|
|
|
|
return PhysicalFile(path, MediaTypeNames.Image.Jpeg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
}
|