2019-11-17 22:05:39 +00:00
using MediaBrowser.Controller.Configuration ;
2019-01-13 20:01:16 +00:00
using MediaBrowser.Controller.Library ;
2014-07-02 18:34:08 +00:00
using MediaBrowser.Controller.Net ;
2014-01-28 18:37:01 +00:00
using MediaBrowser.Controller.Providers ;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Model.IO ;
using MediaBrowser.Model.Services ;
2019-01-13 19:24:58 +00:00
using Microsoft.Extensions.Logging ;
2013-06-27 19:29:58 +00:00
namespace MediaBrowser.Api
{
2014-02-04 20:19:29 +00:00
public class BaseRefreshRequest : IReturnVoid
2013-06-27 19:29:58 +00:00
{
2014-07-04 02:22:57 +00:00
[ApiMember(Name = "MetadataRefreshMode", Description = "Specifies the metadata refresh mode", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public MetadataRefreshMode MetadataRefreshMode { get ; set ; }
2014-06-15 02:24:04 +00:00
2014-07-04 02:22:57 +00:00
[ApiMember(Name = "ImageRefreshMode", Description = "Specifies the image refresh mode", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
2018-09-12 17:26:21 +00:00
public MetadataRefreshMode ImageRefreshMode { get ; set ; }
2014-07-04 02:22:57 +00:00
[ApiMember(Name = "ReplaceAllMetadata", Description = "Determines if metadata should be replaced. Only applicable if mode is FullRefresh", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public bool ReplaceAllMetadata { get ; set ; }
[ApiMember(Name = "ReplaceAllImages", Description = "Determines if images should be replaced. Only applicable if mode is FullRefresh", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
2014-06-15 02:24:04 +00:00
public bool ReplaceAllImages { get ; set ; }
2014-02-04 20:19:29 +00:00
}
2013-06-27 19:29:58 +00:00
2014-11-15 02:31:03 +00:00
[Route("/Items/{Id}/Refresh", "POST", Summary = "Refreshes metadata for an item")]
2014-02-04 20:19:29 +00:00
public class RefreshItem : BaseRefreshRequest
{
2013-06-27 19:29:58 +00:00
[ApiMember(Name = "Recursive", Description = "Indicates if the refresh should occur recursively.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool Recursive { get ; set ; }
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Id { get ; set ; }
}
2014-07-02 18:34:08 +00:00
[Authenticated]
2013-06-27 19:29:58 +00:00
public class ItemRefreshService : BaseApiService
{
private readonly ILibraryManager _libraryManager ;
2015-03-14 15:38:16 +00:00
private readonly IProviderManager _providerManager ;
2015-09-13 23:07:54 +00:00
private readonly IFileSystem _fileSystem ;
2013-06-27 19:29:58 +00:00
2019-11-17 22:05:39 +00:00
public ItemRefreshService (
ILogger < ItemRefreshService > logger ,
IServerConfigurationManager serverConfigurationManager ,
IHttpResultFactory httpResultFactory ,
ILibraryManager libraryManager ,
IProviderManager providerManager ,
IFileSystem fileSystem )
: base ( logger , serverConfigurationManager , httpResultFactory )
2013-06-27 19:29:58 +00:00
{
_libraryManager = libraryManager ;
2015-03-14 15:38:16 +00:00
_providerManager = providerManager ;
2015-09-13 23:07:54 +00:00
_fileSystem = fileSystem ;
2013-06-27 19:46:34 +00:00
}
2013-06-27 19:29:58 +00:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
public void Post ( RefreshItem request )
{
2014-04-27 03:42:05 +00:00
var item = _libraryManager . GetItemById ( request . Id ) ;
2014-02-09 07:27:44 +00:00
var options = GetRefreshOptions ( request ) ;
2014-07-04 02:22:57 +00:00
2017-04-30 02:37:51 +00:00
_providerManager . QueueRefresh ( item . Id , options , RefreshPriority . High ) ;
2013-06-29 00:49:44 +00:00
}
2014-02-04 20:19:29 +00:00
2017-06-23 16:04:45 +00:00
private MetadataRefreshOptions GetRefreshOptions ( RefreshItem request )
2014-02-04 20:19:29 +00:00
{
2019-09-10 20:37:53 +00:00
return new MetadataRefreshOptions ( new DirectoryService ( _fileSystem ) )
2014-02-04 20:19:29 +00:00
{
2014-07-04 02:22:57 +00:00
MetadataRefreshMode = request . MetadataRefreshMode ,
ImageRefreshMode = request . ImageRefreshMode ,
ReplaceAllImages = request . ReplaceAllImages ,
2014-07-20 04:46:29 +00:00
ReplaceAllMetadata = request . ReplaceAllMetadata ,
2018-09-12 17:26:21 +00:00
ForceSave = request . MetadataRefreshMode = = MetadataRefreshMode . FullRefresh | | request . ImageRefreshMode = = MetadataRefreshMode . FullRefresh | | request . ReplaceAllImages | | request . ReplaceAllMetadata ,
IsAutomated = false
2014-02-04 20:19:29 +00:00
} ;
}
2013-06-27 19:29:58 +00:00
}
}