Bladeren bron

start on content type setting

Luke Pulverenti 10 jaren geleden
bovenliggende
commit
74520804f8

+ 104 - 0
MediaBrowser.Api/ItemUpdateService.cs

@@ -6,6 +6,7 @@ using MediaBrowser.Controller.Localization;
 using MediaBrowser.Controller.Net;
 using MediaBrowser.Controller.Net;
 using MediaBrowser.Controller.Providers;
 using MediaBrowser.Controller.Providers;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Dto;
+using MediaBrowser.Model.Entities;
 using ServiceStack;
 using ServiceStack;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
@@ -28,6 +29,16 @@ namespace MediaBrowser.Api
         [ApiMember(Name = "ItemId", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
         [ApiMember(Name = "ItemId", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
         public string ItemId { get; set; }
         public string ItemId { get; set; }
     }
     }
+
+    [Route("/Items/{ItemId}/ContentType", "POST", Summary = "Updates an item's content type")]
+    public class UpdateItemContentType : IReturnVoid
+    {
+        [ApiMember(Name = "ItemId", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+        public string ItemId { get; set; }
+
+        [ApiMember(Name = "ContentType", Description = "The content type of the item", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
+        public string ContentType { get; set; }
+    }
     
     
     [Authenticated]
     [Authenticated]
     public class ItemUpdateService : BaseApiService
     public class ItemUpdateService : BaseApiService
@@ -55,9 +66,102 @@ namespace MediaBrowser.Api
                 Cultures = _localizationManager.GetCultures().ToList()
                 Cultures = _localizationManager.GetCultures().ToList()
             };
             };
 
 
+            var locationType = item.LocationType;
+            if (locationType == LocationType.FileSystem ||
+                locationType == LocationType.Offline)
+            {
+                var collectionType = _libraryManager.GetInheritedContentType(item);
+                if (string.IsNullOrWhiteSpace(collectionType))
+                {
+                    info.ContentTypeOptions = GetContentTypeOptions(true);
+                    info.ContentType = _libraryManager.GetContentType(item);
+                }
+            }
+
             return ToOptimizedResult(info);
             return ToOptimizedResult(info);
         }
         }
 
 
+        public void Post(UpdateItemContentType request)
+        {
+            
+        }
+
+        private List<NameValuePair> GetContentTypeOptions(bool isForItem)
+        {
+            var list = new List<NameValuePair>();
+
+            if (isForItem)
+            {
+                list.Add(new NameValuePair
+                {
+                    Name = "FolderTypeInherit",
+                    Value = ""
+                });
+            }
+            
+            list.Add(new NameValuePair
+            {
+                Name = "FolderTypeMovies",
+                Value = "movies"
+            });
+            list.Add(new NameValuePair
+            {
+                Name = "FolderTypeMusic",
+                Value = "music"
+            });
+            list.Add(new NameValuePair
+            {
+                Name = "FolderTypeTvShows",
+                Value = "tvshows"
+            });
+
+            if (!isForItem)
+            {
+                list.Add(new NameValuePair
+                {
+                    Name = "FolderTypeBooks",
+                    Value = "books"
+                });
+                list.Add(new NameValuePair
+                {
+                    Name = "FolderTypeGames",
+                    Value = "games"
+                });
+            }
+
+            list.Add(new NameValuePair
+            {
+                Name = "FolderTypeHomeVideos",
+                Value = "homevideos"
+            });
+            list.Add(new NameValuePair
+            {
+                Name = "FolderTypeMusicVideos",
+                Value = "musicvideos"
+            });
+            list.Add(new NameValuePair
+            {
+                Name = "FolderTypePhotos",
+                Value = "photos"
+            });
+
+            if (!isForItem)
+            {
+                list.Add(new NameValuePair
+                {
+                    Name = "FolderTypeMixed",
+                    Value = ""
+                });
+            }
+
+            foreach (var val in list)
+            {
+                val.Name = _localizationManager.GetLocalizedString(val.Name);
+            }
+
+            return list;
+        }
+
         public void Post(UpdateItem request)
         public void Post(UpdateItem request)
         {
         {
             var task = UpdateItem(request);
             var task = UpdateItem(request);

+ 19 - 1
MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs

@@ -208,11 +208,29 @@ namespace MediaBrowser.Common.Implementations.Configuration
 
 
                 lock (_configurationSyncLock)
                 lock (_configurationSyncLock)
                 {
                 {
-                    return ConfigurationHelper.GetXmlConfiguration(configurationType, file, XmlSerializer);
+                    return LoadConfiguration(file, configurationType);
                 }
                 }
             });
             });
         }
         }
 
 
