using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; 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)); } return inputItems.SelectMany(i => GetPlaylistItems(i, user)) .Where(m => string.Equals(m.MediaType, playlistMediaType, StringComparison.OrdinalIgnoreCase)); } private static IEnumerable GetPlaylistItems(BaseItem i, User user) { var musicGenre = i as MusicGenre; if (musicGenre != null) { var items = user == null ? LibraryManager.RootFolder.GetRecursiveChildren() : user.RootFolder.GetRecursiveChildren(user, true); var songs = items .OfType