2014-02-02 13:36:31 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-02-09 23:08:01 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-02-02 13:36:31 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
using ServiceStack;
|
2014-06-29 17:35:05 +00:00
|
|
|
|
using ServiceStack.Text.Controller;
|
|
|
|
|
using ServiceStack.Web;
|
2014-02-09 23:08:01 +00:00
|
|
|
|
using System;
|
2014-02-02 13:36:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-06-29 17:35:05 +00:00
|
|
|
|
using System.IO;
|
2014-02-02 13:36:31 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-25 21:13:55 +00:00
|
|
|
|
[Route("/System/Configuration", "GET", Summary = "Gets application configuration")]
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public class GetConfiguration : IReturn<ServerConfiguration>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 17:35:05 +00:00
|
|
|
|
[Route("/System/Configuration/{Key}", "GET", Summary = "Gets a named configuration")]
|
|
|
|
|
public class GetNamedConfiguration
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Key", Description = "Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Key { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdateConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-25 21:13:55 +00:00
|
|
|
|
[Route("/System/Configuration", "POST", Summary = "Updates application configuration")]
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public class UpdateConfiguration : ServerConfiguration, IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 17:35:05 +00:00
|
|
|
|
[Route("/System/Configuration/{Key}", "POST", Summary = "Updates named configuration")]
|
|
|
|
|
public class UpdateNamedConfiguration : IReturnVoid, IRequiresRequestStream
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Key", Description = "Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Key { get; set; }
|
|
|
|
|
|
|
|
|
|
public Stream RequestStream { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 21:13:55 +00:00
|
|
|
|
[Route("/System/Configuration/MetadataOptions/Default", "GET", Summary = "Gets a default MetadataOptions object")]
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public class GetDefaultMetadataOptions : IReturn<MetadataOptions>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 21:13:55 +00:00
|
|
|
|
[Route("/System/Configuration/MetadataPlugins", "GET", Summary = "Gets all available metadata plugins")]
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public class GetMetadataPlugins : IReturn<List<MetadataPluginSummary>>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 21:13:55 +00:00
|
|
|
|
[Route("/System/Configuration/VideoImageExtraction", "POST", Summary = "Updates image extraction for all types")]
|
2014-02-19 18:50:37 +00:00
|
|
|
|
public class UpdateVideoImageExtraction : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
public bool Enabled { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public class ConfigurationService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _json serializer
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _configuration manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
|
|
|
|
|
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
private readonly IProviderManager _providerManager;
|
|
|
|
|
|
|
|
|
|
public ConfigurationService(IJsonSerializer jsonSerializer, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IProviderManager providerManager)
|
|
|
|
|
{
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
_configurationManager = configurationManager;
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
_providerManager = providerManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
var configPath = _configurationManager.ApplicationPaths.SystemConfigurationFilePath;
|
|
|
|
|
|
|
|
|
|
var dateModified = _fileSystem.GetLastWriteTimeUtc(configPath);
|
|
|
|
|
|
|
|
|
|
var cacheKey = (configPath + dateModified.Ticks).GetMD5();
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResultUsingCache(cacheKey, dateModified, null, () => _configurationManager.Configuration);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 17:35:05 +00:00
|
|
|
|
public object Get(GetNamedConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
var result = _configurationManager.GetConfiguration(request.Key);
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified configuraiton.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(UpdateConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
// Silly, but we need to serialize and deserialize or the XmlSerializer will write the xml with an element name of UpdateConfiguration
|
|
|
|
|
var json = _jsonSerializer.SerializeToString(request);
|
|
|
|
|
|
|
|
|
|
var config = _jsonSerializer.DeserializeFromString<ServerConfiguration>(json);
|
|
|
|
|
|
|
|
|
|
_configurationManager.ReplaceConfiguration(config);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 17:35:05 +00:00
|
|
|
|
public void Post(UpdateNamedConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
var pathInfo = PathInfo.Parse(Request.PathInfo);
|
|
|
|
|
var key = pathInfo.GetArgumentValue<string>(2);
|
|
|
|
|
|
|
|
|
|
var configurationType = _configurationManager.GetConfigurationType(key);
|
|
|
|
|
var configuration = _jsonSerializer.DeserializeFromStream(request.RequestStream, configurationType);
|
|
|
|
|
|
|
|
|
|
_configurationManager.SaveConfiguration(key, configuration);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public object Get(GetDefaultMetadataOptions request)
|
|
|
|
|
{
|
2014-02-04 04:04:19 +00:00
|
|
|
|
return ToOptimizedSerializedResultUsingCache(new MetadataOptions());
|
2014-02-02 13:36:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Get(GetMetadataPlugins request)
|
|
|
|
|
{
|
2014-02-04 04:04:19 +00:00
|
|
|
|
return ToOptimizedSerializedResultUsingCache(_providerManager.GetAllMetadataPlugins().ToList());
|
2014-02-02 13:36:31 +00:00
|
|
|
|
}
|
2014-02-09 23:08:01 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is a temporary method used until image settings get broken out.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
2014-02-19 18:50:37 +00:00
|
|
|
|
public void Post(UpdateVideoImageExtraction request)
|
|
|
|
|
{
|
|
|
|
|
var config = _configurationManager.Configuration;
|
|
|
|
|
|
|
|
|
|
EnableImageExtractionForType(typeof(Movie), config, request.Enabled);
|
|
|
|
|
EnableImageExtractionForType(typeof(Episode), config, request.Enabled);
|
|
|
|
|
EnableImageExtractionForType(typeof(AdultVideo), config, request.Enabled);
|
|
|
|
|
EnableImageExtractionForType(typeof(MusicVideo), config, request.Enabled);
|
|
|
|
|
EnableImageExtractionForType(typeof(Video), config, request.Enabled);
|
|
|
|
|
EnableImageExtractionForType(typeof(Trailer), config, request.Enabled);
|
|
|
|
|
|
|
|
|
|
_configurationManager.SaveConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnableImageExtractionForType(Type type, ServerConfiguration config, bool enabled)
|
|
|
|
|
{
|
|
|
|
|
var options = GetMetadataOptions(type, config);
|
|
|
|
|
|
|
|
|
|
const string imageProviderName = "Screen Grabber";
|
|
|
|
|
|
|
|
|
|
var contains = options.DisabledImageFetchers.Contains(imageProviderName, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (!enabled && !contains)
|
|
|
|
|
{
|
|
|
|
|
var list = options.DisabledImageFetchers.ToList();
|
|
|
|
|
|
|
|
|
|
list.Add(imageProviderName);
|
|
|
|
|
|
|
|
|
|
options.DisabledImageFetchers = list.ToArray();
|
|
|
|
|
}
|
|
|
|
|
else if (enabled && contains)
|
|
|
|
|
{
|
|
|
|
|
var list = options.DisabledImageFetchers.ToList();
|
|
|
|
|
|
|
|
|
|
list.Remove(imageProviderName);
|
|
|
|
|
|
|
|
|
|
options.DisabledImageFetchers = list.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-09 23:08:01 +00:00
|
|
|
|
private MetadataOptions GetMetadataOptions(Type type, ServerConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
var options = config.MetadataOptions
|
|
|
|
|
.FirstOrDefault(i => string.Equals(i.ItemType, type.Name, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (options == null)
|
|
|
|
|
{
|
|
|
|
|
var list = config.MetadataOptions.ToList();
|
|
|
|
|
|
|
|
|
|
options = new MetadataOptions
|
|
|
|
|
{
|
|
|
|
|
ItemType = type.Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
list.Add(options);
|
|
|
|
|
|
|
|
|
|
config.MetadataOptions = list.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
2014-02-02 13:36:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|