added content type selection

This commit is contained in:
Luke Pulverenti 2014-12-22 01:50:29 -05:00
parent 98ae564226
commit 498b58aad0
6 changed files with 82 additions and 19 deletions

View File

@ -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.Audio;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -46,12 +47,14 @@ namespace MediaBrowser.Api
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IProviderManager _providerManager; private readonly IProviderManager _providerManager;
private readonly ILocalizationManager _localizationManager; 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; _libraryManager = libraryManager;
_providerManager = providerManager; _providerManager = providerManager;
_localizationManager = localizationManager; _localizationManager = localizationManager;
_config = config;
} }
public object Get(GetMetadataEditorInfo request) public object Get(GetMetadataEditorInfo request)
@ -69,6 +72,8 @@ namespace MediaBrowser.Api
var locationType = item.LocationType; var locationType = item.LocationType;
if (locationType == LocationType.FileSystem || if (locationType == LocationType.FileSystem ||
locationType == LocationType.Offline) locationType == LocationType.Offline)
{
if (!(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder))
{ {
var collectionType = _libraryManager.GetInheritedContentType(item); var collectionType = _libraryManager.GetInheritedContentType(item);
if (string.IsNullOrWhiteSpace(collectionType)) if (string.IsNullOrWhiteSpace(collectionType))
@ -77,13 +82,31 @@ namespace MediaBrowser.Api
info.ContentType = _libraryManager.GetContentType(item); info.ContentType = _libraryManager.GetContentType(item);
} }
} }
}
return ToOptimizedResult(info); return ToOptimizedResult(info);
} }
public void Post(UpdateItemContentType request) 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<NameValuePair> GetContentTypeOptions(bool isForItem) private List<NameValuePair> GetContentTypeOptions(bool isForItem)

View File

@ -23,11 +23,9 @@ namespace MediaBrowser.Controller.Library
/// </summary> /// </summary>
/// <param name="fileInfo">The file information.</param> /// <param name="fileInfo">The file information.</param>
/// <param name="parent">The parent.</param> /// <param name="parent">The parent.</param>
/// <param name="collectionType">Type of the collection.</param>
/// <returns>BaseItem.</returns> /// <returns>BaseItem.</returns>
BaseItem ResolvePath(FileSystemInfo fileInfo, BaseItem ResolvePath(FileSystemInfo fileInfo,
Folder parent = null, Folder parent = null);
string collectionType = null);
/// <summary> /// <summary>
/// Resolves a set of files into a list of BaseItem /// Resolves a set of files into a list of BaseItem

View File

@ -19,6 +19,7 @@ namespace MediaBrowser.Model.Configuration
public CinemaModeConfiguration() public CinemaModeConfiguration()
{ {
EnableIntrosParentalControl = true; EnableIntrosParentalControl = true;
EnableIntrosFromSimilarMovies = true;
TrailerLimit = 2; TrailerLimit = 2;
} }
} }

View File

@ -1,4 +1,5 @@
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Configuration namespace MediaBrowser.Model.Configuration
{ {
@ -165,6 +166,8 @@ namespace MediaBrowser.Model.Configuration
public bool SaveMetadataHidden { get; set; } public bool SaveMetadataHidden { get; set; }
public NameValuePair[] ContentTypes { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class. /// Initializes a new instance of the <see cref="ServerConfiguration" /> class.
/// </summary> /// </summary>
@ -192,6 +195,7 @@ namespace MediaBrowser.Model.Configuration
FindInternetTrailers = true; FindInternetTrailers = true;
PathSubstitutions = new PathSubstitution[] { }; PathSubstitutions = new PathSubstitution[] { };
ContentTypes = new NameValuePair[] { };
PreferredMetadataLanguage = "en"; PreferredMetadataLanguage = "en";
MetadataCountryCode = "US"; MetadataCountryCode = "US";

View File

@ -560,10 +560,9 @@ namespace MediaBrowser.Server.Implementations.Library
} }
public BaseItem ResolvePath(FileSystemInfo fileInfo, public BaseItem ResolvePath(FileSystemInfo fileInfo,
Folder parent = null, Folder parent = null)
string collectionType = 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) 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"); throw new ArgumentNullException("fileInfo");
} }
var fullPath = fileInfo.FullName;
if (string.IsNullOrWhiteSpace(collectionType))
{
collectionType = GetConfiguredContentType(fullPath);
}
var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, this, directoryService) var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, this, directoryService)
{ {
Parent = parent, Parent = parent,
Path = fileInfo.FullName, Path = fullPath,
FileInfo = fileInfo, FileInfo = fileInfo,
CollectionType = collectionType CollectionType = collectionType
}; };
@ -1548,12 +1554,43 @@ namespace MediaBrowser.Server.Implementations.Library
public string GetContentType(BaseItem item) 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) 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) private string GetTopFolderContentType(BaseItem item)

View File

@ -79,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return ResolveVideos<Video>(parent, files, directoryService, collectionType); return 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)) if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
@ -219,7 +219,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
} }
else if (string.IsNullOrEmpty(collectionType)) else if (string.IsNullOrEmpty(collectionType))
{ {
item = ResolveVideo<Movie>(args, false); item = ResolveVideo<Video>(args, false);
} }
if (item != null) if (item != null)