diff --git a/MediaBrowser.Api/DisplayPreferencesService.cs b/MediaBrowser.Api/DisplayPreferencesService.cs
index 870c62ccd6..b6c7434a16 100644
--- a/MediaBrowser.Api/DisplayPreferencesService.cs
+++ b/MediaBrowser.Api/DisplayPreferencesService.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Common.Extensions;
+using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Serialization;
using ServiceStack.ServiceHost;
@@ -20,7 +21,7 @@ namespace MediaBrowser.Api
///
/// The id.
[ApiMember(Name = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
- public Guid DisplayPreferencesId { get; set; }
+ public string DisplayPreferencesId { get; set; }
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public Guid UserId { get; set; }
@@ -38,7 +39,7 @@ namespace MediaBrowser.Api
///
/// The id.
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
- public Guid Id { get; set; }
+ public string Id { get; set; }
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public Guid UserId { get; set; }
@@ -78,7 +79,14 @@ namespace MediaBrowser.Api
/// The request.
public object Get(GetDisplayPreferences request)
{
- var result = _displayPreferencesManager.GetDisplayPreferences(request.Id, request.UserId, request.Client);
+ Guid displayPreferencesId;
+
+ if (!Guid.TryParse(request.Id, out displayPreferencesId))
+ {
+ displayPreferencesId = request.Id.GetMD5();
+ }
+
+ var result = _displayPreferencesManager.GetDisplayPreferences(displayPreferencesId, request.UserId, request.Client);
return ToOptimizedResult(result);
}
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
index 8bb07caa90..d4881c1675 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
@@ -142,6 +142,12 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.Name, StringComparison.CurrentCultureIgnoreCase) < 1);
}
+ var imageTypes = request.GetImageTypes().ToArray();
+ if (imageTypes.Length > 0)
+ {
+ items = items.Where(item => imageTypes.Any(imageType => ItemsService.HasImage(item.GetItem().Result, imageType)));
+ }
+
var filters = request.GetFilters().ToList();
if (filters.Count == 0)
@@ -221,6 +227,17 @@ namespace MediaBrowser.Api.UserLibrary
items = items.OrderBy(i => i.Name);
}
}
+ else if (string.Equals(request.SortBy, "Random", StringComparison.OrdinalIgnoreCase))
+ {
+ if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
+ {
+ items = items.OrderByDescending(i => Guid.NewGuid());
+ }
+ else
+ {
+ items = items.OrderBy(i => Guid.NewGuid());
+ }
+ }
return items;
}
@@ -358,7 +375,6 @@ namespace MediaBrowser.Api.UserLibrary
public string Name;
- public BaseItem Item;
private UserItemData _userData;
public List Items
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
index bc096f67cf..f1bb56b167 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
@@ -79,6 +79,13 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "MediaTypes", Description = "Optional filter by MediaType. Allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string MediaTypes { get; set; }
+ ///
+ /// Gets or sets the image types.
+ ///
+ /// The image types.
+ [ApiMember(Name = "ImageTypes", Description = "Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
+ public string ImageTypes { get; set; }
+
///
/// Gets the filters.
///
@@ -120,5 +127,21 @@ namespace MediaBrowser.Api.UserLibrary
}).Where(i => i.HasValue).Select(i => i.Value);
}
+
+ ///
+ /// Gets the image types.
+ ///
+ /// IEnumerable{ImageType}.
+ public IEnumerable GetImageTypes()
+ {
+ var val = ImageTypes;
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return new ImageType[] { };
+ }
+
+ return val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true));
+ }
}
}
diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs
index 5013f685a8..288b670573 100644
--- a/MediaBrowser.Api/UserLibrary/ItemsService.cs
+++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs
@@ -87,7 +87,7 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "Albums", Description = "Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Albums { get; set; }
-
+
///
/// Limit results to items containing specific years
///
@@ -95,13 +95,6 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "Years", Description = "Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Years { get; set; }
- ///
- /// Gets or sets the image types.
- ///
- /// The image types.
- [ApiMember(Name = "ImageTypes", Description = "Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
- public string ImageTypes { get; set; }
-
///
/// Gets or sets the item ids.
///
@@ -174,7 +167,7 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "MinIndexNumber", Description = "Optional filter index number.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? MinIndexNumber { get; set; }
-
+
///
/// Gets the order by.
///
@@ -620,7 +613,7 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => !string.IsNullOrEmpty(i.MediaType) && types.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase));
}
- var imageTypes = GetImageTypes(request).ToArray();
+ var imageTypes = request.GetImageTypes().ToArray();
if (imageTypes.Length > 0)
{
items = items.Where(item => imageTypes.Any(imageType => HasImage(item, imageType)));
@@ -717,7 +710,7 @@ namespace MediaBrowser.Api.UserLibrary
/// The item.
/// Type of the image.
/// true if the specified item has image; otherwise, false.
- private static bool HasImage(BaseItem item, ImageType imageType)
+ internal static bool HasImage(BaseItem item, ImageType imageType)
{
if (imageType == ImageType.Backdrop)
{
@@ -772,23 +765,6 @@ namespace MediaBrowser.Api.UserLibrary
return items;
}
-
- ///
- /// Gets the image types.
- ///
- /// The request.
- /// IEnumerable{ImageType}.
- private static IEnumerable GetImageTypes(GetItems request)
- {
- var val = request.ImageTypes;
-
- if (string.IsNullOrEmpty(val))
- {
- return new ImageType[] { };
- }
-
- return val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true));
- }
}
///