start on content type setting
This commit is contained in:
parent
659128073e
commit
74520804f8
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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
MediaBrowser.Model/Dto/NameValuePair.cs
Normal file
17
MediaBrowser.Model/Dto/NameValuePair.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -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" />
|
||||||
|
|
|
@ -1546,12 +1546,17 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
return ItemRepository.RetrieveItem(id);
|
return ItemRepository.RetrieveItem(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public string GetContentType(BaseItem item)
|
||||||
/// Finds the type of the collection.
|
{
|
||||||
/// </summary>
|
return GetInheritedContentType(item);
|
||||||
/// <param name="item">The item.</param>
|
}
|
||||||
/// <returns>System.String.</returns>
|
|
||||||
public string FindCollectionType(BaseItem 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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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:",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user