diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-08-02 22:16:37 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-08-02 22:16:37 -0400 |
| commit | 2714127d2b663b735048da6d9def08efa38f2b5f (patch) | |
| tree | b260b23486fddf75d2dfa292544c7e03c05a74ce /MediaBrowser.Controller/Playlists | |
| parent | f0464dfa17d146f34849e45097085b891e51ebc8 (diff) | |
fixes #791 - Support server-side playlists
Diffstat (limited to 'MediaBrowser.Controller/Playlists')
| -rw-r--r-- | MediaBrowser.Controller/Playlists/Playlist.cs | 77 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Playlists/PlaylistCreationOptions.cs | 4 |
2 files changed, 76 insertions, 5 deletions
diff --git a/MediaBrowser.Controller/Playlists/Playlist.cs b/MediaBrowser.Controller/Playlists/Playlist.cs index e20387eba3..5ea535f4d5 100644 --- a/MediaBrowser.Controller/Playlists/Playlist.cs +++ b/MediaBrowser.Controller/Playlists/Playlist.cs @@ -1,20 +1,87 @@ using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Querying; +using System; using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; namespace MediaBrowser.Controller.Playlists { public class Playlist : Folder { - public List<string> ItemIds { get; set; } + public string OwnerUserId { get; set; } - public Playlist() + public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren) { - ItemIds = new List<string>(); + return GetPlayableItems(user); } - public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren) + public override IEnumerable<BaseItem> GetRecursiveChildren(User user, bool includeLinkedChildren = true) + { + return GetPlayableItems(user); + } + + public IEnumerable<BaseItem> GetManageableItems() + { + return GetLinkedChildren(); + } + + private IEnumerable<BaseItem> GetPlayableItems(User user) + { + return GetPlaylistItems(MediaType, base.GetChildren(user, true), user); + } + + public static IEnumerable<BaseItem> GetPlaylistItems(string playlistMediaType, IEnumerable<BaseItem> inputItems, User user) + { + return inputItems.SelectMany(i => + { + var folder = i as Folder; + + if (folder != null) + { + var items = folder.GetRecursiveChildren(user, true) + .Where(m => !m.IsFolder && string.Equals(m.MediaType, playlistMediaType, StringComparison.OrdinalIgnoreCase)); + + if (!folder.IsPreSorted) + { + items = LibraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending); + } + + return items; + } + + return new[] { i }; + }); + } + + [IgnoreDataMember] + public override bool IsPreSorted + { + get + { + return true; + } + } + + public string PlaylistMediaType { get; set; } + + public override string MediaType + { + get + { + return PlaylistMediaType; + } + } + + public void SetMediaType(string value) + { + PlaylistMediaType = value; + } + + public override bool IsVisible(User user) { - return base.GetChildren(user, includeLinkedChildren); + return base.IsVisible(user) && string.Equals(user.Id.ToString("N"), OwnerUserId); } } } diff --git a/MediaBrowser.Controller/Playlists/PlaylistCreationOptions.cs b/MediaBrowser.Controller/Playlists/PlaylistCreationOptions.cs index a62cbe12e5..1766ba75ca 100644 --- a/MediaBrowser.Controller/Playlists/PlaylistCreationOptions.cs +++ b/MediaBrowser.Controller/Playlists/PlaylistCreationOptions.cs @@ -8,6 +8,10 @@ namespace MediaBrowser.Controller.Playlists public List<string> ItemIdList { get; set; } + public string MediaType { get; set; } + + public string UserId { get; set; } + public PlaylistCreationOptions() { ItemIdList = new List<string>(); |
