2015-04-24 23:30:44 -04:00
using MediaBrowser.Controller.Entities ;
using MediaBrowser.Controller.Library ;
2014-07-02 14:34:08 -04:00
using MediaBrowser.Controller.Net ;
2014-01-28 13:37:01 -05:00
using MediaBrowser.Controller.Providers ;
2015-04-24 23:30:44 -04:00
using System.Threading ;
2017-05-26 02:48:54 -04:00
2016-10-25 15:02:04 -04:00
using MediaBrowser.Controller.IO ;
using MediaBrowser.Model.IO ;
2016-08-06 00:48:00 -04:00
using MediaBrowser.Model.Logging ;
2016-10-25 15:02:04 -04:00
using MediaBrowser.Model.Services ;
2013-06-27 15:29:58 -04:00
namespace MediaBrowser.Api
{
2014-02-04 15:19:29 -05:00
public class BaseRefreshRequest : IReturnVoid
2013-06-27 15:29:58 -04:00
{
2014-07-03 22:22:57 -04: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-14 22:24:04 -04:00
2014-07-03 22:22:57 -04:00
[ApiMember(Name = "ImageRefreshMode", Description = "Specifies the image refresh mode", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
public ImageRefreshMode ImageRefreshMode { get ; set ; }
[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-14 22:24:04 -04:00
public bool ReplaceAllImages { get ; set ; }
2014-02-04 15:19:29 -05:00
}
2013-06-27 15:29:58 -04:00
2014-11-14 21:31:03 -05:00
[Route("/Items/{Id}/Refresh", "POST", Summary = "Refreshes metadata for an item")]
2014-02-04 15:19:29 -05:00
public class RefreshItem : BaseRefreshRequest
{
2013-06-27 15:29:58 -04: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 14:34:08 -04:00
[Authenticated]
2013-06-27 15:29:58 -04:00
public class ItemRefreshService : BaseApiService
{
private readonly ILibraryManager _libraryManager ;
2015-03-14 11:38:16 -04:00
private readonly IProviderManager _providerManager ;
2015-09-13 19:07:54 -04:00
private readonly IFileSystem _fileSystem ;
2016-08-06 00:48:00 -04:00
private readonly ILogger _logger ;
2013-06-27 15:29:58 -04:00
2016-08-06 00:48:00 -04:00
public ItemRefreshService ( ILibraryManager libraryManager , IProviderManager providerManager , IFileSystem fileSystem , ILogger logger )
2013-06-27 15:29:58 -04:00
{
_libraryManager = libraryManager ;
2015-03-14 11:38:16 -04:00
_providerManager = providerManager ;
2015-09-13 19:07:54 -04:00
_fileSystem = fileSystem ;
2016-08-06 00:48:00 -04:00
_logger = logger ;
2013-06-27 15:46:34 -04:00
}
2013-06-27 15:29:58 -04:00
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
public void Post ( RefreshItem request )
{
2014-04-26 23:42:05 -04:00
var item = _libraryManager . GetItemById ( request . Id ) ;
2014-02-09 02:27:44 -05:00
var options = GetRefreshOptions ( request ) ;
2014-07-03 22:22:57 -04:00
2017-04-29 22:37:51 -04:00
_providerManager . QueueRefresh ( item . Id , options , RefreshPriority . High ) ;
2013-06-28 20:49:44 -04:00
}
2014-02-04 15:19:29 -05:00
2017-06-23 12:04:45 -04:00
private MetadataRefreshOptions GetRefreshOptions ( RefreshItem request )
2014-02-04 15:19:29 -05:00
{
2016-08-06 00:48:00 -04:00
return new MetadataRefreshOptions ( new DirectoryService ( _logger , _fileSystem ) )
2014-02-04 15:19:29 -05:00
{
2014-07-03 22:22:57 -04:00
MetadataRefreshMode = request . MetadataRefreshMode ,
ImageRefreshMode = request . ImageRefreshMode ,
ReplaceAllImages = request . ReplaceAllImages ,
2014-07-20 00:46:29 -04:00
ReplaceAllMetadata = request . ReplaceAllMetadata ,
2017-06-23 12:04:45 -04:00
ForceSave = request . MetadataRefreshMode = = MetadataRefreshMode . FullRefresh | | request . ImageRefreshMode = = ImageRefreshMode . FullRefresh | | request . ReplaceAllImages | | request . ReplaceAllMetadata ,
IsAutomated = false ,
ValidateChildren = request . Recursive
2014-02-04 15:19:29 -05:00
} ;
}
2013-06-27 15:29:58 -04:00
}
}