2014-08-02 02:34:45 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-08-19 01:42:53 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-08-24 15:48:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-08-03 02:16:37 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
|
using System;
|
2014-08-02 02:34:45 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-08-03 02:16:37 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
2014-08-02 02:34:45 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Playlists
|
|
|
|
|
{
|
2014-12-13 03:56:30 +00:00
|
|
|
|
public class Playlist : Folder, IHasShares
|
2014-08-02 02:34:45 +00:00
|
|
|
|
{
|
2014-08-03 02:16:37 +00:00
|
|
|
|
public string OwnerUserId { get; set; }
|
2014-08-02 02:34:45 +00:00
|
|
|
|
|
2014-12-13 03:56:30 +00:00
|
|
|
|
public List<Share> Shares { get; set; }
|
|
|
|
|
|
|
|
|
|
public Playlist()
|
|
|
|
|
{
|
|
|
|
|
Shares = new List<Share>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 03:04:45 +00:00
|
|
|
|
[IgnoreDataMember]
|
2014-08-14 13:24:30 +00:00
|
|
|
|
protected override bool FilterLinkedChildrenPerUser
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 03:04:45 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool AlwaysScanInternalMetadataPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 23:17:55 +00:00
|
|
|
|
public override bool IsSaveLocalMetadataEnabled()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-03 02:16:37 +00:00
|
|
|
|
public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
|
2014-08-02 02:34:45 +00:00
|
|
|
|
{
|
2014-08-03 02:16:37 +00:00
|
|
|
|
return GetPlayableItems(user);
|
2014-08-02 02:34:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem, bool> filter)
|
2014-08-03 02:16:37 +00:00
|
|
|
|
{
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var items = GetPlayableItems(user);
|
|
|
|
|
|
|
|
|
|
if (filter != null)
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items;
|
2014-08-03 02:16:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-11 23:41:11 +00:00
|
|
|
|
public IEnumerable<Tuple<LinkedChild, BaseItem>> GetManageableItems()
|
2014-08-03 02:16:37 +00:00
|
|
|
|
{
|
2014-08-11 23:41:11 +00:00
|
|
|
|
return GetLinkedChildrenInfos();
|
2014-08-03 02:16:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2014-08-14 13:24:30 +00:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
inputItems = inputItems.Where(i => i.IsVisible(user));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 01:42:53 +00:00
|
|
|
|
return inputItems.SelectMany(i => GetPlaylistItems(i, user))
|
2014-08-22 02:24:38 +00:00
|
|
|
|
.Where(m => string.Equals(m.MediaType, playlistMediaType, StringComparison.OrdinalIgnoreCase));
|
2014-08-19 01:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
private static IEnumerable<BaseItem> GetPlaylistItems(BaseItem item, User user)
|
2014-08-19 01:42:53 +00:00
|
|
|
|
{
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var musicGenre = item as MusicGenre;
|
2014-08-19 01:42:53 +00:00
|
|
|
|
if (musicGenre != null)
|
2014-08-03 02:16:37 +00:00
|
|
|
|
{
|
2015-01-25 06:34:50 +00:00
|
|
|
|
Func<BaseItem, bool> filter = i => i is Audio && i.Genres.Contains(musicGenre.Name, StringComparer.OrdinalIgnoreCase);
|
2014-08-22 02:24:38 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var items = user == null
|
|
|
|
|
? LibraryManager.RootFolder.GetRecursiveChildren(filter)
|
|
|
|
|
: user.RootFolder.GetRecursiveChildren(user, filter);
|
2014-08-03 02:16:37 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
return LibraryManager.Sort(items, user, new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }, SortOrder.Ascending);
|
2014-08-19 01:42:53 +00:00
|
|
|
|
}
|
2014-08-07 02:51:09 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var musicArtist = item as MusicArtist;
|
2014-08-19 01:42:53 +00:00
|
|
|
|
if (musicArtist != null)
|
|
|
|
|
{
|
2015-01-25 06:34:50 +00:00
|
|
|
|
Func<BaseItem, bool> filter = i =>
|
|
|
|
|
{
|
|
|
|
|
var audio = i as Audio;
|
|
|
|
|
return audio != null && audio.HasArtist(musicArtist.Name);
|
|
|
|
|
};
|
2014-08-22 02:24:38 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var items = user == null
|
|
|
|
|
? LibraryManager.RootFolder.GetRecursiveChildren(filter)
|
|
|
|
|
: user.RootFolder.GetRecursiveChildren(user, filter);
|
2014-08-03 02:16:37 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
return LibraryManager.Sort(items, user, new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }, SortOrder.Ascending);
|
2014-08-19 01:42:53 +00:00
|
|
|
|
}
|
2014-08-22 02:24:38 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var folder = item as Folder;
|
2014-08-19 01:42:53 +00:00
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
|
|
|
|
var items = user == null
|
2015-01-25 06:34:50 +00:00
|
|
|
|
? folder.GetRecursiveChildren(m => !m.IsFolder)
|
|
|
|
|
: folder.GetRecursiveChildren(user, m => !m.IsFolder);
|
2014-08-03 02:16:37 +00:00
|
|
|
|
|
2015-01-26 16:47:15 +00:00
|
|
|
|
if (folder.IsPreSorted)
|
|
|
|
|
{
|
|
|
|
|
return items;
|
|
|
|
|
}
|
2014-08-24 15:48:06 +00:00
|
|
|
|
return LibraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending);
|
2014-08-19 01:42:53 +00:00
|
|
|
|
}
|
2014-08-14 13:24:30 +00:00
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
return new[] { item };
|
2014-08-03 02:16:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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)
|
2014-08-02 02:34:45 +00:00
|
|
|
|
{
|
2014-12-13 03:56:30 +00:00
|
|
|
|
if (base.IsVisible(user))
|
|
|
|
|
{
|
|
|
|
|
var userId = user.Id.ToString("N");
|
|
|
|
|
|
|
|
|
|
return Shares.Any(i => string.Equals(userId, i.UserId, StringComparison.OrdinalIgnoreCase)) ||
|
|
|
|
|
string.Equals(OwnerUserId, userId, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2014-08-02 02:34:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|