update people sorting
This commit is contained in:
parent
7736bab314
commit
8c52c065fb
|
@ -252,6 +252,11 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
return (PersonIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public string[] GetItemIds()
|
||||
{
|
||||
return (Ids ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public VideoType[] GetVideoTypes()
|
||||
{
|
||||
var val = VideoTypes;
|
||||
|
@ -329,54 +334,12 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
var result = await GetItemsToSerialize(request, user, parentItem).ConfigureAwait(false);
|
||||
|
||||
var isFiltered = result.Item2;
|
||||
var dtoOptions = GetDtoOptions(request);
|
||||
|
||||
if (isFiltered)
|
||||
{
|
||||
return new ItemsResult
|
||||
{
|
||||
TotalRecordCount = result.Item1.TotalRecordCount,
|
||||
Items = _dtoService.GetBaseItemDtos(result.Item1.Items, dtoOptions, user).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
var items = result.Item1.Items.Where(i => ApplyAdditionalFilters(request, i, user, false, _libraryManager));
|
||||
|
||||
// Apply filters
|
||||
// Run them starting with the ones that are likely to reduce the list the most
|
||||
foreach (var filter in request.GetFilters().OrderByDescending(f => (int)f))
|
||||
{
|
||||
items = ApplyFilter(items, filter, user, _userDataRepository);
|
||||
}
|
||||
|
||||
items = UserViewBuilder.FilterVirtualEpisodes(items,
|
||||
request.IsMissing,
|
||||
request.IsVirtualUnaired,
|
||||
request.IsUnaired);
|
||||
|
||||
var internalQuery = GetItemsQuery(request, user);
|
||||
|
||||
items = UserViewBuilder.CollapseBoxSetItemsIfNeeded(items, internalQuery, parentItem, user);
|
||||
|
||||
items = _libraryManager.Sort(items, user, request.GetOrderBy(), request.SortOrder ?? SortOrder.Ascending);
|
||||
|
||||
// This must be the last filter
|
||||
if (!string.IsNullOrEmpty(request.AdjacentTo))
|
||||
{
|
||||
items = UserViewBuilder.FilterForAdjacency(items, request.AdjacentTo);
|
||||
}
|
||||
|
||||
var itemsArray = items.ToList();
|
||||
|
||||
var pagedItems = ApplyPaging(request, itemsArray);
|
||||
|
||||
var returnItems = _dtoService.GetBaseItemDtos(pagedItems, dtoOptions, user).ToArray();
|
||||
|
||||
return new ItemsResult
|
||||
{
|
||||
TotalRecordCount = itemsArray.Count,
|
||||
Items = returnItems
|
||||
TotalRecordCount = result.Item1.TotalRecordCount,
|
||||
Items = _dtoService.GetBaseItemDtos(result.Item1.Items, dtoOptions, user).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -394,45 +357,46 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
parentItem;
|
||||
|
||||
// Default list type = children
|
||||
IEnumerable<BaseItem> items;
|
||||
|
||||
if (!string.IsNullOrEmpty(request.Ids))
|
||||
{
|
||||
var idList = request.Ids.Split(',').ToList();
|
||||
request.Recursive = true;
|
||||
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
|
||||
|
||||
items = idList.Select(i => _libraryManager.GetItemById(i));
|
||||
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
|
||||
}
|
||||
|
||||
else if (request.Recursive)
|
||||
if (request.Recursive)
|
||||
{
|
||||
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
|
||||
|
||||
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
|
||||
}
|
||||
else
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
var result = await ((Folder)item).GetItems(GetItemsQuery(request, null)).ConfigureAwait(false);
|
||||
var result = await ((Folder)item).GetItems(GetItemsQuery(request, null)).ConfigureAwait(false);
|
||||
|
||||
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
|
||||
}
|
||||
|
||||
var userRoot = item as UserRootFolder;
|
||||
|
||||
if (userRoot == null)
|
||||
{
|
||||
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
|
||||
|
||||
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
|
||||
}
|
||||
|
||||
items = ((Folder)item).GetChildren(user, true);
|
||||
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
|
||||
}
|
||||
|
||||
var userRoot = item as UserRootFolder;
|
||||
|
||||
if (userRoot == null)
|
||||
{
|
||||
var result = await ((Folder)item).GetItems(GetItemsQuery(request, user)).ConfigureAwait(false);
|
||||
|
||||
return new Tuple<QueryResult<BaseItem>, bool>(result, true);
|
||||
}
|
||||
|
||||
IEnumerable<BaseItem> items = ((Folder)item).GetChildren(user, true);
|
||||
|
||||
var itemsArray = items.ToArray();
|
||||
|
||||
return new Tuple<QueryResult<BaseItem>, bool>(new QueryResult<BaseItem>
|
||||
{
|
||||
Items = items.ToArray()
|
||||
Items = itemsArray,
|
||||
TotalRecordCount = itemsArray.Length
|
||||
|
||||
}, false);
|
||||
}
|
||||
|
@ -450,7 +414,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
SortBy = request.GetOrderBy(),
|
||||
SortOrder = request.SortOrder ?? SortOrder.Ascending,
|
||||
|
||||
Filter = i => ApplyAdditionalFilters(request, i, user, true, _libraryManager),
|
||||
Filter = i => ApplyAdditionalFilters(request, i, user, _libraryManager),
|
||||
|
||||
Limit = request.Limit,
|
||||
StartIndex = request.StartIndex,
|
||||
|
@ -490,7 +454,12 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
Years = request.GetYears(),
|
||||
ImageTypes = request.GetImageTypes().ToArray(),
|
||||
VideoTypes = request.GetVideoTypes().ToArray(),
|
||||
AdjacentTo = request.AdjacentTo
|
||||
AdjacentTo = request.AdjacentTo,
|
||||
ItemIds = request.GetItemIds(),
|
||||
MinPlayers = request.MinPlayers,
|
||||
MaxPlayers = request.MaxPlayers,
|
||||
MinCommunityRating = request.MinCommunityRating,
|
||||
MinCriticRating = request.MinCriticRating
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Ids))
|
||||
|
@ -619,440 +588,8 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
return items;
|
||||
}
|
||||
|
||||
private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, bool isPreFiltered, ILibraryManager libraryManager)
|
||||
private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, ILibraryManager libraryManager)
|
||||
{
|
||||
var video = i as Video;
|
||||
|
||||
if (!isPreFiltered)
|
||||
{
|
||||
var mediaTypes = request.GetMediaTypes();
|
||||
if (mediaTypes.Length > 0)
|
||||
{
|
||||
if (!(!string.IsNullOrEmpty(i.MediaType) && mediaTypes.Contains(i.MediaType, StringComparer.OrdinalIgnoreCase)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.IsPlayed.HasValue)
|
||||
{
|
||||
var val = request.IsPlayed.Value;
|
||||
if (i.IsPlayed(user) != val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Exclude item types
|
||||
var excluteItemTypes = request.GetExcludeItemTypes();
|
||||
if (excluteItemTypes.Length > 0 && excluteItemTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Include item types
|
||||
var includeItemTypes = request.GetIncludeItemTypes();
|
||||
if (includeItemTypes.Length > 0 && !includeItemTypes.Contains(i.GetType().Name, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request.IsInBoxSet.HasValue)
|
||||
{
|
||||
var val = request.IsInBoxSet.Value;
|
||||
if (i.Parents.OfType<BoxSet>().Any() != val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by Video3DFormat
|
||||
if (request.Is3D.HasValue)
|
||||
{
|
||||
var val = request.Is3D.Value;
|
||||
|
||||
if (video == null || val != video.Video3DFormat.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.IsHD.HasValue)
|
||||
{
|
||||
var val = request.IsHD.Value;
|
||||
|
||||
if (video == null || val != video.IsHD)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.IsUnidentified.HasValue)
|
||||
{
|
||||
var val = request.IsUnidentified.Value;
|
||||
if (i.IsUnidentified != val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.IsLocked.HasValue)
|
||||
{
|
||||
var val = request.IsLocked.Value;
|
||||
if (i.IsLocked != val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasOverview.HasValue)
|
||||
{
|
||||
var filterValue = request.HasOverview.Value;
|
||||
|
||||
var hasValue = !string.IsNullOrEmpty(i.Overview);
|
||||
|
||||
if (hasValue != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasImdbId.HasValue)
|
||||
{
|
||||
var filterValue = request.HasImdbId.Value;
|
||||
|
||||
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Imdb));
|
||||
|
||||
if (hasValue != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasTmdbId.HasValue)
|
||||
{
|
||||
var filterValue = request.HasTmdbId.Value;
|
||||
|
||||
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb));
|
||||
|
||||
if (hasValue != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasTvdbId.HasValue)
|
||||
{
|
||||
var filterValue = request.HasTvdbId.Value;
|
||||
|
||||
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb));
|
||||
|
||||
if (hasValue != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.IsYearMismatched.HasValue)
|
||||
{
|
||||
var filterValue = request.IsYearMismatched.Value;
|
||||
|
||||
if (UserViewBuilder.IsYearMismatched(i, libraryManager) != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasOfficialRating.HasValue)
|
||||
{
|
||||
var filterValue = request.HasOfficialRating.Value;
|
||||
|
||||
var hasValue = !string.IsNullOrEmpty(i.OfficialRating);
|
||||
|
||||
if (hasValue != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.IsPlaceHolder.HasValue)
|
||||
{
|
||||
var filterValue = request.IsPlaceHolder.Value;
|
||||
|
||||
var isPlaceHolder = false;
|
||||
|
||||
var hasPlaceHolder = i as ISupportsPlaceHolders;
|
||||
|
||||
if (hasPlaceHolder != null)
|
||||
{
|
||||
isPlaceHolder = hasPlaceHolder.IsPlaceHolder;
|
||||
}
|
||||
|
||||
if (isPlaceHolder != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasSpecialFeature.HasValue)
|
||||
{
|
||||
var filterValue = request.HasSpecialFeature.Value;
|
||||
|
||||
var movie = i as IHasSpecialFeatures;
|
||||
|
||||
if (movie != null)
|
||||
{
|
||||
var ok = filterValue
|
||||
? movie.SpecialFeatureIds.Count > 0
|
||||
: movie.SpecialFeatureIds.Count == 0;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasSubtitles.HasValue)
|
||||
{
|
||||
var val = request.HasSubtitles.Value;
|
||||
|
||||
if (video == null || val != video.HasSubtitles)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasParentalRating.HasValue)
|
||||
{
|
||||
var val = request.HasParentalRating.Value;
|
||||
|
||||
var rating = i.CustomRating;
|
||||
|
||||
if (string.IsNullOrEmpty(rating))
|
||||
{
|
||||
rating = i.OfficialRating;
|
||||
}
|
||||
|
||||
if (val)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rating))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(rating))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasTrailer.HasValue)
|
||||
{
|
||||
var val = request.HasTrailer.Value;
|
||||
var trailerCount = 0;
|
||||
|
||||
var hasTrailers = i as IHasTrailers;
|
||||
if (hasTrailers != null)
|
||||
{
|
||||
trailerCount = hasTrailers.GetTrailerIds().Count;
|
||||
}
|
||||
|
||||
var ok = val ? trailerCount > 0 : trailerCount == 0;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasThemeSong.HasValue)
|
||||
{
|
||||
var filterValue = request.HasThemeSong.Value;
|
||||
|
||||
var themeCount = 0;
|
||||
var iHasThemeMedia = i as IHasThemeMedia;
|
||||
|
||||
if (iHasThemeMedia != null)
|
||||
{
|
||||
themeCount = iHasThemeMedia.ThemeSongIds.Count;
|
||||
}
|
||||
var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.HasThemeVideo.HasValue)
|
||||
{
|
||||
var filterValue = request.HasThemeVideo.Value;
|
||||
|
||||
var themeCount = 0;
|
||||
var iHasThemeMedia = i as IHasThemeMedia;
|
||||
|
||||
if (iHasThemeMedia != null)
|
||||
{
|
||||
themeCount = iHasThemeMedia.ThemeVideoIds.Count;
|
||||
}
|
||||
var ok = filterValue ? themeCount > 0 : themeCount == 0;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply tag filter
|
||||
var tags = request.GetTags();
|
||||
if (tags.Length > 0)
|
||||
{
|
||||
var hasTags = i as IHasTags;
|
||||
if (hasTags == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(tags.Any(v => hasTags.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply official rating filter
|
||||
var officialRatings = request.GetOfficialRatings();
|
||||
if (officialRatings.Length > 0 && !officialRatings.Contains(i.OfficialRating ?? string.Empty))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply genre filter
|
||||
var genres = request.GetGenres();
|
||||
if (genres.Length > 0 && !(genres.Any(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter by VideoType
|
||||
var videoTypes = request.GetVideoTypes();
|
||||
if (videoTypes.Length > 0 && (video == null || !videoTypes.Contains(video.VideoType)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var imageTypes = request.GetImageTypes().ToList();
|
||||
if (imageTypes.Count > 0)
|
||||
{
|
||||
if (!(imageTypes.Any(i.HasImage)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply studio filter
|
||||
var studios = request.GetStudios();
|
||||
if (studios.Length > 0 && !studios.Any(v => i.Studios.Contains(v, StringComparer.OrdinalIgnoreCase)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply studio filter
|
||||
var studioIds = request.GetStudioIds();
|
||||
if (studioIds.Length > 0 && !studioIds.Any(id =>
|
||||
{
|
||||
var studioItem = libraryManager.GetItemById(id);
|
||||
return studioItem != null && i.Studios.Contains(studioItem.Name, StringComparer.OrdinalIgnoreCase);
|
||||
}))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply year filter
|
||||
var years = request.GetYears();
|
||||
if (years.Length > 0 && !(i.ProductionYear.HasValue && years.Contains(i.ProductionYear.Value)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply person filter
|
||||
var personIds = request.GetPersonIds();
|
||||
if (personIds.Length > 0)
|
||||
{
|
||||
var names = personIds
|
||||
.Select(libraryManager.GetItemById)
|
||||
.Select(p => p == null ? "-1" : p.Name)
|
||||
.ToList();
|
||||
|
||||
if (!(names.Any(v => libraryManager.GetPeople(i).Select(p => p.Name).Contains(v, StringComparer.OrdinalIgnoreCase))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply person filter
|
||||
if (!string.IsNullOrEmpty(request.Person))
|
||||
{
|
||||
var personTypes = request.GetPersonTypes();
|
||||
|
||||
if (personTypes.Length == 0)
|
||||
{
|
||||
if (!(libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, request.Person, StringComparison.OrdinalIgnoreCase))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var types = personTypes;
|
||||
|
||||
var ok = new[] { i }.Any(item =>
|
||||
libraryManager.GetPeople(item).Any(p =>
|
||||
p.Name.Equals(request.Person, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role, StringComparer.OrdinalIgnoreCase))));
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (request.MinCommunityRating.HasValue)
|
||||
{
|
||||
var val = request.MinCommunityRating.Value;
|
||||
|
||||
if (!(i.CommunityRating.HasValue && i.CommunityRating >= val))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.MinCriticRating.HasValue)
|
||||
{
|
||||
var val = request.MinCriticRating.Value;
|
||||
|
||||
var hasCriticRating = i as IHasCriticRating;
|
||||
|
||||
if (hasCriticRating != null)
|
||||
{
|
||||
if (!(hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Artists
|
||||
if (!string.IsNullOrEmpty(request.ArtistIds))
|
||||
{
|
||||
|
@ -1239,52 +776,6 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
}
|
||||
}
|
||||
|
||||
if (request.MinPlayers.HasValue)
|
||||
{
|
||||
var filterValue = request.MinPlayers.Value;
|
||||
|
||||
var game = i as Game;
|
||||
|
||||
if (game != null)
|
||||
{
|
||||
var players = game.PlayersSupported ?? 1;
|
||||
|
||||
var ok = players >= filterValue;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.MaxPlayers.HasValue)
|
||||
{
|
||||
var filterValue = request.MaxPlayers.Value;
|
||||
|
||||
var game = i as Game;
|
||||
|
||||
if (game != null)
|
||||
{
|
||||
var players = game.PlayersSupported ?? 1;
|
||||
|
||||
var ok = players <= filterValue;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.ParentIndexNumber.HasValue)
|
||||
{
|
||||
var filterValue = request.ParentIndexNumber.Value;
|
||||
|
@ -1347,29 +838,6 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the paging.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <returns>IEnumerable{BaseItem}.</returns>
|
||||
private IEnumerable<BaseItem> ApplyPaging(GetItems request, IEnumerable<BaseItem> items)
|
||||
{
|
||||
// Start at
|
||||
if (request.StartIndex.HasValue)
|
||||
{
|
||||
items = items.Skip(request.StartIndex.Value);
|
||||
}
|
||||
|
||||
// Return limit
|
||||
if (request.Limit.HasValue)
|
||||
{
|
||||
items = items.Take(request.Limit.Value);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -235,6 +235,15 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public virtual bool EnableAlphaNumericSorting
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is just a helper for convenience
|
||||
/// </summary>
|
||||
|
@ -439,6 +448,11 @@ namespace MediaBrowser.Controller.Entities
|
|||
{
|
||||
if (Name == null) return null; //some items may not have name filled in properly
|
||||
|
||||
if (!EnableAlphaNumericSorting)
|
||||
{
|
||||
return Name.TrimStart();
|
||||
}
|
||||
|
||||
var sortable = Name.Trim().ToLower();
|
||||
sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty));
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
|
@ -42,6 +43,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
public string Person { get; set; }
|
||||
public string[] PersonIds { get; set; }
|
||||
public string[] ItemIds { get; set; }
|
||||
public string AdjacentTo { get; set; }
|
||||
public string[] PersonTypes { get; set; }
|
||||
|
||||
|
@ -82,9 +84,16 @@ namespace MediaBrowser.Controller.Entities
|
|||
public bool? IsMovie { get; set; }
|
||||
public bool? IsSports { get; set; }
|
||||
public bool? IsKids { get; set; }
|
||||
|
||||
|
||||
public int? MinPlayers { get; set; }
|
||||
public int? MaxPlayers { get; set; }
|
||||
public double? MinCriticRating { get; set; }
|
||||
public double? MinCommunityRating { get; set; }
|
||||
|
||||
public string[] ChannelIds { get; set; }
|
||||
|
||||
|
||||
internal List<Guid> ItemIdsFromPersonFilters { get; set; }
|
||||
|
||||
public InternalItemsQuery()
|
||||
{
|
||||
Tags = new string[] { };
|
||||
|
@ -102,6 +111,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
PersonTypes = new string[] { };
|
||||
PersonIds = new string[] { };
|
||||
ChannelIds = new string[] { };
|
||||
ItemIds = new string[] { };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,15 @@ namespace MediaBrowser.Controller.Entities
|
|||
return true;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public override bool EnableAlphaNumericSorting
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is owned item.
|
||||
/// </summary>
|
||||
|
|
|
@ -1116,6 +1116,11 @@ namespace MediaBrowser.Controller.Entities
|
|||
return false;
|
||||
}
|
||||
|
||||
if (request.ItemIds.Length > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request.Studios.Length > 0)
|
||||
{
|
||||
return false;
|
||||
|
@ -1146,6 +1151,26 @@ namespace MediaBrowser.Controller.Entities
|
|||
return false;
|
||||
}
|
||||
|
||||
if (request.MinPlayers.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request.MaxPlayers.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request.MinCommunityRating.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request.MinCriticRating.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1304,6 +1329,41 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
|
@ -1691,44 +1751,20 @@ namespace MediaBrowser.Controller.Entities
|
|||
return false;
|
||||
}
|
||||
|
||||
// Apply person filter
|
||||
if (query.PersonIds.Length > 0)
|
||||
if (query.ItemIds.Length > 0)
|
||||
{
|
||||
var names = query.PersonIds
|
||||
.Select(libraryManager.GetItemById)
|
||||
.Select(i => i == null ? "-1" : i.Name)
|
||||
.ToList();
|
||||
|
||||
if (!(names.Any(v => libraryManager.GetPeople(item).Select(i => i.Name).Contains(v, StringComparer.OrdinalIgnoreCase))))
|
||||
if (!query.ItemIds.Contains(item.Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply person filter
|
||||
if (!string.IsNullOrWhiteSpace(query.Person))
|
||||
if (query.ItemIdsFromPersonFilters != null)
|
||||
{
|
||||
var personTypes = query.PersonTypes;
|
||||
|
||||
if (personTypes.Length == 0)
|
||||
if (!query.ItemIdsFromPersonFilters.Contains(item.Id))
|
||||
{
|
||||
if (!(libraryManager.GetPeople(item).Any(p => string.Equals(p.Name, query.Person, StringComparison.OrdinalIgnoreCase))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var types = personTypes;
|
||||
|
||||
var ok = new[] { item }.Any(i =>
|
||||
libraryManager.GetPeople(i).Any(p =>
|
||||
string.Equals(p.Name, query.Person, StringComparison.OrdinalIgnoreCase) && (types.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase) || types.Contains(p.Role ?? string.Empty, StringComparer.OrdinalIgnoreCase))));
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1747,6 +1783,81 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
if (query.MinPlayers.HasValue)
|
||||
{
|
||||
var filterValue = query.MinPlayers.Value;
|
||||
|
||||
var game = item as Game;
|
||||
|
||||
if (game != null)
|
||||
{
|
||||
var players = game.PlayersSupported ?? 1;
|
||||
|
||||
var ok = players >= filterValue;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (query.MaxPlayers.HasValue)
|
||||
{
|
||||
var filterValue = query.MaxPlayers.Value;
|
||||
|
||||
var game = item as Game;
|
||||
|
||||
if (game != null)
|
||||
{
|
||||
var players = game.PlayersSupported ?? 1;
|
||||
|
||||
var ok = players <= filterValue;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (query.MinCommunityRating.HasValue)
|
||||
{
|
||||
var val = query.MinCommunityRating.Value;
|
||||
|
||||
if (!(item.CommunityRating.HasValue && item.CommunityRating >= val))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -439,7 +439,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
|
||||
if (!string.IsNullOrWhiteSpace(artists))
|
||||
{
|
||||
audio.Artists = artists.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
audio.Artists = SplitArtists(artists, new[] { '/' }, false)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
}
|
||||
else
|
||||
{
|
||||
audio.Artists = SplitArtists(artist)
|
||||
audio.Artists = SplitArtists(artist, _nameDelimiters, true)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -474,7 +474,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
}
|
||||
else
|
||||
{
|
||||
audio.AlbumArtists = SplitArtists(albumArtist)
|
||||
audio.AlbumArtists = SplitArtists(albumArtist, _nameDelimiters, true)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
|
@ -552,10 +552,13 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
|
||||
private const string ArtistReplaceValue = " | ";
|
||||
|
||||
private IEnumerable<string> SplitArtists(string val)
|
||||
private IEnumerable<string> SplitArtists(string val, char[] delimiters, bool splitFeaturing)
|
||||
{
|
||||
val = val.Replace(" featuring ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase)
|
||||
.Replace(" feat. ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase);
|
||||
if (splitFeaturing)
|
||||
{
|
||||
val = val.Replace(" featuring ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase)
|
||||
.Replace(" feat. ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
var artistsFound = new List<string>();
|
||||
|
||||
|
@ -570,11 +573,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
}
|
||||
}
|
||||
|
||||
// Only use the comma as a delimeter if there are no slashes or pipes.
|
||||
// We want to be careful not to split names that have commas in them
|
||||
var delimeter = _nameDelimiters;
|
||||
|
||||
var artists = val.Split(delimeter, StringSplitOptions.RemoveEmptyEntries)
|
||||
var artists = val.Split(delimiters, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
.Select(i => i.Trim());
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Sorting;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Sorting
|
||||
{
|
||||
|
@ -17,6 +18,11 @@ namespace MediaBrowser.Server.Implementations.Sorting
|
|||
/// <returns>System.Int32.</returns>
|
||||
public int Compare(BaseItem x, BaseItem y)
|
||||
{
|
||||
if (!x.EnableAlphaNumericSorting || !y.EnableAlphaNumericSorting)
|
||||
{
|
||||
return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
return AlphanumComparator.CompareValues(x.Name, y.Name);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Sorting;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Sorting
|
||||
{
|
||||
|
@ -17,6 +18,11 @@ namespace MediaBrowser.Server.Implementations.Sorting
|
|||
/// <returns>System.Int32.</returns>
|
||||
public int Compare(BaseItem x, BaseItem y)
|
||||
{
|
||||
if (!x.EnableAlphaNumericSorting || !y.EnableAlphaNumericSorting)
|
||||
{
|
||||
return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
return AlphanumComparator.CompareValues(x.SortName, y.SortName);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user