update folder queries

This commit is contained in:
Luke Pulverenti 2017-04-27 14:12:44 -04:00
parent ffb935700c
commit da39d9a5bf
12 changed files with 69 additions and 114 deletions

View File

@ -470,7 +470,7 @@ namespace Emby.Server.Implementations.FileOrganization
return new List<string>();
}
var episodePaths = series.GetRecursiveChildren()
var episodePaths = series.GetRecursiveChildren(i => i is Episode)
.OfType<Episode>()
.Where(i =>
{

View File

@ -5,6 +5,7 @@ using MediaBrowser.Controller.Playlists;
using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Model.Querying;
namespace Emby.Server.Implementations.Library
{
@ -27,53 +28,17 @@ namespace Emby.Server.Implementations.Library
return list.Concat(GetInstantMixFromGenres(item.Genres, user));
}
public IEnumerable<Audio> GetInstantMixFromArtist(MusicArtist artist, User user)
public IEnumerable<Audio> GetInstantMixFromArtist(MusicArtist item, User user)
{
var genres = user.RootFolder
.GetRecursiveChildren(user, new InternalItemsQuery(user)
{
IncludeItemTypes = new[] { typeof(Audio).Name }
})
.Cast<Audio>()
.Where(i => i.HasAnyArtist(artist.Name))
.SelectMany(i => i.Genres)
.Concat(artist.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase);
return GetInstantMixFromGenres(genres, user);
return GetInstantMixFromGenres(item.Genres, user);
}
public IEnumerable<Audio> GetInstantMixFromAlbum(MusicAlbum item, User user)
{
var genres = item
.GetRecursiveChildren(user, new InternalItemsQuery(user)
{
IncludeItemTypes = new[] { typeof(Audio).Name }
})
.Cast<Audio>()
.SelectMany(i => i.Genres)
.Concat(item.Genres)
.DistinctNames();
return GetInstantMixFromGenres(genres, user);
return GetInstantMixFromGenres(item.Genres, user);
}
public IEnumerable<Audio> GetInstantMixFromFolder(Folder item, User user)
{
var genres = item
.GetRecursiveChildren(user, new InternalItemsQuery(user)
{
IncludeItemTypes = new[] {typeof(Audio).Name}
})
.Cast<Audio>()
.SelectMany(i => i.Genres)
.Concat(item.Genres)
.DistinctNames();
return GetInstantMixFromGenres(genres, user);
}
public IEnumerable<Audio> GetInstantMixFromPlaylist(Playlist item, User user)
{
var genres = item
.GetRecursiveChildren(user, new InternalItemsQuery(user)
@ -88,28 +53,42 @@ namespace Emby.Server.Implementations.Library
return GetInstantMixFromGenres(genres, user);
}
public IEnumerable<Audio> GetInstantMixFromPlaylist(Playlist item, User user)
{
return GetInstantMixFromGenres(item.Genres, user);
}
public IEnumerable<Audio> GetInstantMixFromGenres(IEnumerable<string> genres, User user)
{
var genreList = genres.ToList();
var genreIds = genres.DistinctNames().Select(i =>
{
try
{
return _libraryManager.GetMusicGenre(i).Id.ToString("N");
}
catch
{
return null;
}
var inputItems = _libraryManager.GetItemList(new InternalItemsQuery(user)
}).Where(i => i != null);
return GetInstantMixFromGenreIds(genreIds, user);
}
public IEnumerable<Audio> GetInstantMixFromGenreIds(IEnumerable<string> genreIds, User user)
{
return _libraryManager.GetItemList(new InternalItemsQuery(user)
{
IncludeItemTypes = new[] { typeof(Audio).Name },
Genres = genreList.ToArray()
GenreIds = genreIds.ToArray(),
});
Limit = 200,
var genresDictionary = genreList.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
SortBy = new[] { ItemSortBy.Random }
return inputItems
.Cast<Audio>()
.Select(i => new Tuple<Audio, int>(i, i.Genres.Count(genresDictionary.ContainsKey)))
.OrderByDescending(i => i.Item2)
.ThenBy(i => Guid.NewGuid())
.Select(i => i.Item1)
.Take(200)
.OrderBy(i => Guid.NewGuid());
}).Cast<Audio>();
}
public IEnumerable<Audio> GetInstantMixFromItem(BaseItem item, User user)
@ -117,7 +96,7 @@ namespace Emby.Server.Implementations.Library
var genre = item as MusicGenre;
if (genre != null)
{
return GetInstantMixFromGenres(new[] { item.Name }, user);
return GetInstantMixFromGenreIds(new[] { item.Id.ToString("N") }, user);
}
var playlist = item as Playlist;

View File

@ -112,7 +112,7 @@ namespace MediaBrowser.Controller.Entities.Audio
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
{
query.Genres = new[] { Name };
query.GenreIds = new[] { Id.ToString("N") };
query.IncludeItemTypes = new[] { typeof(MusicVideo).Name, typeof(Audio).Name, typeof(MusicAlbum).Name, typeof(MusicArtist).Name };
return LibraryManager.GetItemList(query);

View File

@ -81,7 +81,7 @@ namespace MediaBrowser.Controller.Entities
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
{
query.Genres = new[] { Name };
query.GenreIds = new[] { Id.ToString("N") };
query.IncludeItemTypes = new[] { typeof(Game).Name };
return LibraryManager.GetItemList(query);

View File

@ -93,7 +93,7 @@ namespace MediaBrowser.Controller.Entities
public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
{
query.Genres = new[] { Name };
query.GenreIds = new[] { Id.ToString("N") };
query.ExcludeItemTypes = new[] { typeof(Game).Name, typeof(MusicVideo).Name, typeof(Audio.Audio).Name, typeof(MusicAlbum).Name, typeof(MusicArtist).Name };
return LibraryManager.GetItemList(query);

View File

@ -152,9 +152,7 @@ namespace MediaBrowser.Controller.Entities.Movies
var currentOfficialRating = OfficialRating;
// Gather all possible ratings
var ratings = GetRecursiveChildren()
.Concat(GetLinkedChildren())
.Where(i => i is Movie || i is Series || i is MusicAlbum || i is Game)
var ratings = GetRecursiveChildren(i => i is Movie || i is Series || i is MusicAlbum || i is Game)
.Select(i => i.OfficialRating)
.Where(i => !string.IsNullOrEmpty(i))
.Distinct(StringComparer.OrdinalIgnoreCase)

View File

@ -586,7 +586,7 @@ namespace MediaBrowser.Controller.Entities
{
query.Recursive = true;
query.ParentId = queryParent.Id;
query.Genres = new[] { displayParent.Name };
query.GenreIds = new[] { displayParent.Id.ToString("N") };
query.SetUser(user);
query.IncludeItemTypes = new[] { typeof(Movie).Name };
@ -729,7 +729,7 @@ namespace MediaBrowser.Controller.Entities
{
query.Recursive = true;
query.ParentId = queryParent.Id;
query.Genres = new[] { displayParent.Name };
query.GenreIds = new[] { displayParent.Id.ToString("N") };
query.SetUser(user);
query.IncludeItemTypes = new[] { typeof(Series).Name };
@ -905,6 +905,11 @@ namespace MediaBrowser.Controller.Entities
return false;
}
if (request.GenreIds.Length > 0)
{
return false;
}
if (request.HasImdbId.HasValue)
{
return false;
@ -1768,26 +1773,6 @@ namespace MediaBrowser.Controller.Entities
return new List<Folder> { parent };
}
private IEnumerable<BaseItem> GetRecursiveChildren(Folder parent, User user, IEnumerable<string> viewTypes)
{
if (parent == null || parent is UserView)
{
if (user == null)
{
return GetMediaFolders(null, viewTypes).SelectMany(i => i.GetRecursiveChildren());
}
return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user));
}
if (user == null)
{
return parent.GetRecursiveChildren();
}
return parent.GetRecursiveChildren(user);
}
private async Task<QueryResult<BaseItem>> GetLiveTvView(Folder queryParent, User user, InternalItemsQuery query)
{
if (query.Recursive)

View File

@ -134,34 +134,27 @@ namespace MediaBrowser.Controller.Playlists
var musicGenre = item as MusicGenre;
if (musicGenre != null)
{
var items = LibraryManager.GetItemList(new InternalItemsQuery(user)
return LibraryManager.GetItemList(new InternalItemsQuery(user)
{
Recursive = true,
IncludeItemTypes = new[] { typeof(Audio).Name },
Genres = new[] { musicGenre.Name }
GenreIds = new[] { musicGenre.Id.ToString("N") },
SortBy = new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName },
SortOrder = SortOrder.Ascending
});
return LibraryManager.Sort(items, user, new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }, SortOrder.Ascending);
}
var musicArtist = item as MusicArtist;
if (musicArtist != null)
{
Func<BaseItem, bool> filter = i =>
return LibraryManager.GetItemList(new InternalItemsQuery(user)
{
var audio = i as Audio;
return audio != null && audio.HasAnyArtist(musicArtist.Name);
};
var items = user == null
? LibraryManager.RootFolder.GetRecursiveChildren(filter)
: user.RootFolder.GetRecursiveChildren(user, new InternalItemsQuery(user)
{
IncludeItemTypes = new[] { typeof(Audio).Name },
ArtistIds = new[] { musicArtist.Id.ToString("N") }
});
return LibraryManager.Sort(items, user, new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName }, SortOrder.Ascending);
Recursive = true,
IncludeItemTypes = new[] { typeof(Audio).Name },
ArtistIds = new[] { musicArtist.Id.ToString("N") },
SortBy = new[] { ItemSortBy.AlbumArtist, ItemSortBy.Album, ItemSortBy.SortName },
SortOrder = SortOrder.Ascending
});
}
var folder = item as Folder;

View File

@ -41,8 +41,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
public string ItemType { get; set; }
public string AlbumCoverPath { get; set; }
public string GetMimeType(string outputPath)
{
if (!string.IsNullOrEmpty(MimeType))

View File

@ -20,8 +20,7 @@ namespace MediaBrowser.Providers.Music
{
var album = (MusicAlbum)item;
var image = album.GetRecursiveChildren()
.OfType<Audio>()
var image = album.GetRecursiveChildren(i => !i.IsFolder)
.Select(i => i.GetImageInfo(type, 0))
.FirstOrDefault(i => i != null && i.IsLocalFile);

View File

@ -53,8 +53,8 @@ namespace MediaBrowser.Providers.TV
private async Task<bool> AddDummySeasonFolders(Series series, CancellationToken cancellationToken)
{
var episodesInSeriesFolder = series.GetRecursiveChildren()
.OfType<Episode>()
var episodesInSeriesFolder = series.GetRecursiveChildren(i => i is Episode)
.Cast<Episode>()
.Where(i => !i.IsInSeasonFolder)
.ToList();

View File

@ -203,7 +203,7 @@ namespace MediaBrowser.Providers.TV
CancellationToken cancellationToken)
{
var existingEpisodes = (from s in series
from c in s.GetRecursiveChildren().OfType<Episode>()
from c in s.GetRecursiveChildren(i => i is Episode).Cast<Episode>()
select new Tuple<int, Episode>((c.ParentIndexNumber ?? 0) , c))
.ToList();
@ -275,13 +275,16 @@ namespace MediaBrowser.Providers.TV
return hasChanges;
}
private Series DetermineAppropriateSeries(IEnumerable<Series> series, int seasonNumber)
private Series DetermineAppropriateSeries(List<Series> series, int seasonNumber)
{
var seriesAndOffsets = series.ToList();
if (series.Count == 1)
{
return series[0];
}
return seriesAndOffsets.FirstOrDefault(s => s.GetRecursiveChildren().OfType<Season>().Any(season => (season.IndexNumber) == seasonNumber)) ??
seriesAndOffsets.FirstOrDefault(s => s.GetRecursiveChildren().OfType<Season>().Any(season => (season.IndexNumber) == 1)) ??
seriesAndOffsets.OrderBy(s => s.GetRecursiveChildren().OfType<Season>().Select(season => season.IndexNumber).Min()).First();
return series.FirstOrDefault(s => s.GetRecursiveChildren(i => i is Season).Any(season => (season.IndexNumber) == seasonNumber)) ??
series.FirstOrDefault(s => s.GetRecursiveChildren(i => i is Season).Any(season => (season.IndexNumber) == 1)) ??
series.OrderBy(s => s.GetRecursiveChildren(i => i is Season).Select(season => season.IndexNumber).Min()).First();
}
/// <summary>
@ -292,7 +295,7 @@ namespace MediaBrowser.Providers.TV
bool allowMissingEpisodes)
{
var existingEpisodes = (from s in series
from c in s.GetRecursiveChildren().OfType<Episode>()
from c in s.GetRecursiveChildren(i => i is Episode).Cast<Episode>()
select new { Episode = c })
.ToList();
@ -402,7 +405,7 @@ namespace MediaBrowser.Providers.TV
// Season does not have a number
// Remove if there are no episodes directly in series without a season number
return i.Series.GetRecursiveChildren().OfType<Episode>().All(s => s.ParentIndexNumber.HasValue || s.IsInSeasonFolder);
return i.Series.GetRecursiveChildren(e => e is Episode).Cast<Episode>().All(s => s.ParentIndexNumber.HasValue || s.IsInSeasonFolder);
})
.ToList();