diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 939a173149..a8a9109c1b 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -48,7 +48,7 @@ namespace MediaBrowser.Api.UserLibrary /// What to sort the results by /// /// The sort by. - [ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, CommunityRating, DateCreated, DatePlayed, PremiereDate, ProductionYear, SortName, Random, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + [ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, CommunityRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string SortBy { get; set; } /// @@ -243,6 +243,22 @@ namespace MediaBrowser.Api.UserLibrary { switch (filter) { + case ItemFilter.Likes: + return items.Where(item => + { + var userdata = item.GetUserData(user, false); + + return userdata != null && userdata.Likes.HasValue && userdata.Likes.Value; + }); + + case ItemFilter.Dislikes: + return items.Where(item => + { + var userdata = item.GetUserData(user, false); + + return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value; + }); + case ItemFilter.IsFavorite: return items.Where(item => { diff --git a/MediaBrowser.Model/Querying/ItemFilter.cs b/MediaBrowser.Model/Querying/ItemFilter.cs index 9c7f139a80..38ca67fa2c 100644 --- a/MediaBrowser.Model/Querying/ItemFilter.cs +++ b/MediaBrowser.Model/Querying/ItemFilter.cs @@ -33,6 +33,14 @@ namespace MediaBrowser.Model.Querying /// /// The item is resumable /// - IsResumable = 7 + IsResumable = 7, + /// + /// The likes + /// + Likes = 8, + /// + /// The dislikes + /// + Dislikes = 9 } } diff --git a/MediaBrowser.Model/Querying/ItemSortBy.cs b/MediaBrowser.Model/Querying/ItemSortBy.cs index 9599e2aac2..c85ed8780a 100644 --- a/MediaBrowser.Model/Querying/ItemSortBy.cs +++ b/MediaBrowser.Model/Querying/ItemSortBy.cs @@ -50,5 +50,9 @@ namespace MediaBrowser.Model.Querying /// The production year /// public const string ProductionYear = "ProductionYear"; + /// + /// The play count + /// + public const string PlayCount = "PlayCount"; } } diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 4303c4f80c..0ce5a7f44a 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -163,6 +163,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Sorting/PlayCountComparer.cs b/MediaBrowser.Server.Implementations/Sorting/PlayCountComparer.cs new file mode 100644 index 0000000000..9cd5281c36 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/PlayCountComparer.cs @@ -0,0 +1,50 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.Server.Implementations.Sorting +{ + /// + /// Class PlayCountComparer + /// + public class PlayCountComparer : IUserBaseItemComparer + { + /// + /// Gets or sets the user. + /// + /// The user. + public User User { get; set; } + + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + return GetValue(x).CompareTo(GetValue(y)); + } + + /// + /// Gets the date. + /// + /// The x. + /// DateTime. + private int GetValue(BaseItem x) + { + var userdata = x.GetUserData(User, false); + + return userdata == null ? 0 : userdata.PlayCount; + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.PlayCount; } + } + } +}