2014-10-29 22:01:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Channels;
|
2014-09-01 20:10:54 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2015-03-14 04:50:23 +00:00
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
2014-09-01 20:10:54 +00:00
|
|
|
|
using MediaBrowser.Controller.TV;
|
|
|
|
|
using MediaBrowser.Model.Channels;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.LiveTv;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-06-05 19:44:55 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2016-07-01 15:51:35 +00:00
|
|
|
|
using MoreLinq;
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
|
|
|
|
public class UserViewBuilder
|
|
|
|
|
{
|
|
|
|
|
private readonly IChannelManager _channelManager;
|
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IUserDataManager _userDataManager;
|
|
|
|
|
private readonly ITVSeriesManager _tvSeriesManager;
|
2016-06-05 19:44:55 +00:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2015-03-14 04:50:23 +00:00
|
|
|
|
private readonly IPlaylistManager _playlistManager;
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2016-06-05 19:44:55 +00:00
|
|
|
|
public UserViewBuilder(IUserViewManager userViewManager, ILiveTvManager liveTvManager, IChannelManager channelManager, ILibraryManager libraryManager, ILogger logger, IUserDataManager userDataManager, ITVSeriesManager tvSeriesManager, IServerConfigurationManager config, IPlaylistManager playlistManager)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
|
_channelManager = channelManager;
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_userDataManager = userDataManager;
|
|
|
|
|
_tvSeriesManager = tvSeriesManager;
|
2016-06-05 19:44:55 +00:00
|
|
|
|
_config = config;
|
2015-03-14 04:50:23 +00:00
|
|
|
|
_playlistManager = playlistManager;
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
public async Task<QueryResult<BaseItem>> GetUserItems(Folder queryParent, Folder displayParent, string viewType, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
var user = query.User;
|
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
//if (query.IncludeItemTypes != null &&
|
|
|
|
|
// query.IncludeItemTypes.Length == 1 &&
|
|
|
|
|
// string.Equals(query.IncludeItemTypes[0], "Playlist", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
//{
|
|
|
|
|
// if (!string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
// {
|
|
|
|
|
// return await FindPlaylists(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2015-04-12 18:58:21 +00:00
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
switch (viewType)
|
|
|
|
|
{
|
|
|
|
|
case CollectionType.Channels:
|
|
|
|
|
{
|
|
|
|
|
var result = await _channelManager.GetChannelsInternal(new ChannelQuery
|
|
|
|
|
{
|
2015-07-27 05:03:34 +00:00
|
|
|
|
UserId = user == null ? null : user.Id.ToString("N"),
|
2014-09-01 20:10:54 +00:00
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
StartIndex = query.StartIndex
|
|
|
|
|
|
|
|
|
|
}, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return GetResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.LiveTvChannels:
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
var result = await _liveTvManager.GetInternalChannels(new LiveTvChannelQuery
|
|
|
|
|
{
|
|
|
|
|
UserId = query.User.Id.ToString("N"),
|
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
StartIndex = query.StartIndex
|
|
|
|
|
|
|
|
|
|
}, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return GetResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.LiveTvNowPlaying:
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
var result = await _liveTvManager.GetRecommendedProgramsInternal(new RecommendedProgramQuery
|
|
|
|
|
{
|
|
|
|
|
UserId = query.User.Id.ToString("N"),
|
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
IsAiring = true
|
|
|
|
|
|
|
|
|
|
}, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return GetResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.LiveTvRecordingGroups:
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
var result = await _liveTvManager.GetInternalRecordings(new RecordingQuery
|
|
|
|
|
{
|
|
|
|
|
UserId = query.User.Id.ToString("N"),
|
|
|
|
|
Status = RecordingStatus.Completed,
|
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
StartIndex = query.StartIndex
|
|
|
|
|
|
|
|
|
|
}, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return GetResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CollectionType.LiveTv:
|
|
|
|
|
{
|
2015-04-13 05:12:02 +00:00
|
|
|
|
return await GetLiveTvView(queryParent, user, query).ConfigureAwait(false);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-02 17:25:01 +00:00
|
|
|
|
case CollectionType.Photos:
|
2015-03-16 03:41:12 +00:00
|
|
|
|
case CollectionType.Books:
|
|
|
|
|
case CollectionType.HomeVideos:
|
2015-11-02 17:25:01 +00:00
|
|
|
|
case CollectionType.Games:
|
2015-03-18 16:40:16 +00:00
|
|
|
|
case CollectionType.MusicVideos:
|
2015-11-09 18:18:37 +00:00
|
|
|
|
{
|
2016-05-15 19:25:54 +00:00
|
|
|
|
if (query.Recursive)
|
|
|
|
|
{
|
2016-05-18 05:34:10 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = queryParent.Id;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2016-05-15 19:25:54 +00:00
|
|
|
|
}
|
|
|
|
|
return GetResult(queryParent.GetChildren(user, true), queryParent, query);
|
2015-11-09 18:18:37 +00:00
|
|
|
|
}
|
2015-03-16 03:41:12 +00:00
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
case CollectionType.Folders:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetResult(user.RootFolder.GetChildren(user, true), queryParent, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
case CollectionType.Playlists:
|
|
|
|
|
return await GetPlaylistsView(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
case CollectionType.BoxSets:
|
2016-05-15 19:25:54 +00:00
|
|
|
|
return GetBoxsetView(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
|
|
|
|
case CollectionType.TvShows:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return await GetTvView(queryParent, user, query).ConfigureAwait(false);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
|
|
|
|
case CollectionType.Movies:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return await GetMovieFolders(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.TvShowSeries:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetTvSeries(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.TvGenres:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return await GetTvGenres(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.TvGenre:
|
2016-06-05 19:44:55 +00:00
|
|
|
|
return GetTvGenreItems(queryParent, displayParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.TvResume:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetTvResume(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.TvNextUp:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetTvNextUp(queryParent, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.TvLatest:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetTvLatest(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.MovieFavorites:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetFavoriteMovies(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.MovieLatest:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetMovieLatest(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.MovieGenres:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return await GetMovieGenres(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MovieGenre:
|
|
|
|
|
return await GetMovieGenreItems(queryParent, displayParent, user, query).ConfigureAwait(false);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.MovieResume:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetMovieResume(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.MovieMovies:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetMovieMovies(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.MovieCollections:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetMovieCollections(queryParent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.TvFavoriteEpisodes:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetFavoriteEpisodes(queryParent, user, query);
|
2014-09-06 04:21:23 +00:00
|
|
|
|
|
2014-10-29 22:01:02 +00:00
|
|
|
|
case SpecialFolder.TvFavoriteSeries:
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return GetFavoriteSeries(queryParent, user, query);
|
2014-09-06 04:21:23 +00:00
|
|
|
|
|
2015-11-17 17:38:31 +00:00
|
|
|
|
case CollectionType.Music:
|
|
|
|
|
return await GetMusicFolders(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicGenres:
|
|
|
|
|
return await GetMusicGenres(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicGenre:
|
|
|
|
|
return await GetMusicGenreItems(queryParent, displayParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicLatest:
|
|
|
|
|
return GetMusicLatest(queryParent, user, query);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicPlaylists:
|
2016-05-15 19:25:54 +00:00
|
|
|
|
return GetMusicPlaylists(queryParent, user, query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicAlbums:
|
|
|
|
|
return GetMusicAlbums(queryParent, user, query);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicAlbumArtists:
|
|
|
|
|
return GetMusicAlbumArtists(queryParent, user, query);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicArtists:
|
|
|
|
|
return GetMusicArtists(queryParent, user, query);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicSongs:
|
|
|
|
|
return GetMusicSongs(queryParent, user, query);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicFavorites:
|
|
|
|
|
return await GetMusicFavorites(queryParent, user, query).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicFavoriteAlbums:
|
|
|
|
|
return GetFavoriteAlbums(queryParent, user, query);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicFavoriteArtists:
|
|
|
|
|
return GetFavoriteArtists(queryParent, user, query);
|
|
|
|
|
|
|
|
|
|
case SpecialFolder.MusicFavoriteSongs:
|
|
|
|
|
return GetFavoriteSongs(queryParent, user, query);
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
default:
|
2015-04-15 21:59:20 +00:00
|
|
|
|
{
|
2015-04-19 15:54:20 +00:00
|
|
|
|
if (queryParent is UserView)
|
|
|
|
|
{
|
|
|
|
|
return GetResult(GetMediaFolders(user).SelectMany(i => i.GetChildren(user, true)), queryParent, query);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return GetResult(queryParent.GetChildren(user, true), queryParent, query);
|
|
|
|
|
}
|
2015-04-15 21:59:20 +00:00
|
|
|
|
}
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 17:38:31 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetMusicFolders(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
if (query.Recursive)
|
|
|
|
|
{
|
2016-05-16 18:20:08 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
if (query.IncludeItemTypes.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(MusicArtist).Name, typeof(MusicAlbum).Name, typeof(Audio.Audio).Name, typeof(MusicVideo).Name };
|
|
|
|
|
}
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-05-17 20:16:30 +00:00
|
|
|
|
return parent.QueryRecursive(query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = new List<BaseItem>();
|
|
|
|
|
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicLatest, "0", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicPlaylists, "1", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicAlbums, "2", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicAlbumArtists, "3", parent).ConfigureAwait(false));
|
2015-12-30 19:52:06 +00:00
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicArtists, "4", parent).ConfigureAwait(false));
|
2015-11-17 17:38:31 +00:00
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicSongs, "5", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicGenres, "6", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicFavorites, "7", parent).ConfigureAwait(false));
|
|
|
|
|
|
|
|
|
|
return GetResult(list, parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<QueryResult<BaseItem>> GetMusicFavorites(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<BaseItem>();
|
|
|
|
|
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicFavoriteAlbums, "0", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicFavoriteArtists, "1", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MusicFavoriteSongs, "2", parent).ConfigureAwait(false));
|
|
|
|
|
|
|
|
|
|
return GetResult(list, parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<QueryResult<BaseItem>> GetMusicGenres(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var tasks = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos })
|
|
|
|
|
.Where(i => !i.IsFolder)
|
|
|
|
|
.SelectMany(i => i.Genres)
|
|
|
|
|
.DistinctNames()
|
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetMusicGenre(i);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Full exception logged at lower levels
|
|
|
|
|
_logger.Error("Error getting genre");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.Select(i => GetUserView(i.Name, SpecialFolder.MusicGenre, i.SortName, parent));
|
|
|
|
|
|
|
|
|
|
var genres = await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return GetResult(genres, parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<QueryResult<BaseItem>> GetMusicGenreItems(Folder queryParent, Folder displayParent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = queryParent.Id;
|
|
|
|
|
query.Genres = new[] { displayParent.Name };
|
|
|
|
|
query.SetUser(user);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(MusicAlbum).Name };
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetMusicAlbumArtists(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-27 03:46:31 +00:00
|
|
|
|
var items = parent.QueryRecursive(new InternalItemsQuery(user)
|
2016-05-18 05:34:10 +00:00
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
ParentId = parent.Id,
|
2016-05-27 03:46:31 +00:00
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio.Audio).Name },
|
|
|
|
|
EnableTotalRecordCount = false
|
2016-05-18 05:34:10 +00:00
|
|
|
|
|
2016-05-27 03:46:31 +00:00
|
|
|
|
}).Items.Cast<IHasAlbumArtist>();
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
|
|
|
|
var artists = _libraryManager.GetAlbumArtists(items);
|
|
|
|
|
|
|
|
|
|
return GetResult(artists, parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetMusicArtists(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-27 03:46:31 +00:00
|
|
|
|
var items = parent.QueryRecursive(new InternalItemsQuery(user)
|
2016-05-18 05:34:10 +00:00
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
ParentId = parent.Id,
|
2016-05-27 03:46:31 +00:00
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio.Audio).Name, typeof(MusicVideo).Name },
|
|
|
|
|
EnableTotalRecordCount = false
|
2016-05-18 05:34:10 +00:00
|
|
|
|
|
2016-05-27 03:46:31 +00:00
|
|
|
|
}).Items.Cast<IHasArtist>();
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
|
|
|
|
var artists = _libraryManager.GetArtists(items);
|
|
|
|
|
|
|
|
|
|
return GetResult(artists, parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetFavoriteArtists(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-27 03:46:31 +00:00
|
|
|
|
var items = parent.QueryRecursive(new InternalItemsQuery(user)
|
2016-05-18 05:34:10 +00:00
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
ParentId = parent.Id,
|
2016-05-27 03:46:31 +00:00
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio.Audio).Name },
|
|
|
|
|
EnableTotalRecordCount = false
|
2016-05-18 05:34:10 +00:00
|
|
|
|
|
2016-05-27 03:46:31 +00:00
|
|
|
|
}).Items.Cast<IHasAlbumArtist>();
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-04-30 22:05:13 +00:00
|
|
|
|
var artists = _libraryManager.GetAlbumArtists(items).Where(i => _userDataManager.GetUserData(user, i).IsFavorite);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
|
|
|
|
return GetResult(artists, parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:25:54 +00:00
|
|
|
|
private QueryResult<BaseItem> GetMusicPlaylists(Folder parent, User user, InternalItemsQuery query)
|
2015-11-17 17:38:31 +00:00
|
|
|
|
{
|
2016-05-15 19:25:54 +00:00
|
|
|
|
query.ParentId = null;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Playlist).Name };
|
|
|
|
|
query.SetUser(user);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
|
2016-05-15 19:25:54 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetMusicAlbums(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(MusicAlbum).Name };
|
|
|
|
|
|
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetMusicSongs(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Audio.Audio).Name };
|
|
|
|
|
|
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetMusicLatest(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var items = _userViewManager.GetLatestItems(new LatestItemsQuery
|
|
|
|
|
{
|
|
|
|
|
UserId = user.Id.ToString("N"),
|
|
|
|
|
Limit = GetSpecialItemsLimit(),
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio.Audio).Name },
|
2016-03-27 21:11:27 +00:00
|
|
|
|
ParentId = parent == null ? null : parent.Id.ToString("N"),
|
2015-11-17 17:38:31 +00:00
|
|
|
|
GroupItems = true
|
|
|
|
|
|
|
|
|
|
}).Select(i => i.Item1 ?? i.Item2.FirstOrDefault()).Where(i => i != null);
|
|
|
|
|
|
|
|
|
|
query.SortBy = new string[] { };
|
|
|
|
|
|
|
|
|
|
return PostFilterAndSort(items, parent, null, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetFavoriteSongs(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
query.IsFavorite = true;
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Audio.Audio).Name };
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetFavoriteAlbums(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
query.IsFavorite = true;
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(MusicAlbum).Name };
|
2015-11-17 17:38:31 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2015-11-17 17:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 18:58:21 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> FindPlaylists(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2015-07-29 20:31:15 +00:00
|
|
|
|
var list = _playlistManager.GetPlaylists(user.Id.ToString("N"));
|
2015-04-12 18:58:21 +00:00
|
|
|
|
|
|
|
|
|
return GetResult(list, parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
private int GetSpecialItemsLimit()
|
|
|
|
|
{
|
|
|
|
|
return 50;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetMovieFolders(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (query.Recursive)
|
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.SetUser(user);
|
2015-01-24 22:33:26 +00:00
|
|
|
|
|
2016-05-16 17:11:49 +00:00
|
|
|
|
if (query.IncludeItemTypes.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name, typeof(BoxSet).Name };
|
|
|
|
|
}
|
2015-01-24 22:33:26 +00:00
|
|
|
|
|
2016-05-17 20:16:30 +00:00
|
|
|
|
return parent.QueryRecursive(query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = new List<BaseItem>();
|
|
|
|
|
|
2015-08-14 18:00:26 +00:00
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MovieResume, "0", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MovieLatest, "1", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MovieMovies, "2", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MovieCollections, "3", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MovieFavorites, "4", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.MovieGenres, "5", parent).ConfigureAwait(false));
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
return GetResult(list, parent, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetFavoriteMovies(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
query.IsFavorite = true;
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name };
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetFavoriteSeries(Folder parent, User user, InternalItemsQuery query)
|
2014-09-06 04:21:23 +00:00
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2014-09-06 04:21:23 +00:00
|
|
|
|
query.IsFavorite = true;
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Series).Name };
|
2014-09-06 04:21:23 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2014-09-06 04:21:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetFavoriteEpisodes(Folder parent, User user, InternalItemsQuery query)
|
2014-09-06 04:21:23 +00:00
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2014-09-06 04:21:23 +00:00
|
|
|
|
query.IsFavorite = true;
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Episode).Name };
|
2014-09-06 04:21:23 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2014-09-06 04:21:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetMovieMovies(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2015-01-25 19:13:04 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name };
|
|
|
|
|
|
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetMovieCollections(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return GetBoxsetView(parent, user, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetMovieLatest(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
query.SortBy = new[] { ItemSortBy.DateCreated, ItemSortBy.SortName };
|
|
|
|
|
query.SortOrder = SortOrder.Descending;
|
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.Limit = GetSpecialItemsLimit();
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name };
|
2015-01-25 06:34:50 +00:00
|
|
|
|
|
2016-06-30 14:50:08 +00:00
|
|
|
|
return ConvertToResult(_libraryManager.GetItemList(query));
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetMovieResume(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
query.SortBy = new[] { ItemSortBy.DatePlayed, ItemSortBy.SortName };
|
|
|
|
|
query.SortOrder = SortOrder.Descending;
|
|
|
|
|
query.IsResumable = true;
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.Limit = GetSpecialItemsLimit();
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name };
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2016-06-30 14:50:08 +00:00
|
|
|
|
return ConvertToResult(_libraryManager.GetItemList(query));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> ConvertToResult(IEnumerable<BaseItem> items)
|
|
|
|
|
{
|
|
|
|
|
var arr = items.ToArray();
|
|
|
|
|
return new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
Items = arr,
|
|
|
|
|
TotalRecordCount = arr.Length
|
|
|
|
|
};
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
2014-09-05 03:48:53 +00:00
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetMovieGenres(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-05-16 18:20:08 +00:00
|
|
|
|
var tasks = parent.QueryRecursive(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Movie).Name },
|
|
|
|
|
Recursive = true,
|
|
|
|
|
EnableTotalRecordCount = false
|
|
|
|
|
|
|
|
|
|
}).Items
|
2014-09-01 20:10:54 +00:00
|
|
|
|
.SelectMany(i => i.Genres)
|
2015-04-09 21:11:57 +00:00
|
|
|
|
.DistinctNames()
|
2014-09-01 20:10:54 +00:00
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetGenre(i);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Full exception logged at lower levels
|
|
|
|
|
_logger.Error("Error getting genre");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
2014-11-11 03:41:55 +00:00
|
|
|
|
.Where(i => i != null)
|
2015-08-14 18:00:26 +00:00
|
|
|
|
.Select(i => GetUserView(i.Name, SpecialFolder.MovieGenre, i.SortName, parent));
|
2014-11-11 03:41:55 +00:00
|
|
|
|
|
|
|
|
|
var genres = await Task.WhenAll(tasks).ConfigureAwait(false);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
return GetResult(genres, parent, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetMovieGenreItems(Folder queryParent, Folder displayParent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = queryParent.Id;
|
|
|
|
|
query.Genres = new[] { displayParent.Name };
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name };
|
2014-11-11 03:41:55 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2014-11-11 03:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetPlaylistsView(Folder parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
return GetResult(_playlistManager.GetPlaylists(user.Id.ToString("N")), parent, query);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:25:54 +00:00
|
|
|
|
private QueryResult<BaseItem> GetBoxsetView(Folder parent, User user, InternalItemsQuery query)
|
2015-01-24 04:50:45 +00:00
|
|
|
|
{
|
2016-05-15 19:25:54 +00:00
|
|
|
|
query.ParentId = null;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(BoxSet).Name };
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.Recursive = true;
|
2015-01-24 04:50:45 +00:00
|
|
|
|
|
2016-05-15 19:25:54 +00:00
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2015-01-24 04:50:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetTvView(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (query.Recursive)
|
|
|
|
|
{
|
2016-05-15 19:55:17 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.SetUser(user);
|
2015-01-25 19:13:04 +00:00
|
|
|
|
|
2016-05-16 17:11:49 +00:00
|
|
|
|
if (query.IncludeItemTypes.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Series).Name, typeof(Season).Name, typeof(Episode).Name };
|
|
|
|
|
}
|
2016-05-15 19:55:17 +00:00
|
|
|
|
|
2016-05-17 20:16:30 +00:00
|
|
|
|
return parent.QueryRecursive(query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = new List<BaseItem>();
|
|
|
|
|
|
2015-08-14 18:00:26 +00:00
|
|
|
|
list.Add(await GetUserView(SpecialFolder.TvResume, "0", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.TvNextUp, "1", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.TvLatest, "2", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.TvShowSeries, "3", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.TvFavoriteSeries, "4", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.TvFavoriteEpisodes, "5", parent).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.TvGenres, "6", parent).ConfigureAwait(false));
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
return GetResult(list, parent, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetTvLatest(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
query.SortBy = new[] { ItemSortBy.DateCreated, ItemSortBy.SortName };
|
|
|
|
|
query.SortOrder = SortOrder.Descending;
|
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.Limit = GetSpecialItemsLimit();
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Episode).Name };
|
2016-06-11 17:10:06 +00:00
|
|
|
|
query.ExcludeLocationTypes = new[] { LocationType.Virtual };
|
2015-01-25 06:34:50 +00:00
|
|
|
|
|
2016-06-30 14:50:08 +00:00
|
|
|
|
return ConvertToResult(_libraryManager.GetItemList(query));
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetTvNextUp(Folder parent, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
var parentFolders = GetMediaFolders(parent, query.User, new[] { CollectionType.TvShows, string.Empty });
|
2014-09-05 03:48:53 +00:00
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
var result = _tvSeriesManager.GetNextUp(new NextUpQuery
|
|
|
|
|
{
|
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
UserId = query.User.Id.ToString("N")
|
|
|
|
|
|
|
|
|
|
}, parentFolders);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetTvResume(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
query.SortBy = new[] { ItemSortBy.DatePlayed, ItemSortBy.SortName };
|
|
|
|
|
query.SortOrder = SortOrder.Descending;
|
|
|
|
|
query.IsResumable = true;
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.Limit = GetSpecialItemsLimit();
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Episode).Name };
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2016-06-30 14:50:08 +00:00
|
|
|
|
return ConvertToResult(_libraryManager.GetItemList(query));
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
private QueryResult<BaseItem> GetTvSeries(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = parent.Id;
|
|
|
|
|
query.SetUser(user);
|
2015-01-25 19:13:04 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Series).Name };
|
|
|
|
|
|
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetTvGenres(Folder parent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-05-16 18:20:08 +00:00
|
|
|
|
var tasks = parent.QueryRecursive(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Series).Name },
|
|
|
|
|
Recursive = true,
|
|
|
|
|
EnableTotalRecordCount = false
|
|
|
|
|
|
|
|
|
|
}).Items
|
2014-09-01 20:10:54 +00:00
|
|
|
|
.SelectMany(i => i.Genres)
|
2015-04-09 21:11:57 +00:00
|
|
|
|
.DistinctNames()
|
2014-09-01 20:10:54 +00:00
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetGenre(i);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Full exception logged at lower levels
|
|
|
|
|
_logger.Error("Error getting genre");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
2014-11-11 03:41:55 +00:00
|
|
|
|
.Where(i => i != null)
|
2015-08-14 18:00:26 +00:00
|
|
|
|
.Select(i => GetUserView(i.Name, SpecialFolder.TvGenre, i.SortName, parent));
|
2014-11-11 03:41:55 +00:00
|
|
|
|
|
|
|
|
|
var genres = await Task.WhenAll(tasks).ConfigureAwait(false);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
return GetResult(genres, parent, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 19:44:55 +00:00
|
|
|
|
private QueryResult<BaseItem> GetTvGenreItems(Folder queryParent, Folder displayParent, User user, InternalItemsQuery query)
|
2014-11-11 03:41:55 +00:00
|
|
|
|
{
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.ParentId = queryParent.Id;
|
|
|
|
|
query.Genres = new[] { displayParent.Name };
|
|
|
|
|
query.SetUser(user);
|
2014-11-11 03:41:55 +00:00
|
|
|
|
|
2016-05-15 19:49:50 +00:00
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Series).Name };
|
|
|
|
|
|
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
2014-11-11 03:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
private QueryResult<BaseItem> GetResult<T>(QueryResult<T> result)
|
|
|
|
|
where T : BaseItem
|
|
|
|
|
{
|
|
|
|
|
return new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
Items = result.Items,
|
|
|
|
|
TotalRecordCount = result.TotalRecordCount
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetResult<T>(IEnumerable<T> items,
|
2014-11-11 03:41:55 +00:00
|
|
|
|
BaseItem queryParent,
|
2014-10-06 23:58:46 +00:00
|
|
|
|
InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
where T : BaseItem
|
|
|
|
|
{
|
2015-01-25 06:34:50 +00:00
|
|
|
|
items = items.Where(i => Filter(i, query.User, query, _userDataManager, _libraryManager));
|
|
|
|
|
|
2016-06-05 19:44:55 +00:00
|
|
|
|
return PostFilterAndSort(items, queryParent, null, query, _libraryManager, _config);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 05:34:10 +00:00
|
|
|
|
public static bool FilterItem(BaseItem item, InternalItemsQuery query)
|
2015-01-25 06:34:50 +00:00
|
|
|
|
{
|
2016-05-18 05:34:10 +00:00
|
|
|
|
return Filter(item, query.User, query, BaseItem.UserDataManager, BaseItem.LibraryManager);
|
2015-01-25 06:34:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items,
|
2014-11-11 03:41:55 +00:00
|
|
|
|
BaseItem queryParent,
|
2014-09-01 20:10:54 +00:00
|
|
|
|
int? totalRecordLimit,
|
2014-10-06 23:58:46 +00:00
|
|
|
|
InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2016-06-05 19:44:55 +00:00
|
|
|
|
return PostFilterAndSort(items, queryParent, totalRecordLimit, query, _libraryManager, _config);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
public static QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items,
|
2014-11-11 03:41:55 +00:00
|
|
|
|
BaseItem queryParent,
|
2014-09-01 20:10:54 +00:00
|
|
|
|
int? totalRecordLimit,
|
2014-10-06 23:58:46 +00:00
|
|
|
|
InternalItemsQuery query,
|
2016-06-05 19:44:55 +00:00
|
|
|
|
ILibraryManager libraryManager,
|
|
|
|
|
IServerConfigurationManager configurationManager)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
var user = query.User;
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
items = FilterVirtualEpisodes(items,
|
|
|
|
|
query.IsMissing,
|
|
|
|
|
query.IsVirtualUnaired,
|
|
|
|
|
query.IsUnaired);
|
|
|
|
|
|
2016-06-05 19:44:55 +00:00
|
|
|
|
items = CollapseBoxSetItemsIfNeeded(items, query, queryParent, user, configurationManager);
|
2014-10-08 01:37:45 +00:00
|
|
|
|
|
|
|
|
|
// This must be the last filter
|
|
|
|
|
if (!string.IsNullOrEmpty(query.AdjacentTo))
|
|
|
|
|
{
|
|
|
|
|
items = FilterForAdjacency(items, query.AdjacentTo);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
return Sort(items, totalRecordLimit, query, libraryManager);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
public static IEnumerable<BaseItem> CollapseBoxSetItemsIfNeeded(IEnumerable<BaseItem> items,
|
|
|
|
|
InternalItemsQuery query,
|
2014-11-11 03:41:55 +00:00
|
|
|
|
BaseItem queryParent,
|
2016-06-05 19:44:55 +00:00
|
|
|
|
User user,
|
|
|
|
|
IServerConfigurationManager configurationManager)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
2015-02-05 03:01:37 +00:00
|
|
|
|
if (items == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("items");
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 19:44:55 +00:00
|
|
|
|
if (CollapseBoxSetItems(query, queryParent, user, configurationManager))
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
items = BaseItem.CollectionManager.CollapseItemsWithinBoxSets(items, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
items = ApplyPostCollectionCollapseFilters(query, items, user);
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<BaseItem> ApplyPostCollectionCollapseFilters(InternalItemsQuery request,
|
|
|
|
|
IEnumerable<BaseItem> items,
|
|
|
|
|
User user)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(request.NameStartsWithOrGreater))
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(i => string.Compare(request.NameStartsWithOrGreater, i.SortName, StringComparison.CurrentCultureIgnoreCase) < 1);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(request.NameStartsWith))
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(i => string.Compare(request.NameStartsWith, i.SortName.Substring(0, 1), StringComparison.CurrentCultureIgnoreCase) == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(request.NameLessThan))
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(i => string.Compare(request.NameLessThan, i.SortName, StringComparison.CurrentCultureIgnoreCase) == 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
public static bool CollapseBoxSetItems(InternalItemsQuery query,
|
2014-11-11 03:41:55 +00:00
|
|
|
|
BaseItem queryParent,
|
2016-06-05 19:44:55 +00:00
|
|
|
|
User user,
|
|
|
|
|
IServerConfigurationManager configurationManager)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
// Could end up stuck in a loop like this
|
2014-11-11 03:41:55 +00:00
|
|
|
|
if (queryParent is BoxSet)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var param = query.CollapseBoxSetItems;
|
|
|
|
|
|
|
|
|
|
if (!param.HasValue)
|
|
|
|
|
{
|
2016-06-05 19:44:55 +00:00
|
|
|
|
if (user != null && !configurationManager.Configuration.EnableGroupingIntoCollections)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-10 20:09:55 +00:00
|
|
|
|
if (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains("Movie", StringComparer.OrdinalIgnoreCase))
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
param = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return param.HasValue && param.Value && AllowBoxSetCollapsing(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool AllowBoxSetCollapsing(InternalItemsQuery request)
|
|
|
|
|
{
|
|
|
|
|
if (request.IsFavorite.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (request.IsFavoriteOrLiked.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (request.IsLiked.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (request.IsPlayed.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (request.IsResumable.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (request.IsFolder.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.Genres.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasImdbId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasOfficialRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasOverview.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasParentalRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasSpecialFeature.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasSubtitles.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasThemeSong.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasThemeVideo.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasTmdbId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.HasTrailer.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.ImageTypes.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.Is3D.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.IsHD.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.IsInBoxSet.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.IsLocked.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.IsPlaceHolder.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.IsPlayed.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.Person))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-18 16:40:16 +00:00
|
|
|
|
if (request.PersonIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (request.ItemIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
if (request.Studios.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 18:45:03 +00:00
|
|
|
|
if (request.StudioIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 15:02:22 +00:00
|
|
|
|
if (request.GenreIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
if (request.VideoTypes.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.Years.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 04:20:11 +00:00
|
|
|
|
if (request.Tags.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.OfficialRatings.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (request.MinPlayers.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.MaxPlayers.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.MinCommunityRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.MinCriticRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 15:53:23 +00:00
|
|
|
|
if (request.MinIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 15:53:23 +00:00
|
|
|
|
private static IEnumerable<BaseItem> FilterVirtualEpisodes(
|
2014-10-08 01:37:45 +00:00
|
|
|
|
IEnumerable<BaseItem> items,
|
|
|
|
|
bool? isMissing,
|
|
|
|
|
bool? isVirtualUnaired,
|
|
|
|
|
bool? isUnaired)
|
|
|
|
|
{
|
|
|
|
|
items = FilterVirtualSeasons(items, isMissing, isVirtualUnaired, isUnaired);
|
|
|
|
|
|
|
|
|
|
if (isMissing.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = isMissing.Value;
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var e = i as Episode;
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
|
|
|
|
return e.IsMissingEpisode == val;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isUnaired.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = isUnaired.Value;
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var e = i as Episode;
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
|
|
|
|
return e.IsUnaired == val;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isVirtualUnaired.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = isVirtualUnaired.Value;
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var e = i as Episode;
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
|
|
|
|
return e.IsVirtualUnaired == val;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<BaseItem> FilterVirtualSeasons(
|
|
|
|
|
IEnumerable<BaseItem> items,
|
|
|
|
|
bool? isMissing,
|
|
|
|
|
bool? isVirtualUnaired,
|
|
|
|
|
bool? isUnaired)
|
|
|
|
|
{
|
|
|
|
|
if (isMissing.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = isMissing.Value;
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var e = i as Season;
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
2016-05-20 21:32:43 +00:00
|
|
|
|
return (e.IsMissingSeason) == val;
|
2014-10-08 01:37:45 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isUnaired.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = isUnaired.Value;
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var e = i as Season;
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
|
|
|
|
return e.IsUnaired == val;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isVirtualUnaired.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = isVirtualUnaired.Value;
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var e = i as Season;
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
|
|
|
|
return e.IsVirtualUnaired == val;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
public static QueryResult<BaseItem> Sort(IEnumerable<BaseItem> items,
|
|
|
|
|
int? totalRecordLimit,
|
2014-10-06 23:58:46 +00:00
|
|
|
|
InternalItemsQuery query,
|
2014-09-01 20:10:54 +00:00
|
|
|
|
ILibraryManager libraryManager)
|
|
|
|
|
{
|
|
|
|
|
var user = query.User;
|
|
|
|
|
|
2016-08-12 19:11:45 +00:00
|
|
|
|
items = items.DistinctBy(i => i.GetPresentationUniqueKey(), StringComparer.OrdinalIgnoreCase);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
|
|
|
|
if (query.SortBy.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
items = libraryManager.Sort(items, user, query.SortBy, query.SortOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var itemsArray = totalRecordLimit.HasValue ? items.Take(totalRecordLimit.Value).ToArray() : items.ToArray();
|
|
|
|
|
var totalCount = itemsArray.Length;
|
|
|
|
|
|
|
|
|
|
if (query.Limit.HasValue)
|
|
|
|
|
{
|
|
|
|
|
itemsArray = itemsArray.Skip(query.StartIndex ?? 0).Take(query.Limit.Value).ToArray();
|
|
|
|
|
}
|
|
|
|
|
else if (query.StartIndex.HasValue)
|
|
|
|
|
{
|
|
|
|
|
itemsArray = itemsArray.Skip(query.StartIndex.Value).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = totalCount,
|
|
|
|
|
Items = itemsArray
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 06:34:50 +00:00
|
|
|
|
public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (query.ItemIdsFromPersonFilters == null)
|
|
|
|
|
{
|
|
|
|
|
if (query.PersonIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var names = query.PersonIds
|
|
|
|
|
.Select(libraryManager.GetItemById)
|
|
|
|
|
.Select(i => i == null ? null : i.Name)
|
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var itemIdList = new List<Guid>();
|
|
|
|
|
foreach (var name in names)
|
|
|
|
|
{
|
|
|
|
|
itemIdList.AddRange(libraryManager.GetItemIds(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
Person = name
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
query.ItemIdsFromPersonFilters = itemIdList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply person filter
|
|
|
|
|
else if (!string.IsNullOrWhiteSpace(query.Person))
|
|
|
|
|
{
|
|
|
|
|
var itemIdList = new List<Guid>();
|
|
|
|
|
|
|
|
|
|
itemIdList.AddRange(libraryManager.GetItemIds(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
Person = query.Person,
|
|
|
|
|
PersonTypes = query.PersonTypes
|
|
|
|
|
}));
|
|
|
|
|
query.ItemIdsFromPersonFilters = itemIdList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
if (query.IncludeItemTypes.Length > 0 && !query.IncludeItemTypes.Contains(item.GetClientTypeName(), StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.ExcludeItemTypes.Length > 0 && query.ExcludeItemTypes.Contains(item.GetClientTypeName(), StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-10-08 01:37:45 +00:00
|
|
|
|
|
2016-03-21 03:14:39 +00:00
|
|
|
|
if (query.ExcludeLocationTypes.Length > 0 && query.ExcludeLocationTypes.Contains(item.LocationType))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
if (query.IsFolder.HasValue && query.IsFolder.Value != item.IsFolder)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserItemData userData = null;
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
if (query.IsLiked.HasValue)
|
|
|
|
|
{
|
2016-04-30 22:05:13 +00:00
|
|
|
|
userData = userData ?? userDataManager.GetUserData(user, item);
|
2014-10-06 23:58:46 +00:00
|
|
|
|
|
|
|
|
|
if (!userData.Likes.HasValue || userData.Likes != query.IsLiked.Value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.IsFavoriteOrLiked.HasValue)
|
|
|
|
|
{
|
2016-04-30 22:05:13 +00:00
|
|
|
|
userData = userData ?? userDataManager.GetUserData(user, item);
|
2014-10-06 23:58:46 +00:00
|
|
|
|
var isFavoriteOrLiked = userData.IsFavorite || (userData.Likes ?? false);
|
|
|
|
|
|
|
|
|
|
if (isFavoriteOrLiked != query.IsFavoriteOrLiked.Value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
if (query.IsFavorite.HasValue)
|
|
|
|
|
{
|
2016-04-30 22:05:13 +00:00
|
|
|
|
userData = userData ?? userDataManager.GetUserData(user, item);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
|
|
|
|
if (userData.IsFavorite != query.IsFavorite.Value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.IsResumable.HasValue)
|
|
|
|
|
{
|
2016-04-30 22:05:13 +00:00
|
|
|
|
userData = userData ?? userDataManager.GetUserData(user, item);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
var isResumable = userData.PlaybackPositionTicks > 0;
|
|
|
|
|
|
|
|
|
|
if (isResumable != query.IsResumable.Value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.IsPlayed.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (item.IsPlayed(user) != query.IsPlayed.Value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
if (query.IsInBoxSet.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.IsInBoxSet.Value;
|
2015-11-11 14:56:31 +00:00
|
|
|
|
if (item.GetParents().OfType<BoxSet>().Any() != val)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by Video3DFormat
|
|
|
|
|
if (query.Is3D.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.Is3D.Value;
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
|
|
|
|
if (video == null || val != video.Video3DFormat.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.IsHD.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.IsHD.Value;
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
2015-10-04 18:10:50 +00:00
|
|
|
|
if (video == null || !video.IsHD.HasValue || val != video.IsHD)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.IsLocked.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.IsLocked.Value;
|
|
|
|
|
if (item.IsLocked != val)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasOverview.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasOverview.Value;
|
|
|
|
|
|
|
|
|
|
var hasValue = !string.IsNullOrEmpty(item.Overview);
|
|
|
|
|
|
|
|
|
|
if (hasValue != filterValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasImdbId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasImdbId.Value;
|
|
|
|
|
|
|
|
|
|
var hasValue = !string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Imdb));
|
|
|
|
|
|
|
|
|
|
if (hasValue != filterValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasTmdbId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasTmdbId.Value;
|
|
|
|
|
|
|
|
|
|
var hasValue = !string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb));
|
|
|
|
|
|
|
|
|
|
if (hasValue != filterValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasTvdbId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasTvdbId.Value;
|
|
|
|
|
|
|
|
|
|
var hasValue = !string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb));
|
|
|
|
|
|
|
|
|
|
if (hasValue != filterValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasOfficialRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasOfficialRating.Value;
|
|
|
|
|
|
|
|
|
|
var hasValue = !string.IsNullOrEmpty(item.OfficialRating);
|
|
|
|
|
|
|
|
|
|
if (hasValue != filterValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.IsPlaceHolder.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.IsPlaceHolder.Value;
|
|
|
|
|
|
|
|
|
|
var isPlaceHolder = false;
|
|
|
|
|
|
|
|
|
|
var hasPlaceHolder = item as ISupportsPlaceHolders;
|
|
|
|
|
|
|
|
|
|
if (hasPlaceHolder != null)
|
|
|
|
|
{
|
|
|
|
|
isPlaceHolder = hasPlaceHolder.IsPlaceHolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isPlaceHolder != filterValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasSpecialFeature.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasSpecialFeature.Value;
|
|
|
|
|
|
|
|
|
|
var movie = item as IHasSpecialFeatures;
|
|
|
|
|
|
|
|
|
|
if (movie != null)
|
|
|
|
|
{
|
|
|
|
|
var ok = filterValue
|
|
|
|
|
? movie.SpecialFeatureIds.Count > 0
|
|
|
|
|
: movie.SpecialFeatureIds.Count == 0;
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasSubtitles.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.HasSubtitles.Value;
|
|
|
|
|
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
|
|
|
|
if (video == null || val != video.HasSubtitles)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasParentalRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.HasParentalRating.Value;
|
|
|
|
|
|
|
|
|
|
var rating = item.CustomRating;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(rating))
|
|
|
|
|
{
|
|
|
|
|
rating = item.OfficialRating;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (val)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(rating))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(rating))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasTrailer.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.HasTrailer.Value;
|
|
|
|
|
var trailerCount = 0;
|
|
|
|
|
|
|
|
|
|
var hasTrailers = item as IHasTrailers;
|
|
|
|
|
if (hasTrailers != null)
|
|
|
|
|
{
|
2014-12-11 06:20:28 +00:00
|
|
|
|
trailerCount = hasTrailers.GetTrailerIds().Count;
|
2014-10-08 01:37:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ok = val ? trailerCount > 0 : trailerCount == 0;
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasThemeSong.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasThemeSong.Value;
|
|
|
|
|
|
|
|
|
|
var themeCount = 0;
|
|
|
|
|
var iHasThemeMedia = item as IHasThemeMedia;
|
|
|
|
|
|
|
|
|
|
if (iHasThemeMedia != null)
|
|
|
|
|
{
|
|
|
|
|
themeCount = iHasThemeMedia.ThemeSongIds.Count;
|
|
|
|
|
}
|
|
|
|
|
var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.HasThemeVideo.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.HasThemeVideo.Value;
|
|
|
|
|
|
|
|
|
|
var themeCount = 0;
|
|
|
|
|
var iHasThemeMedia = item as IHasThemeMedia;
|
|
|
|
|
|
|
|
|
|
if (iHasThemeMedia != null)
|
|
|
|
|
{
|
|
|
|
|
themeCount = iHasThemeMedia.ThemeVideoIds.Count;
|
|
|
|
|
}
|
|
|
|
|
var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply genre filter
|
2016-03-27 21:11:27 +00:00
|
|
|
|
if (query.Genres.Length > 0 && !query.Genres.Any(v => item.Genres.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by VideoType
|
|
|
|
|
if (query.VideoTypes.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
if (video == null || !query.VideoTypes.Contains(video.VideoType))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.ImageTypes.Length > 0 && !query.ImageTypes.Any(item.HasImage))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply studio filter
|
|
|
|
|
if (query.Studios.Length > 0 && !query.Studios.Any(v => item.Studios.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 18:45:03 +00:00
|
|
|
|
// Apply studio filter
|
|
|
|
|
if (query.StudioIds.Length > 0 && !query.StudioIds.Any(id =>
|
|
|
|
|
{
|
|
|
|
|
var studioItem = libraryManager.GetItemById(id);
|
|
|
|
|
return studioItem != null && item.Studios.Contains(studioItem.Name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 15:02:22 +00:00
|
|
|
|
// Apply genre filter
|
|
|
|
|
if (query.GenreIds.Length > 0 && !query.GenreIds.Any(id =>
|
|
|
|
|
{
|
|
|
|
|
var genreItem = libraryManager.GetItemById(id);
|
|
|
|
|
return genreItem != null && item.Genres.Contains(genreItem.Name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
// Apply year filter
|
|
|
|
|
if (query.Years.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
if (!(item.ProductionYear.HasValue && query.Years.Contains(item.ProductionYear.Value)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 04:20:11 +00:00
|
|
|
|
// Apply official rating filter
|
|
|
|
|
if (query.OfficialRatings.Length > 0 && !query.OfficialRatings.Contains(item.OfficialRating ?? string.Empty))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (query.ItemIds.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
if (!query.ItemIds.Contains(item.Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
// Apply person filter
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (query.ItemIdsFromPersonFilters != null)
|
2015-03-18 16:40:16 +00:00
|
|
|
|
{
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (!query.ItemIdsFromPersonFilters.Contains(item.Id))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-08 16:10:34 +00:00
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
// Apply tag filter
|
|
|
|
|
var tags = query.Tags;
|
|
|
|
|
if (tags.Length > 0)
|
|
|
|
|
{
|
2016-06-02 17:43:29 +00:00
|
|
|
|
if (!tags.Any(v => item.Tags.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
2015-03-18 17:04:49 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-18 16:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (query.MinPlayers.HasValue)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
2015-07-14 19:04:16 +00:00
|
|
|
|
var filterValue = query.MinPlayers.Value;
|
|
|
|
|
|
|
|
|
|
var game = item as Game;
|
2014-10-08 01:37:45 +00:00
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (game != null)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
2015-07-14 19:04:16 +00:00
|
|
|
|
var players = game.PlayersSupported ?? 1;
|
|
|
|
|
|
|
|
|
|
var ok = players >= filterValue;
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
2014-10-08 01:37:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-14 19:04:16 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.MaxPlayers.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.MaxPlayers.Value;
|
|
|
|
|
|
|
|
|
|
var game = item as Game;
|
|
|
|
|
|
|
|
|
|
if (game != null)
|
|
|
|
|
{
|
|
|
|
|
var players = game.PlayersSupported ?? 1;
|
2014-10-08 01:37:45 +00:00
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
var ok = players <= filterValue;
|
2014-10-08 01:37:45 +00:00
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-14 19:04:16 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-11-16 22:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:04:16 +00:00
|
|
|
|
if (query.MinCommunityRating.HasValue)
|
2014-11-10 04:20:11 +00:00
|
|
|
|
{
|
2015-07-14 19:04:16 +00:00
|
|
|
|
var val = query.MinCommunityRating.Value;
|
|
|
|
|
|
|
|
|
|
if (!(item.CommunityRating.HasValue && item.CommunityRating >= val))
|
2014-11-10 04:20:11 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-07-14 19:04:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.MinCriticRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.MinCriticRating.Value;
|
|
|
|
|
|
|
|
|
|
var hasCriticRating = item as IHasCriticRating;
|
|
|
|
|
|
|
|
|
|
if (hasCriticRating != null)
|
|
|
|
|
{
|
|
|
|
|
if (!(hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-11-10 04:20:11 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-10-08 01:37:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 15:53:23 +00:00
|
|
|
|
if (query.MinIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.MinIndexNumber.Value;
|
|
|
|
|
|
|
|
|
|
if (!(item.IndexNumber.HasValue && item.IndexNumber.Value >= val))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 06:46:51 +00:00
|
|
|
|
if (query.MinPremiereDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.MinPremiereDate.Value;
|
|
|
|
|
|
|
|
|
|
if (!(item.PremiereDate.HasValue && item.PremiereDate.Value >= val))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.MaxPremiereDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = query.MaxPremiereDate.Value;
|
|
|
|
|
|
|
|
|
|
if (!(item.PremiereDate.HasValue && item.PremiereDate.Value <= val))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 19:53:22 +00:00
|
|
|
|
if (query.ParentIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var filterValue = query.ParentIndexNumber.Value;
|
|
|
|
|
|
|
|
|
|
if (item.ParentIndexNumber.HasValue && item.ParentIndexNumber.Value != filterValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.AirDays.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var ok = new[] { item }.OfType<Series>().Any(p => p.AirDays != null && query.AirDays.Any(d => p.AirDays.Contains(d)));
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (query.SeriesStatuses.Length > 0)
|
|
|
|
|
{
|
2016-05-15 19:25:54 +00:00
|
|
|
|
var ok = new[] { item }.OfType<Series>().Any(p => p.Status.HasValue && query.SeriesStatuses.Contains(p.Status.Value));
|
2016-03-20 19:53:22 +00:00
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 20:04:27 +00:00
|
|
|
|
if (query.AiredDuringSeason.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var episode = item as Episode;
|
|
|
|
|
|
|
|
|
|
if (episode == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Series.FilterEpisodesBySeason(new[] { episode }, query.AiredDuringSeason.Value, true).Any())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 00:15:56 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(query.AlbumArtistStartsWithOrGreater))
|
|
|
|
|
{
|
|
|
|
|
var ok = new[] { item }.OfType<IHasAlbumArtist>()
|
|
|
|
|
.Any(p => string.Compare(query.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1);
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 16:50:50 +00:00
|
|
|
|
// Artists
|
|
|
|
|
if (query.ArtistNames.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var audio = item as IHasArtist;
|
|
|
|
|
|
|
|
|
|
if (!(audio != null && query.ArtistNames.Any(audio.HasAnyArtist)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Albums
|
|
|
|
|
if (query.AlbumNames.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var audio = item as Audio.Audio;
|
|
|
|
|
|
|
|
|
|
if (audio != null)
|
|
|
|
|
{
|
|
|
|
|
if (!query.AlbumNames.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var album = item as MusicAlbum;
|
|
|
|
|
|
|
|
|
|
if (album != null)
|
|
|
|
|
{
|
|
|
|
|
if (!query.AlbumNames.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var musicVideo = item as MusicVideo;
|
|
|
|
|
|
|
|
|
|
if (musicVideo != null)
|
|
|
|
|
{
|
|
|
|
|
if (!query.AlbumNames.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<Folder> GetMediaFolders(User user)
|
|
|
|
|
{
|
2015-09-15 18:09:44 +00:00
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.RootFolder
|
|
|
|
|
.Children
|
|
|
|
|
.OfType<Folder>()
|
2015-11-18 05:49:20 +00:00
|
|
|
|
.Where(UserView.IsEligibleForGrouping);
|
2015-09-15 18:09:44 +00:00
|
|
|
|
}
|
2014-09-01 20:10:54 +00:00
|
|
|
|
return user.RootFolder
|
2015-11-11 14:56:31 +00:00
|
|
|
|
.GetChildren(user, true)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
.OfType<Folder>()
|
2015-11-18 05:49:20 +00:00
|
|
|
|
.Where(i => user.IsFolderGrouped(i.Id) && UserView.IsEligibleForGrouping(i));
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 01:37:45 +00:00
|
|
|
|
private IEnumerable<Folder> GetMediaFolders(User user, IEnumerable<string> viewTypes)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2015-09-15 18:09:44 +00:00
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
return GetMediaFolders(null)
|
|
|
|
|
.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var folder = i as ICollectionFolder;
|
|
|
|
|
|
|
|
|
|
return folder != null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-09-01 20:10:54 +00:00
|
|
|
|
return GetMediaFolders(user)
|
|
|
|
|
.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var folder = i as ICollectionFolder;
|
|
|
|
|
|
|
|
|
|
return folder != null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
private IEnumerable<Folder> GetMediaFolders(Folder parent, User user, IEnumerable<string> viewTypes)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (parent == null || parent is UserView)
|
|
|
|
|
{
|
|
|
|
|
return GetMediaFolders(user, viewTypes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new[] { parent };
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
private IEnumerable<BaseItem> GetRecursiveChildren(Folder parent, User user, IEnumerable<string> viewTypes)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (parent == null || parent is UserView)
|
|
|
|
|
{
|
2015-09-15 18:09:44 +00:00
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
return GetMediaFolders(null, viewTypes).SelectMany(i => i.GetRecursiveChildren());
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user));
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-15 18:09:44 +00:00
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
return parent.GetRecursiveChildren();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:10:54 +00:00
|
|
|
|
return parent.GetRecursiveChildren(user);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-13 05:12:02 +00:00
|
|
|
|
private async Task<QueryResult<BaseItem>> GetLiveTvView(Folder queryParent, User user, InternalItemsQuery query)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2015-04-13 05:12:02 +00:00
|
|
|
|
if (query.Recursive)
|
|
|
|
|
{
|
|
|
|
|
return await _liveTvManager.GetInternalRecordings(new RecordingQuery
|
|
|
|
|
{
|
|
|
|
|
IsInProgress = false,
|
|
|
|
|
Status = RecordingStatus.Completed,
|
|
|
|
|
UserId = user.Id.ToString("N")
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2015-04-13 05:12:02 +00:00
|
|
|
|
}, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = new List<BaseItem>();
|
2014-10-29 22:01:02 +00:00
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
//list.Add(await GetUserSubView(SpecialFolder.LiveTvNowPlaying, user, "0", parent).ConfigureAwait(false));
|
2015-08-14 18:00:26 +00:00
|
|
|
|
list.Add(await GetUserView(SpecialFolder.LiveTvChannels, string.Empty, user.RootFolder).ConfigureAwait(false));
|
|
|
|
|
list.Add(await GetUserView(SpecialFolder.LiveTvRecordingGroups, string.Empty, user.RootFolder).ConfigureAwait(false));
|
2014-09-01 20:10:54 +00:00
|
|
|
|
|
2015-04-13 05:12:02 +00:00
|
|
|
|
return GetResult(list, queryParent, query);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 18:00:26 +00:00
|
|
|
|
private Task<UserView> GetUserView(string name, string type, string sortName, BaseItem parent)
|
2014-11-11 03:41:55 +00:00
|
|
|
|
{
|
2015-08-14 18:00:26 +00:00
|
|
|
|
return _userViewManager.GetUserSubView(name, parent.Id.ToString("N"), type, sortName, CancellationToken.None);
|
2014-11-11 03:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 18:00:26 +00:00
|
|
|
|
private Task<UserView> GetUserView(string type, string sortName, BaseItem parent)
|
2014-09-01 20:10:54 +00:00
|
|
|
|
{
|
2015-08-14 18:00:26 +00:00
|
|
|
|
return _userViewManager.GetUserSubView(parent.Id.ToString("N"), type, sortName, CancellationToken.None);
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
2014-10-08 01:37:45 +00:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<BaseItem> FilterForAdjacency(IEnumerable<BaseItem> items, string adjacentToId)
|
|
|
|
|
{
|
|
|
|
|
var list = items.ToList();
|
|
|
|
|
|
|
|
|
|
var adjacentToIdGuid = new Guid(adjacentToId);
|
|
|
|
|
var adjacentToItem = list.FirstOrDefault(i => i.Id == adjacentToIdGuid);
|
|
|
|
|
|
|
|
|
|
var index = list.IndexOf(adjacentToItem);
|
|
|
|
|
|
|
|
|
|
var previousId = Guid.Empty;
|
|
|
|
|
var nextId = Guid.Empty;
|
|
|
|
|
|
|
|
|
|
if (index > 0)
|
|
|
|
|
{
|
|
|
|
|
previousId = list[index - 1].Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index < list.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
nextId = list[index + 1].Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list.Where(i => i.Id == previousId || i.Id == nextId || i.Id == adjacentToIdGuid);
|
|
|
|
|
}
|
2014-09-01 20:10:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|