diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index 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.Api private 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.Api if (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.Api public 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 GetContentTypeOptions(bool isForItem) diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 7cdfb7788a..8573f32e0b 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -23,11 +23,9 @@ namespace MediaBrowser.Controller.Library /// /// The file information. /// The parent. - /// Type of the collection. /// BaseItem. BaseItem ResolvePath(FileSystemInfo fileInfo, - Folder parent = null, - string collectionType = null); + Folder parent = null); /// /// Resolves a set of files into a list of BaseItem diff --git a/MediaBrowser.Model/Configuration/CinemaModeConfiguration.cs b/MediaBrowser.Model/Configuration/CinemaModeConfiguration.cs index bd20713de4..764a7222f6 100644 --- a/MediaBrowser.Model/Configuration/CinemaModeConfiguration.cs +++ b/MediaBrowser.Model/Configuration/CinemaModeConfiguration.cs @@ -19,6 +19,7 @@ namespace MediaBrowser.Model.Configuration public CinemaModeConfiguration() { EnableIntrosParentalControl = true; + EnableIntrosFromSimilarMovies = true; TrailerLimit = 2; } } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 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.Configuration public bool SaveMetadataHidden { get; set; } + public NameValuePair[] ContentTypes { get; set; } + /// /// Initializes a new instance of the class. /// @@ -192,6 +195,7 @@ namespace MediaBrowser.Model.Configuration FindInternetTrailers = 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.cs index 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.Library throw 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.Library public 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.cs index 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.Movies return ResolveVideos