| | 1 | | using System; |
| | 2 | | using System.ComponentModel; |
| | 3 | | using System.ComponentModel.DataAnnotations; |
| | 4 | | using Jellyfin.Api.Constants; |
| | 5 | | using Jellyfin.Api.Extensions; |
| | 6 | | using Jellyfin.Api.Helpers; |
| | 7 | | using MediaBrowser.Common.Api; |
| | 8 | | using MediaBrowser.Controller.Entities; |
| | 9 | | using MediaBrowser.Controller.Library; |
| | 10 | | using MediaBrowser.Controller.Providers; |
| | 11 | | using MediaBrowser.Model.IO; |
| | 12 | | using Microsoft.AspNetCore.Authorization; |
| | 13 | | using Microsoft.AspNetCore.Http; |
| | 14 | | using Microsoft.AspNetCore.Mvc; |
| | 15 | |
|
| | 16 | | namespace Jellyfin.Api.Controllers; |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Item Refresh Controller. |
| | 20 | | /// </summary> |
| | 21 | | [Route("Items")] |
| | 22 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | 23 | | public class ItemRefreshController : BaseJellyfinApiController |
| | 24 | | { |
| | 25 | | private readonly ILibraryManager _libraryManager; |
| | 26 | | private readonly IProviderManager _providerManager; |
| | 27 | | private readonly IFileSystem _fileSystem; |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Initializes a new instance of the <see cref="ItemRefreshController"/> class. |
| | 31 | | /// </summary> |
| | 32 | | /// <param name="libraryManager">Instance of <see cref="ILibraryManager"/> interface.</param> |
| | 33 | | /// <param name="providerManager">Instance of <see cref="IProviderManager"/> interface.</param> |
| | 34 | | /// <param name="fileSystem">Instance of <see cref="IFileSystem"/> interface.</param> |
| 0 | 35 | | public ItemRefreshController( |
| 0 | 36 | | ILibraryManager libraryManager, |
| 0 | 37 | | IProviderManager providerManager, |
| 0 | 38 | | IFileSystem fileSystem) |
| | 39 | | { |
| 0 | 40 | | _libraryManager = libraryManager; |
| 0 | 41 | | _providerManager = providerManager; |
| 0 | 42 | | _fileSystem = fileSystem; |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Refreshes metadata for an item. |
| | 47 | | /// </summary> |
| | 48 | | /// <param name="itemId">Item id.</param> |
| | 49 | | /// <param name="metadataRefreshMode">(Optional) Specifies the metadata refresh mode.</param> |
| | 50 | | /// <param name="imageRefreshMode">(Optional) Specifies the image refresh mode.</param> |
| | 51 | | /// <param name="replaceAllMetadata">(Optional) Determines if metadata should be replaced. Only applicable if mode i |
| | 52 | | /// <param name="replaceAllImages">(Optional) Determines if images should be replaced. Only applicable if mode is Fu |
| | 53 | | /// <param name="regenerateTrickplay">(Optional) Determines if trickplay images should be replaced. Only applicable |
| | 54 | | /// <response code="204">Item metadata refresh queued.</response> |
| | 55 | | /// <response code="404">Item to refresh not found.</response> |
| | 56 | | /// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the item could not be |
| | 57 | | [HttpPost("{itemId}/Refresh")] |
| | 58 | | [Description("Refreshes metadata for an item.")] |
| | 59 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | 60 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 61 | | public ActionResult RefreshItem( |
| | 62 | | [FromRoute, Required] Guid itemId, |
| | 63 | | [FromQuery] MetadataRefreshMode metadataRefreshMode = MetadataRefreshMode.None, |
| | 64 | | [FromQuery] MetadataRefreshMode imageRefreshMode = MetadataRefreshMode.None, |
| | 65 | | [FromQuery] bool replaceAllMetadata = false, |
| | 66 | | [FromQuery] bool replaceAllImages = false, |
| | 67 | | [FromQuery] bool regenerateTrickplay = false) |
| | 68 | | { |
| 0 | 69 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, User.GetUserId()); |
| 0 | 70 | | if (item is null) |
| | 71 | | { |
| 0 | 72 | | return NotFound(); |
| | 73 | | } |
| | 74 | |
|
| 0 | 75 | | var refreshOptions = new MetadataRefreshOptions(new DirectoryService(_fileSystem)) |
| 0 | 76 | | { |
| 0 | 77 | | MetadataRefreshMode = metadataRefreshMode, |
| 0 | 78 | | ImageRefreshMode = imageRefreshMode, |
| 0 | 79 | | ReplaceAllImages = replaceAllImages, |
| 0 | 80 | | ReplaceAllMetadata = replaceAllMetadata, |
| 0 | 81 | | ForceSave = metadataRefreshMode == MetadataRefreshMode.FullRefresh |
| 0 | 82 | | || imageRefreshMode == MetadataRefreshMode.FullRefresh |
| 0 | 83 | | || replaceAllImages |
| 0 | 84 | | || replaceAllMetadata, |
| 0 | 85 | | IsAutomated = false, |
| 0 | 86 | | RemoveOldMetadata = replaceAllMetadata, |
| 0 | 87 | | RegenerateTrickplay = regenerateTrickplay |
| 0 | 88 | | }; |
| | 89 | |
|
| 0 | 90 | | _providerManager.QueueRefresh(item.Id, refreshOptions, RefreshPriority.High); |
| 0 | 91 | | return NoContent(); |
| | 92 | | } |
| | 93 | | } |