From e5e39e8e56de7c4d6f0cadad579e9b20513f096d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 21 Dec 2014 00:57:06 -0500 Subject: [PATCH] add metadata editor info endpoint --- MediaBrowser.Api/ConfigurationService.cs | 2 +- MediaBrowser.Api/ItemUpdateService.cs | 30 ++++++++++++++- .../Configuration/ConfigurationHelper.cs | 15 -------- MediaBrowser.Common/Plugins/BasePlugin.cs | 38 ++++++++++++++----- MediaBrowser.LocalMetadata/BaseXmlProvider.cs | 2 +- .../MediaBrowser.Model.Portable.csproj | 3 ++ .../MediaBrowser.Model.net35.csproj | 3 ++ MediaBrowser.Model/Dto/DtoOptions.cs | 1 - MediaBrowser.Model/Dto/MetadataEditorInfo.cs | 23 +++++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + MediaBrowser.Model/Querying/ItemFields.cs | 5 +++ .../Dto/DtoService.cs | 7 ++-- .../Migrations/RenameXmlOptions.cs | 4 +- 13 files changed, 99 insertions(+), 35 deletions(-) create mode 100644 MediaBrowser.Model/Dto/MetadataEditorInfo.cs diff --git a/MediaBrowser.Api/ConfigurationService.cs b/MediaBrowser.Api/ConfigurationService.cs index 5fe606e16e..3eb0296fcb 100644 --- a/MediaBrowser.Api/ConfigurationService.cs +++ b/MediaBrowser.Api/ConfigurationService.cs @@ -123,7 +123,7 @@ namespace MediaBrowser.Api public void Post(AutoSetMetadataOptions request) { - _configurationManager.DisableMetadataService("Media Browser Legacy Xml"); + _configurationManager.DisableMetadataService("Media Browser Xml"); _configurationManager.SaveConfiguration(); } diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index 65c51befff..601feabd53 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -2,7 +2,9 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Net; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Dto; using ServiceStack; using System; @@ -20,14 +22,40 @@ namespace MediaBrowser.Api public string ItemId { get; set; } } + [Route("/Items/{ItemId}/MetadataEditor", "GET", Summary = "Gets metadata editor info for an item")] + public class GetMetadataEditorInfo : IReturn + { + [ApiMember(Name = "ItemId", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string ItemId { get; set; } + } + [Authenticated] public class ItemUpdateService : BaseApiService { private readonly ILibraryManager _libraryManager; + private readonly IProviderManager _providerManager; + private readonly ILocalizationManager _localizationManager; - public ItemUpdateService(ILibraryManager libraryManager) + public ItemUpdateService(ILibraryManager libraryManager, IProviderManager providerManager, ILocalizationManager localizationManager) { _libraryManager = libraryManager; + _providerManager = providerManager; + _localizationManager = localizationManager; + } + + public object Get(GetMetadataEditorInfo request) + { + var item = _libraryManager.GetItemById(request.ItemId); + + var info = new MetadataEditorInfo + { + ParentalRatingOptions = _localizationManager.GetParentalRatings().ToList(), + ExternalIdInfos = _providerManager.GetExternalIdInfos(item).ToList(), + Countries = _localizationManager.GetCountries().ToList(), + Cultures = _localizationManager.GetCultures().ToList() + }; + + return ToOptimizedResult(info); } public void Post(UpdateItem request) diff --git a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs index 8c904b0dbf..7212b70e1d 100644 --- a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs +++ b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs @@ -55,20 +55,5 @@ namespace MediaBrowser.Common.Configuration return configuration; } } - - /// - /// Reads an xml configuration file from the file system - /// It will immediately save the configuration after loading it, just - /// in case there are new serializable properties - /// - /// - /// The path. - /// The XML serializer. - /// ``0. - public static T GetXmlConfiguration(string path, IXmlSerializer xmlSerializer) - where T : class - { - return GetXmlConfiguration(typeof(T), path, xmlSerializer) as T; - } } } diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 6bbd69f04b..1a536b4ffb 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -164,11 +164,7 @@ namespace MediaBrowser.Common.Plugins /// /// The _configuration sync lock /// - private object _configurationSyncLock = new object(); - /// - /// The _configuration initialized - /// - private bool _configurationInitialized; + private readonly object _configurationSyncLock = new object(); /// /// The _configuration /// @@ -182,17 +178,39 @@ namespace MediaBrowser.Common.Plugins get { // Lazy load - LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => ConfigurationHelper.GetXmlConfiguration(ConfigurationType, ConfigurationFilePath, XmlSerializer) as TConfigurationType); + if (_configuration == null) + { + lock (_configurationSyncLock) + { + if (_configuration == null) + { + _configuration = LoadConfiguration(); + } + } + } return _configuration; } protected set { _configuration = value; + } + } - if (value == null) - { - _configurationInitialized = false; - } + private TConfigurationType LoadConfiguration() + { + var path = ConfigurationFilePath; + + try + { + return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path); + } + catch (FileNotFoundException) + { + return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); + } + catch (Exception ex) + { + return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); } } diff --git a/MediaBrowser.LocalMetadata/BaseXmlProvider.cs b/MediaBrowser.LocalMetadata/BaseXmlProvider.cs index 6f8047e4ce..82e7809e89 100644 --- a/MediaBrowser.LocalMetadata/BaseXmlProvider.cs +++ b/MediaBrowser.LocalMetadata/BaseXmlProvider.cs @@ -90,7 +90,7 @@ namespace MediaBrowser.LocalMetadata { get { - return "Media Browser Legacy Xml"; + return "Media Browser Xml"; } } diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 8994b16c37..ec41ffe0b5 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -461,6 +461,9 @@ Dto\MediaSourceType.cs + + Dto\MetadataEditorInfo.cs + Dto\RatingType.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index fbde4c92d6..01aaad2ac1 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -426,6 +426,9 @@ Dto\MediaSourceType.cs + + Dto\MetadataEditorInfo.cs + Dto\RatingType.cs diff --git a/MediaBrowser.Model/Dto/DtoOptions.cs b/MediaBrowser.Model/Dto/DtoOptions.cs index 6a61c7ef2b..069d71fceb 100644 --- a/MediaBrowser.Model/Dto/DtoOptions.cs +++ b/MediaBrowser.Model/Dto/DtoOptions.cs @@ -10,7 +10,6 @@ namespace MediaBrowser.Model.Dto public List ImageTypes { get; set; } public int ImageTypeLimit { get; set; } public bool EnableImages { get; set; } - public bool EnableSettings { get; set; } public DtoOptions() { diff --git a/MediaBrowser.Model/Dto/MetadataEditorInfo.cs b/MediaBrowser.Model/Dto/MetadataEditorInfo.cs new file mode 100644 index 0000000000..66bdb8ce3e --- /dev/null +++ b/MediaBrowser.Model/Dto/MetadataEditorInfo.cs @@ -0,0 +1,23 @@ +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Globalization; +using MediaBrowser.Model.Providers; +using System.Collections.Generic; + +namespace MediaBrowser.Model.Dto +{ + public class MetadataEditorInfo + { + public List ParentalRatingOptions { get; set; } + public List Countries { get; set; } + public List Cultures { get; set; } + public List ExternalIdInfos { get; set; } + + public MetadataEditorInfo() + { + ParentalRatingOptions = new List(); + Countries = new List(); + Cultures = new List(); + ExternalIdInfos = new List(); + } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 47bb62a321..0dd5442edf 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -128,6 +128,7 @@ + diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index 0bbb29742e..f288bfe48e 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -156,6 +156,11 @@ namespace MediaBrowser.Model.Querying /// SeasonName, + /// + /// The settings + /// + Settings, + /// /// The short overview /// diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index bbf1d8e3ad..a14a8ad08f 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -71,8 +71,7 @@ namespace MediaBrowser.Server.Implementations.Dto { var options = new DtoOptions { - Fields = fields, - EnableSettings = true + Fields = fields }; // Get everything @@ -677,7 +676,7 @@ namespace MediaBrowser.Server.Implementations.Dto dto.IsUnidentified = item.IsUnidentified; } - if (options.EnableSettings) + if (fields.Contains(ItemFields.Settings)) { dto.LockedFields = item.LockedFields; dto.LockData = item.IsLocked; @@ -1170,7 +1169,7 @@ namespace MediaBrowser.Server.Implementations.Dto dto.SeasonCount = series.SeasonCount; - if (options.EnableSettings) + if (fields.Contains(ItemFields.Settings)) { dto.DisplaySpecialsWithSeasons = series.DisplaySpecialsWithSeasons; } diff --git a/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs b/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs index a955b57eaf..be8ae2f814 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs @@ -42,9 +42,9 @@ namespace MediaBrowser.Server.Startup.Common.Migrations { for (var i = 0; i < options.Length; i++) { - if (string.Equals(options[i], "Media Browser Xml", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(options[i], "Media Browser Legacy Xml", StringComparison.OrdinalIgnoreCase)) { - options[i] = "Media Browser Legacy Xml"; + options[i] = "Media Browser Xml"; changed = true; } }