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-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;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2016-05-07 02:11:22 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-05-21 07:25:49 +00:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2016-08-13 19:53:20 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 19:10:58 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsInheritedParentImages
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 06:46:59 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsPlayedStatus
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return string.Equals(MediaType, "Video", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 03:04:45 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool AlwaysScanInternalMetadataPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 03:13:38 +00:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsCumulativeRunTimeTicks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 20:06:52 +00:00
|
|
|
|
public override double? GetDefaultPrimaryImageAspectRatio()
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 05:39:07 +00:00
|
|
|
|
public override bool IsAuthorizedToDelete(User user)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 23:17:55 +00:00
|
|
|
|
public override bool IsSaveLocalMetadataEnabled()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:36:32 +00:00
|
|
|
|
protected override List<BaseItem> LoadChildren()
|
2016-08-13 05:49:00 +00:00
|
|
|
|
{
|
|
|
|
|
// Save a trip to the database
|
|
|
|
|
return new List<BaseItem>();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren)
|
2014-08-02 02:34:45 +00:00
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
return GetPlayableItems(user, new DtoOptions(true));
|
2014-08-02 02:34:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-13 19:53:20 +00:00
|
|
|
|
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
|
|
|
|
|
{
|
|
|
|
|
return new List<BaseItem>();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 05:34:10 +00:00
|
|
|
|
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
|
2014-08-03 02:16:37 +00:00
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var items = GetPlayableItems(user, query.DtoOptions);
|
2015-01-25 06:34:50 +00:00
|
|
|
|
|
2016-05-18 05:34:10 +00:00
|
|
|
|
if (query != null)
|
2015-01-25 06:34:50 +00:00
|
|
|
|
{
|
2017-08-10 18:01:31 +00:00
|
|
|
|
items = items.Where(i => UserViewBuilder.FilterItem(i, query)).ToList();
|
2015-01-25 06:34:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
private List<BaseItem> GetPlayableItems(User user, DtoOptions options)
|
2014-08-03 02:16:37 +00:00
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
return GetPlaylistItems(MediaType, base.GetChildren(user, true), user, options);
|
2014-08-03 02:16:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
public static List<BaseItem> GetPlaylistItems(string playlistMediaType, IEnumerable<BaseItem> inputItems, User user, DtoOptions options)
|
2014-08-03 02:16:37 +00:00
|
|
|
|
{
|
2014-08-14 13:24:30 +00:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
inputItems = inputItems.Where(i => i.IsVisible(user));
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 02:11:22 +00:00
|
|
|
|
var list = new List<BaseItem>();
|
|
|
|
|
|
|
|
|
|
foreach (var item in inputItems)
|
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var playlistItems = GetPlaylistItems(item, user, playlistMediaType, options);
|
2016-05-07 02:11:22 +00:00
|
|
|
|
list.AddRange(playlistItems);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
2014-08-19 01:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
private static IEnumerable<BaseItem> GetPlaylistItems(BaseItem item, User user, string mediaType, DtoOptions options)
|
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
|
|
|
|
{
|
2017-04-27 18:12:44 +00:00
|
|
|
|
return LibraryManager.GetItemList(new InternalItemsQuery(user)
|
2016-05-07 17:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name },
|
2017-04-27 18:12:44 +00:00
|
|
|
|
GenreIds = new[] { musicGenre.Id.ToString("N") },
|
2017-09-04 19:28:22 +00:00
|
|
|
|
OrderBy = new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }.Select(i => new Tuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(),
|
2017-05-21 07:25:49 +00:00
|
|
|
|
DtoOptions = options
|
2016-05-07 17:47:41 +00:00
|
|
|
|
});
|
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)
|
|
|
|
|
{
|
2017-04-27 18:12:44 +00:00
|
|
|
|
return LibraryManager.GetItemList(new InternalItemsQuery(user)
|
2015-01-25 06:34:50 +00:00
|
|
|
|
{
|
2017-04-27 18:12:44 +00:00
|
|
|
|
Recursive = true,
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name },
|
|
|
|
|
ArtistIds = new[] { musicArtist.Id.ToString("N") },
|
2017-09-04 19:28:22 +00:00
|
|
|
|
OrderBy = new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }.Select(i => new Tuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(),
|
2017-05-21 07:25:49 +00:00
|
|
|
|
DtoOptions = options
|
2017-04-27 18:12:44 +00:00
|
|
|
|
});
|
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)
|
|
|
|
|
{
|
2016-05-07 02:11:22 +00:00
|
|
|
|
var query = new InternalItemsQuery(user)
|
2015-01-26 16:47:15 +00:00
|
|
|
|
{
|
2016-05-07 02:11:22 +00:00
|
|
|
|
Recursive = true,
|
|
|
|
|
IsFolder = false,
|
2017-09-04 19:28:22 +00:00
|
|
|
|
OrderBy = new[] { ItemSortBy.SortName }.Select(i => new Tuple<string, SortOrder>(i, SortOrder.Ascending)).ToArray(),
|
2016-05-11 02:21:28 +00:00
|
|
|
|
MediaTypes = new[] { mediaType },
|
2017-05-21 07:25:49 +00:00
|
|
|
|
EnableTotalRecordCount = false,
|
|
|
|
|
DtoOptions = options
|
2016-05-07 02:11:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-08-01 16:45:57 +00:00
|
|
|
|
return folder.GetItemList(query);
|
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; }
|
|
|
|
|
|
2015-11-13 02:49:47 +00:00
|
|
|
|
[IgnoreDataMember]
|
2014-08-03 02:16:37 +00:00
|
|
|
|
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
|
|
|
|
{
|
2016-10-11 21:33:38 +00:00
|
|
|
|
var userId = user.Id.ToString("N");
|
2014-12-13 03:56:30 +00:00
|
|
|
|
|
2016-10-11 21:33:38 +00:00
|
|
|
|
return Shares.Any(i => string.Equals(userId, i.UserId, StringComparison.OrdinalIgnoreCase)) ||
|
|
|
|
|
string.Equals(OwnerUserId, userId, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
2014-12-13 03:56:30 +00:00
|
|
|
|
|
2016-10-11 21:33:38 +00:00
|
|
|
|
public override bool IsVisibleStandalone(User user)
|
|
|
|
|
{
|
|
|
|
|
return IsVisible(user);
|
2014-08-02 02:34:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|