2014-08-02 04:34:45 +02:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-08-19 03:42:53 +02:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-08-03 04:16:37 +02:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
|
using System;
|
2014-08-02 04:34:45 +02:00
|
|
|
|
using System.Collections.Generic;
|
2014-08-03 04:16:37 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
2016-05-07 04:11:22 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2014-08-02 04:34:45 +02:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Playlists
|
|
|
|
|
{
|
2014-12-13 04:56:30 +01:00
|
|
|
|
public class Playlist : Folder, IHasShares
|
2014-08-02 04:34:45 +02:00
|
|
|
|
{
|
2014-08-03 04:16:37 +02:00
|
|
|
|
public string OwnerUserId { get; set; }
|
2014-08-02 04:34:45 +02:00
|
|
|
|
|
2014-12-13 04:56:30 +01:00
|
|
|
|
public List<Share> Shares { get; set; }
|
|
|
|
|
|
|
|
|
|
public Playlist()
|
|
|
|
|
{
|
|
|
|
|
Shares = new List<Share>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 05:04:45 +02:00
|
|
|
|
[IgnoreDataMember]
|
2014-08-14 15:24:30 +02:00
|
|
|
|
protected override bool FilterLinkedChildrenPerUser
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 05:04:45 +02:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool AlwaysScanInternalMetadataPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 06:39:07 +01:00
|
|
|
|
public override bool IsAuthorizedToDelete(User user)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 00:17:55 +01:00
|
|
|
|
public override bool IsSaveLocalMetadataEnabled()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-03 04:16:37 +02:00
|
|
|
|
public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
|
2014-08-02 04:34:45 +02:00
|
|
|
|
{
|
2016-05-07 04:11:22 +02:00
|
|
|
|
return GetPlayableItems(user).Result;
|
2014-08-02 04:34:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem, bool> filter)
|
2014-08-03 04:16:37 +02:00
|
|
|
|
{
|
2016-05-07 04:11:22 +02:00
|
|
|
|
var items = GetPlayableItems(user).Result;
|
2015-01-25 07:34:50 +01:00
|
|
|
|
|
|
|
|
|
if (filter != null)
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items;
|
2014-08-03 04:16:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 01:41:11 +02:00
|
|
|
|
public IEnumerable<Tuple<LinkedChild, BaseItem>> GetManageableItems()
|
2014-08-03 04:16:37 +02:00
|
|
|
|
{
|
2014-08-12 01:41:11 +02:00
|
|
|
|
return GetLinkedChildrenInfos();
|
2014-08-03 04:16:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 04:11:22 +02:00
|
|
|
|
private Task<IEnumerable<BaseItem>> GetPlayableItems(User user)
|
2014-08-03 04:16:37 +02:00
|
|
|
|
{
|
|
|
|
|
return GetPlaylistItems(MediaType, base.GetChildren(user, true), user);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 04:11:22 +02:00
|
|
|
|
public static async Task<IEnumerable<BaseItem>> GetPlaylistItems(string playlistMediaType, IEnumerable<BaseItem> inputItems, User user)
|
2014-08-03 04:16:37 +02:00
|
|
|
|
{
|
2014-08-14 15:24:30 +02:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
inputItems = inputItems.Where(i => i.IsVisible(user));
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 04:11:22 +02:00
|
|
|
|
var list = new List<BaseItem>();
|
|
|
|
|
|
|
|
|
|
foreach (var item in inputItems)
|
|
|
|
|
{
|
|
|
|
|
var playlistItems = await GetPlaylistItems(item, user, playlistMediaType).ConfigureAwait(false);
|
|
|
|
|
list.AddRange(playlistItems);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
2014-08-19 03:42:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 04:11:22 +02:00
|
|
|
|
private static async Task<IEnumerable<BaseItem>> GetPlaylistItems(BaseItem item, User user, string mediaType)
|
2014-08-19 03:42:53 +02:00
|
|
|
|
{
|
2015-01-25 07:34:50 +01:00
|
|
|
|
var musicGenre = item as MusicGenre;
|
2014-08-19 03:42:53 +02:00
|
|
|
|
if (musicGenre != null)
|
2014-08-03 04:16:37 +02:00
|
|
|
|
{
|
2015-01-25 07:34:50 +01:00
|
|
|
|
Func<BaseItem, bool> filter = i => i is Audio && i.Genres.Contains(musicGenre.Name, StringComparer.OrdinalIgnoreCase);
|
2014-08-22 04:24:38 +02:00
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
var items = user == null
|
|
|
|
|
? LibraryManager.RootFolder.GetRecursiveChildren(filter)
|
|
|
|
|
: user.RootFolder.GetRecursiveChildren(user, filter);
|
2014-08-03 04:16:37 +02:00
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
return LibraryManager.Sort(items, user, new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }, SortOrder.Ascending);
|
2014-08-19 03:42:53 +02:00
|
|
|
|
}
|
2014-08-07 04:51:09 +02:00
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
var musicArtist = item as MusicArtist;
|
2014-08-19 03:42:53 +02:00
|
|
|
|
if (musicArtist != null)
|
|
|
|
|
{
|
2015-01-25 07:34:50 +01:00
|
|
|
|
Func<BaseItem, bool> filter = i =>
|
|
|
|
|
{
|
|
|
|
|
var audio = i as Audio;
|
2015-03-13 18:25:28 +01:00
|
|
|
|
return audio != null && audio.HasAnyArtist(musicArtist.Name);
|
2015-01-25 07:34:50 +01:00
|
|
|
|
};
|
2014-08-22 04:24:38 +02:00
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
var items = user == null
|
|
|
|
|
? LibraryManager.RootFolder.GetRecursiveChildren(filter)
|
|
|
|
|
: user.RootFolder.GetRecursiveChildren(user, filter);
|
2014-08-03 04:16:37 +02:00
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
return LibraryManager.Sort(items, user, new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }, SortOrder.Ascending);
|
2014-08-19 03:42:53 +02:00
|
|
|
|
}
|
2014-08-22 04:24:38 +02:00
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
var folder = item as Folder;
|
2014-08-19 03:42:53 +02:00
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
2016-05-07 04:11:22 +02:00
|
|
|
|
var query = new InternalItemsQuery(user)
|
2015-01-26 17:47:15 +01:00
|
|
|
|
{
|
2016-05-07 04:11:22 +02:00
|
|
|
|
Recursive = true,
|
|
|
|
|
IsFolder = false,
|
|
|
|
|
SortBy = new[] { ItemSortBy.SortName },
|
|
|
|
|
MediaTypes = new[] { mediaType }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var itemsResult = await folder.GetItems(query).ConfigureAwait(false);
|
|
|
|
|
var items = itemsResult.Items;
|
|
|
|
|
|
|
|
|
|
return items;
|
2014-08-19 03:42:53 +02:00
|
|
|
|
}
|
2014-08-14 15:24:30 +02:00
|
|
|
|
|
2015-01-25 07:34:50 +01:00
|
|
|
|
return new[] { item };
|
2014-08-03 04:16:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool IsPreSorted
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string PlaylistMediaType { get; set; }
|
|
|
|
|
|
2015-11-13 03:49:47 +01:00
|
|
|
|
[IgnoreDataMember]
|
2014-08-03 04:16:37 +02:00
|
|
|
|
public override string MediaType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return PlaylistMediaType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMediaType(string value)
|
|
|
|
|
{
|
|
|
|
|
PlaylistMediaType = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsVisible(User user)
|
2014-08-02 04:34:45 +02:00
|
|
|
|
{
|
2014-12-13 04:56:30 +01: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 04:34:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|