瀏覽代碼

add metadata editor info endpoint

Luke Pulverenti 10 年之前
父節點
當前提交
e5e39e8e56

+ 1 - 1
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();
         }
 

+ 29 - 1
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<MetadataEditorInfo>
+    {
+        [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)

+ 0 - 15
MediaBrowser.Common/Configuration/ConfigurationHelper.cs

@@ -55,20 +55,5 @@ namespace MediaBrowser.Common.Configuration
                 return configuration;
             }
         }
-
-        /// <summary>
-        /// 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
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="path">The path.</param>
-        /// <param name="xmlSerializer">The XML serializer.</param>
-        /// <returns>``0.</returns>
-        public static T GetXmlConfiguration<T>(string path, IXmlSerializer xmlSerializer)
-            where T : class
-        {
-            return GetXmlConfiguration(typeof(T), path, xmlSerializer) as T;
-        }
     }
 }

+ 28 - 10
MediaBrowser.Common/Plugins/BasePlugin.cs

@@ -164,11 +164,7 @@ namespace MediaBrowser.Common.Plugins
         /// <summary>
         /// The _configuration sync lock
         /// </summary>
-        private object _configurationSyncLock = new object();
-        /// <summary>
-        /// The _configuration initialized
-        /// </summary>
-        private bool _configurationInitialized;
+        private readonly object _configurationSyncLock = new object();
         /// <summary>
         /// The _configuration
         /// </summary>
@@ -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));
             }
         }
 

+ 1 - 1
MediaBrowser.LocalMetadata/BaseXmlProvider.cs

@@ -90,7 +90,7 @@ namespace MediaBrowser.LocalMetadata
         {
             get
             {
-                return "Media Browser Legacy Xml";
+                return "Media Browser Xml";
             }
         }
         

+ 3 - 0
MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj

@@ -461,6 +461,9 @@
     <Compile Include="..\MediaBrowser.Model\Dto\MediaSourceType.cs">
       <Link>Dto\MediaSourceType.cs</Link>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\Dto\MetadataEditorInfo.cs">
+      <Link>Dto\MetadataEditorInfo.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Dto\RatingType.cs">
       <Link>Dto\RatingType.cs</Link>
     </Compile>

+ 3 - 0
MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj

@@ -426,6 +426,9 @@
     <Compile Include="..\MediaBrowser.Model\Dto\MediaSourceType.cs">
       <Link>Dto\MediaSourceType.cs</Link>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\Dto\MetadataEditorInfo.cs">
+      <Link>Dto\MetadataEditorInfo.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Dto\RatingType.cs">
       <Link>Dto\RatingType.cs</Link>
     </Compile>

+ 0 - 1
MediaBrowser.Model/Dto/DtoOptions.cs

@@ -10,7 +10,6 @@ namespace MediaBrowser.Model.Dto
         public List<ImageType> ImageTypes { get; set; }
         public int ImageTypeLimit { get; set; }
         public bool EnableImages { get; set; }
-        public bool EnableSettings { get; set; }
 
         public DtoOptions()
         {

+ 23 - 0
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<ParentalRating> ParentalRatingOptions { get; set; }
+        public List<CountryInfo> Countries { get; set; }
+        public List<CultureDto> Cultures { get; set; }
+        public List<ExternalIdInfo> ExternalIdInfos { get; set; }
+
+        public MetadataEditorInfo()
+        {
+            ParentalRatingOptions = new List<ParentalRating>();
+            Countries = new List<CountryInfo>();
+            Cultures = new List<CultureDto>();
+            ExternalIdInfos = new List<ExternalIdInfo>();
+        }
+    }
+}

+ 1 - 0
MediaBrowser.Model/MediaBrowser.Model.csproj

@@ -128,6 +128,7 @@
     <Compile Include="Drawing\ImageOrientation.cs" />
     <Compile Include="Dto\DtoOptions.cs" />
     <Compile Include="Dto\IHasServerId.cs" />
+    <Compile Include="Dto\MetadataEditorInfo.cs" />
     <Compile Include="MediaInfo\LiveMediaInfoResult.cs" />
     <Compile Include="Dto\MediaSourceType.cs" />
     <Compile Include="Dto\StreamOptions.cs" />

+ 5 - 0
MediaBrowser.Model/Querying/ItemFields.cs

@@ -156,6 +156,11 @@ namespace MediaBrowser.Model.Querying
         /// </summary>
         SeasonName,
 
+        /// <summary>
+        /// The settings
+        /// </summary>
+        Settings,
+
         /// <summary>
         /// The short overview
         /// </summary>

+ 3 - 4
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;
                 }

+ 2 - 2
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;
                     }
                 }