add movie count sort order
This commit is contained in:
parent
3c2ec758be
commit
9d7b3fdda6
|
@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Persistence;
|
using MediaBrowser.Controller.Persistence;
|
||||||
using MediaBrowser.Model.Dto;
|
using MediaBrowser.Model.Dto;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Querying;
|
using MediaBrowser.Model.Querying;
|
||||||
using ServiceStack.ServiceHost;
|
using ServiceStack.ServiceHost;
|
||||||
using System;
|
using System;
|
||||||
|
@ -81,7 +82,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
items = request.Recursive ? folder.RecursiveChildren: folder.Children;
|
items = request.Recursive ? folder.RecursiveChildren : folder.Children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -149,7 +150,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
items = items.Where(item => imageTypes.Any(imageType => ItemsService.HasImage(item.GetItem().Result, imageType)));
|
items = items.Where(item => imageTypes.Any(imageType => ItemsService.HasImage(item.GetItem().Result, imageType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var filters = request.GetFilters().ToList();
|
var filters = request.GetFilters().ToList();
|
||||||
|
|
||||||
if (filters.Count == 0)
|
if (filters.Count == 0)
|
||||||
|
@ -162,18 +163,20 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
if (filters.Contains(ItemFilter.Dislikes))
|
if (filters.Contains(ItemFilter.Dislikes))
|
||||||
{
|
{
|
||||||
items = items.Where(i =>
|
items = items.Where(i =>
|
||||||
{
|
{
|
||||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
var item = i.GetItem().Result;
|
||||||
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||||
|
|
||||||
return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value;
|
return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filters.Contains(ItemFilter.Likes))
|
if (filters.Contains(ItemFilter.Likes))
|
||||||
{
|
{
|
||||||
items = items.Where(i =>
|
items = items.Where(i =>
|
||||||
{
|
{
|
||||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
var item = i.GetItem().Result;
|
||||||
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||||
|
|
||||||
return userdata != null && userdata.Likes.HasValue && userdata.Likes.Value;
|
return userdata != null && userdata.Likes.HasValue && userdata.Likes.Value;
|
||||||
});
|
});
|
||||||
|
@ -183,12 +186,8 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
items = items.Where(i =>
|
items = items.Where(i =>
|
||||||
{
|
{
|
||||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
var item = i.GetItem().Result;
|
||||||
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||||
if (userdata == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var likes = userdata.Likes ?? false;
|
var likes = userdata.Likes ?? false;
|
||||||
var favorite = userdata.IsFavorite;
|
var favorite = userdata.IsFavorite;
|
||||||
|
@ -196,20 +195,21 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
return likes || favorite;
|
return likes || favorite;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filters.Contains(ItemFilter.IsFavorite))
|
if (filters.Contains(ItemFilter.IsFavorite))
|
||||||
{
|
{
|
||||||
items = items.Where(i =>
|
items = items.Where(i =>
|
||||||
{
|
{
|
||||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
var item = i.GetItem().Result;
|
||||||
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||||
|
|
||||||
return userdata != null && userdata.Likes.HasValue && userdata.IsFavorite;
|
return userdata != null && userdata.Likes.HasValue && userdata.IsFavorite;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.AsEnumerable();
|
return items.AsEnumerable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sorts the items.
|
/// Sorts the items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -220,7 +220,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
if (string.Equals(request.SortBy, "SortName", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(request.SortBy, "SortName", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
|
if (request.SortOrder.HasValue && request.SortOrder.Value == SortOrder.Descending)
|
||||||
{
|
{
|
||||||
items = items.OrderByDescending(i => i.Name);
|
items = items.OrderByDescending(i => i.Name);
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
}
|
}
|
||||||
else if (string.Equals(request.SortBy, "Random", StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(request.SortBy, "Random", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
|
if (request.SortOrder.HasValue && request.SortOrder.Value == SortOrder.Descending)
|
||||||
{
|
{
|
||||||
items = items.OrderByDescending(i => Guid.NewGuid());
|
items = items.OrderByDescending(i => Guid.NewGuid());
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
|
|
||||||
items = items.Where(f => vals.Contains(f.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase));
|
items = items.Where(f => vals.Contains(f.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
|
|
||||||
[ApiMember(Name = "NameStartsWithOrGreater", Description = "Optional filter by items whose name is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
[ApiMember(Name = "NameStartsWithOrGreater", Description = "Optional filter by items whose name is sorted equally or greater than a given input string.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
public string NameStartsWithOrGreater { get; set; }
|
public string NameStartsWithOrGreater { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// What to sort the results by
|
/// What to sort the results by
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -361,26 +361,17 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
public class IbnStub<T>
|
public class IbnStub<T>
|
||||||
where T : BaseItem
|
where T : BaseItem
|
||||||
{
|
{
|
||||||
private readonly Func<string,Task<T>> _itemFunction;
|
private readonly Func<string, Task<T>> _itemFunction;
|
||||||
private Task<T> _itemTask;
|
private Task<T> _itemTask;
|
||||||
|
|
||||||
public string Name;
|
|
||||||
|
|
||||||
private UserItemData _userData;
|
public string Name;
|
||||||
|
|
||||||
public Task<T> GetItem()
|
public Task<T> GetItem()
|
||||||
{
|
{
|
||||||
return _itemTask ?? (_itemTask = _itemFunction(Name));
|
return _itemTask ?? (_itemTask = _itemFunction(Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserItemData> GetUserItemData(IUserDataRepository repo, Guid userId)
|
public IbnStub(string name, Func<string, Task<T>> item)
|
||||||
{
|
|
||||||
var item = await GetItem().ConfigureAwait(false);
|
|
||||||
|
|
||||||
return _userData ?? (_userData = repo.GetUserData(userId, item.GetUserDataKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IbnStub(string name, Func<string,Task<T>> item)
|
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
_itemFunction = item;
|
_itemFunction = item;
|
||||||
|
|
|
@ -13,4 +13,24 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
|
Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class IItemByNameExtensions
|
||||||
|
{
|
||||||
|
public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, User user)
|
||||||
|
{
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return item.ItemCounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemByNameCounts counts;
|
||||||
|
|
||||||
|
if (item.UserItemCounts.TryGetValue(user.Id, out counts))
|
||||||
|
{
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,5 +74,7 @@ namespace MediaBrowser.Model.Querying
|
||||||
public const string IsFolder = "IsFolder";
|
public const string IsFolder = "IsFolder";
|
||||||
public const string IsUnplayed = "IsUnplayed";
|
public const string IsUnplayed = "IsUnplayed";
|
||||||
public const string IsPlayed = "IsPlayed";
|
public const string IsPlayed = "IsPlayed";
|
||||||
|
public const string TrailerCount = "TrailerCount";
|
||||||
|
public const string MovieCount = "MovieCount";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,6 +189,7 @@
|
||||||
<Compile Include="Sorting\DatePlayedComparer.cs" />
|
<Compile Include="Sorting\DatePlayedComparer.cs" />
|
||||||
<Compile Include="Sorting\IsFolderComparer.cs" />
|
<Compile Include="Sorting\IsFolderComparer.cs" />
|
||||||
<Compile Include="Sorting\IsUnplayedComparer.cs" />
|
<Compile Include="Sorting\IsUnplayedComparer.cs" />
|
||||||
|
<Compile Include="Sorting\MovieCountComparer.cs" />
|
||||||
<Compile Include="Sorting\NameComparer.cs" />
|
<Compile Include="Sorting\NameComparer.cs" />
|
||||||
<Compile Include="Sorting\OfficialRatingComparer.cs" />
|
<Compile Include="Sorting\OfficialRatingComparer.cs" />
|
||||||
<Compile Include="Sorting\PlayCountComparer.cs" />
|
<Compile Include="Sorting\PlayCountComparer.cs" />
|
||||||
|
@ -202,6 +203,7 @@
|
||||||
<Compile Include="Persistence\SqliteItemRepository.cs" />
|
<Compile Include="Persistence\SqliteItemRepository.cs" />
|
||||||
<Compile Include="Persistence\SqliteUserDataRepository.cs" />
|
<Compile Include="Persistence\SqliteUserDataRepository.cs" />
|
||||||
<Compile Include="Persistence\SqliteUserRepository.cs" />
|
<Compile Include="Persistence\SqliteUserRepository.cs" />
|
||||||
|
<Compile Include="Sorting\TrailerCountComparer.cs" />
|
||||||
<Compile Include="Udp\UdpMessageReceivedEventArgs.cs" />
|
<Compile Include="Udp\UdpMessageReceivedEventArgs.cs" />
|
||||||
<Compile Include="Udp\UdpServer.cs" />
|
<Compile Include="Udp\UdpServer.cs" />
|
||||||
<Compile Include="WebSocket\AlchemyServer.cs" />
|
<Compile Include="WebSocket\AlchemyServer.cs" />
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Persistence;
|
||||||
|
using MediaBrowser.Controller.Sorting;
|
||||||
|
using MediaBrowser.Model.Querying;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
|
{
|
||||||
|
public class MovieCountComparer : IUserBaseItemComparer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user.</value>
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user manager.</value>
|
||||||
|
public IUserManager UserManager { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user data repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user data repository.</value>
|
||||||
|
public IUserDataRepository UserDataRepository { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compares the specified x.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The x.</param>
|
||||||
|
/// <param name="y">The y.</param>
|
||||||
|
/// <returns>System.Int32.</returns>
|
||||||
|
public int Compare(BaseItem x, BaseItem y)
|
||||||
|
{
|
||||||
|
return GetValue(x).CompareTo(GetValue(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the date.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The x.</param>
|
||||||
|
/// <returns>DateTime.</returns>
|
||||||
|
private int GetValue(BaseItem x)
|
||||||
|
{
|
||||||
|
var itemByName = x as IItemByName;
|
||||||
|
|
||||||
|
if (itemByName != null)
|
||||||
|
{
|
||||||
|
var counts = itemByName.GetItemByNameCounts(User);
|
||||||
|
|
||||||
|
if (counts != null)
|
||||||
|
{
|
||||||
|
return counts.MovieCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name.</value>
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return ItemSortBy.MovieCount; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Persistence;
|
||||||
|
using MediaBrowser.Controller.Sorting;
|
||||||
|
using MediaBrowser.Model.Querying;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
|
{
|
||||||
|
public class TrailerCountComparer : IUserBaseItemComparer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user.</value>
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user manager.</value>
|
||||||
|
public IUserManager UserManager { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user data repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user data repository.</value>
|
||||||
|
public IUserDataRepository UserDataRepository { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compares the specified x.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The x.</param>
|
||||||
|
/// <param name="y">The y.</param>
|
||||||
|
/// <returns>System.Int32.</returns>
|
||||||
|
public int Compare(BaseItem x, BaseItem y)
|
||||||
|
{
|
||||||
|
return GetValue(x).CompareTo(GetValue(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the date.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The x.</param>
|
||||||
|
/// <returns>DateTime.</returns>
|
||||||
|
private int GetValue(BaseItem x)
|
||||||
|
{
|
||||||
|
var itemByName = x as IItemByName;
|
||||||
|
|
||||||
|
if (itemByName != null)
|
||||||
|
{
|
||||||
|
var counts = itemByName.GetItemByNameCounts(User);
|
||||||
|
|
||||||
|
if (counts != null)
|
||||||
|
{
|
||||||
|
return counts.TrailerCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The name.</value>
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return ItemSortBy.TrailerCount; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user