The Free Software Media System - Server Backend & API
added content type selection
Luke Pulverenti498b58aad0b2
diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.csindex 953f7b3bb0..020908ddd5 100644--- a/MediaBrowser.Api/ItemUpdateService.cs+++ b/MediaBrowser.Api/ItemUpdateService.cs@@ -1,4 +1,5 @@-using MediaBrowser.Controller.Entities;+using MediaBrowser.Controller.Configuration;+using MediaBrowser.Controller.Entities;using MediaBrowser.Controller.Entities.Audio;using MediaBrowser.Controller.Entities.TV;using MediaBrowser.Controller.Library;@@ -46,12 +47,14 @@ namespace MediaBrowser.Apiprivate readonly ILibraryManager _libraryManager;private readonly IProviderManager _providerManager;private readonly ILocalizationManager _localizationManager;+ private readonly IServerConfigurationManager _config;- public ItemUpdateService(ILibraryManager libraryManager, IProviderManager providerManager, ILocalizationManager localizationManager)+ public ItemUpdateService(ILibraryManager libraryManager, IProviderManager providerManager, ILocalizationManager localizationManager, IServerConfigurationManager config){_libraryManager = libraryManager;_providerManager = providerManager;_localizationManager = localizationManager;+ _config = config;}public object Get(GetMetadataEditorInfo request)@@ -70,11 +73,14 @@ namespace MediaBrowser.Apiif (locationType == LocationType.FileSystem ||locationType == LocationType.Offline){- var collectionType = _libraryManager.GetInheritedContentType(item);- if (string.IsNullOrWhiteSpace(collectionType))+ if (!(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder)){- info.ContentTypeOptions = GetContentTypeOptions(true);- info.ContentType = _libraryManager.GetContentType(item);+ var collectionType = _libraryManager.GetInheritedContentType(item);+ if (string.IsNullOrWhiteSpace(collectionType))+ {+ info.ContentTypeOptions = GetContentTypeOptions(true);+ info.ContentType = _libraryManager.GetContentType(item);+ }}}@@ -83,7 +89,24 @@ namespace MediaBrowser.Apipublic void Post(UpdateItemContentType request){-+ var item = _libraryManager.GetItemById(request.ItemId);+ var path = item.ContainingFolderPath;++ var types = _config.Configuration.ContentTypes+ .Where(i => !string.Equals(i.Name, path, StringComparison.OrdinalIgnoreCase))+ .ToList();++ if (!string.IsNullOrWhiteSpace(request.ContentType))+ {+ types.Add(new NameValuePair+ {+ Name = path,+ Value = request.ContentType+ });+ }++ _config.Configuration.ContentTypes = types.ToArray();+ _config.SaveConfiguration();}private List<NameValuePair> GetContentTypeOptions(bool isForItem)diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.csindex 7cdfb7788a..8573f32e0b 100644--- a/MediaBrowser.Controller/Library/ILibraryManager.cs+++ b/MediaBrowser.Controller/Library/ILibraryManager.cs@@ -23,11 +23,9 @@ namespace MediaBrowser.Controller.Library/// </summary>/// <param name="fileInfo">The file information.</param>/// <param name="parent">The parent.</param>- /// <param name="collectionType">Type of the collection.</param>/// <returns>BaseItem.</returns>BaseItem ResolvePath(FileSystemInfo fileInfo,- Folder parent = null,- string collectionType = null);+ Folder parent = null);/// <summary>/// Resolves a set of files into a list of BaseItemdiff --git a/MediaBrowser.Model/Configuration/CinemaModeConfiguration.cs b/MediaBrowser.Model/Configuration/CinemaModeConfiguration.csindex bd20713de4..764a7222f6 100644--- a/MediaBrowser.Model/Configuration/CinemaModeConfiguration.cs+++ b/MediaBrowser.Model/Configuration/CinemaModeConfiguration.cs@@ -19,6 +19,7 @@ namespace MediaBrowser.Model.Configurationpublic CinemaModeConfiguration(){EnableIntrosParentalControl = true;+ EnableIntrosFromSimilarMovies = true;TrailerLimit = 2;}}diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.csindex 0852e0a5c6..7307354994 100644--- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs+++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs@@ -1,4 +1,5 @@-using MediaBrowser.Model.Entities;+using MediaBrowser.Model.Dto;+using MediaBrowser.Model.Entities;namespace MediaBrowser.Model.Configuration{@@ -165,6 +166,8 @@ namespace MediaBrowser.Model.Configurationpublic bool SaveMetadataHidden { get; set; }+ public NameValuePair[] ContentTypes { get; set; }+/// <summary>/// Initializes a new instance of the <see cref="ServerConfiguration" /> class./// </summary>@@ -192,6 +195,7 @@ namespace MediaBrowser.Model.ConfigurationFindInternetTrailers = true;PathSubstitutions = new PathSubstitution[] { };+ ContentTypes = new NameValuePair[] { };PreferredMetadataLanguage = "en";MetadataCountryCode = "US";diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.csindex ab50c30fbd..d52288f871 100644--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs@@ -560,10 +560,9 @@ namespace MediaBrowser.Server.Implementations.Library}public BaseItem ResolvePath(FileSystemInfo fileInfo,- Folder parent = null,- string collectionType = null)+ Folder parent = null){- return ResolvePath(fileInfo, new DirectoryService(_logger), parent, collectionType);+ return ResolvePath(fileInfo, new DirectoryService(_logger), parent);}private BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null)@@ -573,10 +572,17 @@ namespace MediaBrowser.Server.Implementations.Librarythrow new ArgumentNullException("fileInfo");}+ var fullPath = fileInfo.FullName;++ if (string.IsNullOrWhiteSpace(collectionType))+ {+ collectionType = GetConfiguredContentType(fullPath);+ }+var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, this, directoryService){Parent = parent,- Path = fileInfo.FullName,+ Path = fullPath,FileInfo = fileInfo,CollectionType = collectionType};@@ -1548,12 +1554,43 @@ namespace MediaBrowser.Server.Implementations.Librarypublic string GetContentType(BaseItem item){- return GetInheritedContentType(item);+ // Types cannot be overridden, so go from the top down until we find a configured content type++ var type = GetTopFolderContentType(item);++ if (!string.IsNullOrWhiteSpace(type))+ {+ return type;+ }++ type = GetInheritedContentType(item);++ if (!string.IsNullOrWhiteSpace(type))+ {+ return type;+ }++ return GetConfiguredContentType(item);}public string GetInheritedContentType(BaseItem item){- return GetTopFolderContentType(item);+ return item.Parents+ .Select(GetConfiguredContentType)+ .LastOrDefault(i => !string.IsNullOrWhiteSpace(i));+ }++ private string GetConfiguredContentType(BaseItem item)+ {+ return GetConfiguredContentType(item.ContainingFolderPath);+ }++ private string GetConfiguredContentType(string path)+ {+ var type = ConfigurationManager.Configuration.ContentTypes+ .FirstOrDefault(i => string.Equals(i.Name, path, StringComparison.OrdinalIgnoreCase) || _fileSystem.ContainsSubPath(i.Name, path));++ return type == null ? null : type.Value;}private string GetTopFolderContentType(BaseItem item)diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.csindex 58b5dbc6ae..01dc4db8a8 100644--- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs@@ -79,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Moviesreturn ResolveVideos<Video>(parent, files, directoryService, collectionType);}- return ResolveVideos<Movie>(parent, files, directoryService, collectionType);+ return ResolveVideos<Video>(parent, files, directoryService, collectionType);}if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))@@ -219,7 +219,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies}else if (string.IsNullOrEmpty(collectionType)){- item = ResolveVideo<Movie>(args, false);+ item = ResolveVideo<Video>(args, false);}if (item != null)