+        private object LoadConfiguration(string path, Type configurationType)
+        {
+            try
+            {
+                return XmlSerializer.DeserializeFromFile(configurationType, path);
+            }
+            catch (FileNotFoundException)
+            {
+                return Activator.CreateInstance(configurationType);
+            }
+            catch (Exception ex)
+            {
+                Logger.ErrorException("Error loading configuration file: {0}", ex, path);
+
+                return Activator.CreateInstance(configurationType);
+            }
+        }
+
         public void SaveConfiguration(string key, object configuration)
         public void SaveConfiguration(string key, object configuration)
         {
         {
             var configurationType = GetConfigurationType(key);
             var configurationType = GetConfigurationType(key);

+ 14 - 3
MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs

@@ -1,5 +1,6 @@
 using MediaBrowser.Model.Serialization;
 using MediaBrowser.Model.Serialization;
 using System;
 using System;
+using System.Collections.Concurrent;
 using System.IO;
 using System.IO;
 using System.Xml;
 using System.Xml;
 
 
@@ -10,6 +11,17 @@ namespace MediaBrowser.Common.Implementations.Serialization
     /// </summary>
     /// </summary>
     public class XmlSerializer : IXmlSerializer
     public class XmlSerializer : IXmlSerializer
     {
     {
+        // Need to cache these
+        // http://dotnetcodebox.blogspot.com/2013/01/xmlserializer-class-may-result-in.html
+        private readonly ConcurrentDictionary<string, System.Xml.Serialization.XmlSerializer> _serializers =
+            new ConcurrentDictionary<string, System.Xml.Serialization.XmlSerializer>();
+
+        private System.Xml.Serialization.XmlSerializer GetSerializer(Type type)
+        {
+            var key = type.FullName;
+            return _serializers.GetOrAdd(key, k => new System.Xml.Serialization.XmlSerializer(type));
+        }
+
         /// <summary>
         /// <summary>
         /// Serializes to writer.
         /// Serializes to writer.
         /// </summary>
         /// </summary>
@@ -18,7 +30,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
         private void SerializeToWriter(object obj, XmlTextWriter writer)
         private void SerializeToWriter(object obj, XmlTextWriter writer)
         {
         {
             writer.Formatting = Formatting.Indented;
             writer.Formatting = Formatting.Indented;
-            var netSerializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
+            var netSerializer = GetSerializer(obj.GetType());
             netSerializer.Serialize(writer, obj);
             netSerializer.Serialize(writer, obj);
         }
         }
 
 
@@ -32,8 +44,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
         {
         {
             using (var reader = new XmlTextReader(stream))
             using (var reader = new XmlTextReader(stream))
             {
             {
-                var netSerializer = new System.Xml.Serialization.XmlSerializer(type);
-
+                var netSerializer = GetSerializer(type);
                 return netSerializer.Deserialize(reader);
                 return netSerializer.Deserialize(reader);
             }
             }
         }
         }

+ 1 - 1
MediaBrowser.Controller/Entities/Folder.cs

@@ -708,7 +708,7 @@ namespace MediaBrowser.Controller.Entities
         /// <returns>IEnumerable{BaseItem}.</returns>
         /// <returns>IEnumerable{BaseItem}.</returns>
         protected virtual IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
         protected virtual IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
         {
         {
-            var collectionType = LibraryManager.FindCollectionType(this);
+            var collectionType = LibraryManager.GetContentType(this);
 
 
             return LibraryManager.ResolvePaths(GetFileSystemChildren(directoryService), directoryService, this, collectionType);
             return LibraryManager.ResolvePaths(GetFileSystemChildren(directoryService), directoryService, this, collectionType);
         }
         }

+ 8 - 1
MediaBrowser.Controller/Library/ILibraryManager.cs

@@ -259,8 +259,15 @@ namespace MediaBrowser.Controller.Library
         /// </summary>
         /// </summary>
         /// <param name="item">The item.</param>
         /// <param name="item">The item.</param>
         /// <returns>System.String.</returns>
         /// <returns>System.String.</returns>
-        string FindCollectionType(BaseItem item);
+        string GetContentType(BaseItem item);
 
 
+        /// <summary>
+        /// Gets the type of the inherited content.
+        /// </summary>
+        /// <param name="item">The item.</param>
+        /// <returns>System.String.</returns>
+        string GetInheritedContentType(BaseItem item);
+        
         /// <summary>
         /// <summary>
         /// Normalizes the root path list.
         /// Normalizes the root path list.
         /// </summary>
         /// </summary>

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

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

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

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

+ 4 - 0
MediaBrowser.Model/Dto/MetadataEditorInfo.cs

@@ -12,12 +12,16 @@ namespace MediaBrowser.Model.Dto
         public List<CultureDto> Cultures { get; set; }
         public List<CultureDto> Cultures { get; set; }
         public List<ExternalIdInfo> ExternalIdInfos { get; set; }
         public List<ExternalIdInfo> ExternalIdInfos { get; set; }
 
 
+        public string ContentType { get; set; }
+        public List<NameValuePair> ContentTypeOptions { get; set; }
+
         public MetadataEditorInfo()
         public MetadataEditorInfo()
         {
         {
             ParentalRatingOptions = new List<ParentalRating>();
             ParentalRatingOptions = new List<ParentalRating>();
             Countries = new List<CountryInfo>();
             Countries = new List<CountryInfo>();
             Cultures = new List<CultureDto>();
             Cultures = new List<CultureDto>();
             ExternalIdInfos = new List<ExternalIdInfo>();
             ExternalIdInfos = new List<ExternalIdInfo>();
+            ContentTypeOptions = new List<NameValuePair>();
         }
         }
     }
     }
 }
 }

