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 string OwnerUserId { get; set; } protected override bool FilterLinkedChildrenPerUser { get { return true; } } public override IEnumerable GetChildren(User user, bool includeLinkedChildren) { return GetPlayableItems(user); } public override IEnumerable GetRecursiveChildren(User user, bool includeLinkedChildren = true) { return GetPlayableItems(user); } public IEnumerable> GetManageableItems() { return GetLinkedChildrenInfos(); } private IEnumerable GetPlayableItems(User user) { return GetPlaylistItems(MediaType, base.GetChildren(user, true), user); } public static IEnumerable GetPlaylistItems(string playlistMediaType, IEnumerable inputItems, User user) { if (user != null) { inputItems = inputItems.Where(i => i.IsVisible(user)); } inputItems = inputItems.SelectMany(i => { var folder = i as Folder; if (folder != null) { var items = user == null ? folder.GetRecursiveChildren() : folder.GetRecursiveChildren(user, true); items = items .Where(m => !m.IsFolder); if (!folder.IsPreSorted) { items = LibraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending); } return items; } return new[] { i }; }).Where(m => string.Equals(m.MediaType, playlistMediaType, StringComparison.OrdinalIgnoreCase)); return FilterInaccessibleItems(inputItems, user); } public static IEnumerable FilterInaccessibleItems(IEnumerable items, User user) { return items; //var locations = user.RootFolder.Children.OfType().SelectMany(i => i.PhysicalLocations).ToList(); //return items.Where(i => //{ // var parent = i.Parent; // while (parent != null) // { // parent = parent.Parent; // if (parent != null && parent.Parent is AggregateFolder) // { // break; // } // } // return parent == null || locations.Contains(parent.Path, StringComparer.OrdinalIgnoreCase); //}); } [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.IsVisible(user) && string.Equals(user.Id.ToString("N"), OwnerUserId); } } }