+ 17 - 0
MediaBrowser.Model/Dto/NameValuePair.cs

@@ -0,0 +1,17 @@
+
+namespace MediaBrowser.Model.Dto
+{
+    public class NameValuePair
+    {
+        /// <summary>
+        /// Gets or sets the name.
+        /// </summary>
+        /// <value>The name.</value>
+        public string Name { get; set; }
+        /// <summary>
+        /// Gets or sets the value.
+        /// </summary>
+        /// <value>The value.</value>
+        public string Value { get; set; }
+    }
+}

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

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

+ 11 - 6
MediaBrowser.Server.Implementations/Library/LibraryManager.cs

@@ -1546,12 +1546,17 @@ namespace MediaBrowser.Server.Implementations.Library
             return ItemRepository.RetrieveItem(id);
             return ItemRepository.RetrieveItem(id);
         }
         }
 
 
-        /// <summary>
-        /// Finds the type of the collection.
-        /// </summary>
-        /// <param name="item">The item.</param>
-        /// <returns>System.String.</returns>
-        public string FindCollectionType(BaseItem item)
+        public string GetContentType(BaseItem item)
+        {
+            return GetInheritedContentType(item);
+        }
+
+        public string GetInheritedContentType(BaseItem item)
+        {
+            return GetTopFolderContentType(item);
+        }
+
+        private string GetTopFolderContentType(BaseItem item)
         {
         {
             while (!(item.Parent is AggregateFolder) && item.Parent != null)
             while (!(item.Parent is AggregateFolder) && item.Parent != null)
             {
             {

+ 12 - 0
MediaBrowser.Server.Implementations/Localization/Server/server.json

@@ -37,6 +37,18 @@
     "ButtonOk": "Ok",
     "ButtonOk": "Ok",
     "ButtonCancel": "Cancel",
     "ButtonCancel": "Cancel",
     "ButtonNew": "New",
     "ButtonNew": "New",
+    "FolderTypeMixed": "Mixed videos",
+    "FolderTypeMovies": "Movies",
+    "FolderTypeMusic": "Music",
+    "FolderTypeAdultVideos": "Adult videos",
+    "FolderTypePhotos": "Photos",
+    "FolderTypeMusicVideos": "Music videos",
+    "FolderTypeHomeVideos": "Home videos",
+    "FolderTypeGames": "Games",
+    "FolderTypeBooks": "Books",
+    "FolderTypeTvShows": "TV",
+    "FolderTypeInherit": "Inherit",
+    "LabelContentType":  "Content type:",
     "HeaderSetupLibrary": "Setup your media library",
     "HeaderSetupLibrary": "Setup your media library",
     "ButtonAddMediaFolder": "Add media folder",
     "ButtonAddMediaFolder": "Add media folder",
     "LabelFolderType": "Folder type:",
     "LabelFolderType": "Folder type:",