added new parent methods

This commit is contained in:
Luke Pulverenti 2015-11-11 09:56:31 -05:00
parent db8e51edb6
commit cc19ce0daf
48 changed files with 189 additions and 143 deletions

View File

@ -259,6 +259,16 @@ namespace Emby.Drawing
_imageEncoder.EncodeImage(originalImagePath, cacheFilePath, newWidth, newHeight, quality, options, outputFormat);
}
return new Tuple<string, string>(cacheFilePath, GetMimeType(outputFormat, cacheFilePath));
}
catch (Exception ex)
{
// If it fails for whatever reason, return the original image
_logger.ErrorException("Error encoding image", ex);
// Just spit out the original file if all the options are default
return new Tuple<string, string>(originalImagePath, MimeTypes.GetMimeType(originalImagePath));
}
finally
{
@ -269,8 +279,6 @@ namespace Emby.Drawing
semaphore.Release();
}
return new Tuple<string, string>(cacheFilePath, GetMimeType(outputFormat, cacheFilePath));
}
private string GetMimeType(ImageFormat format, string path)

View File

@ -108,7 +108,7 @@ namespace MediaBrowser.Api
IncludeItemTypes = new[] { typeof(GameSystem).Name }
};
var parentIds = new string[] { } ;
var gameSystems = _libraryManager.GetItems(query, user, parentIds)
var gameSystems = _libraryManager.GetItems(query, parentIds)
.Cast<GameSystem>()
.ToList();
@ -129,7 +129,7 @@ namespace MediaBrowser.Api
IncludeItemTypes = new[] { typeof(Game).Name }
};
var parentIds = new string[] { };
var games = _libraryManager.GetItems(query, user, parentIds)
var games = _libraryManager.GetItems(query, parentIds)
.Cast<Game>()
.ToList();

View File

@ -698,7 +698,7 @@ namespace MediaBrowser.Api.Images
var userAgent = Request.UserAgent ?? string.Empty;
if (userAgent.IndexOf("crosswalk", StringComparison.OrdinalIgnoreCase) != -1 &&
if (userAgent.IndexOf("dalvik", StringComparison.OrdinalIgnoreCase) != -1 &&
userAgent.IndexOf("android", StringComparison.OrdinalIgnoreCase) != -1)
{
supportsWebP = true;

View File

@ -610,7 +610,7 @@ namespace MediaBrowser.Api.Library
var dtoOptions = GetDtoOptions(request);
BaseItem parent = item.Parent;
BaseItem parent = item.GetParent();
while (parent != null)
{
@ -621,7 +621,7 @@ namespace MediaBrowser.Api.Library
baseItemDtos.Add(_dtoService.GetBaseItemDto(parent, dtoOptions, user));
parent = parent.Parent;
parent = parent.GetParent();
}
return baseItemDtos.ToList();
@ -629,7 +629,7 @@ namespace MediaBrowser.Api.Library
private BaseItem TranslateParentItem(BaseItem item, User user)
{
if (item.Parent is AggregateFolder)
if (item.GetParent() is AggregateFolder)
{
return user.RootFolder.GetChildren(user, true).FirstOrDefault(i => i.PhysicalLocations.Contains(item.Path));
}
@ -861,9 +861,9 @@ namespace MediaBrowser.Api.Library
: (Folder)_libraryManager.RootFolder)
: _libraryManager.GetItemById(request.Id);
while (GetThemeSongIds(item).Count == 0 && request.InheritFromParent && item.Parent != null)
while (GetThemeSongIds(item).Count == 0 && request.InheritFromParent && item.GetParent() != null)
{
item = item.Parent;
item = item.GetParent();
}
var dtoOptions = GetDtoOptions(request);
@ -904,9 +904,9 @@ namespace MediaBrowser.Api.Library
: (Folder)_libraryManager.RootFolder)
: _libraryManager.GetItemById(request.Id);
while (GetThemeVideoIds(item).Count == 0 && request.InheritFromParent && item.Parent != null)
while (GetThemeVideoIds(item).Count == 0 && request.InheritFromParent && item.GetParent() != null)
{
item = item.Parent;
item = item.GetParent();
}
var dtoOptions = GetDtoOptions(request);

View File

@ -139,7 +139,7 @@ namespace MediaBrowser.Api.Movies
IncludeItemTypes = new[] { typeof(Movie).Name }
};
var parentIds = string.IsNullOrWhiteSpace(request.ParentId) ? new string[] { } : new[] { request.ParentId };
var movies = _libraryManager.GetItems(query, user, parentIds);
var movies = _libraryManager.GetItems(query, parentIds);
movies = _libraryManager.ReplaceVideosWithPrimaryVersions(movies);
var listEligibleForCategories = new List<BaseItem>();
@ -195,7 +195,7 @@ namespace MediaBrowser.Api.Movies
IncludeItemTypes = new[] { typeof(Movie).Name }
};
var parentIds = new string[] { };
var list = _libraryManager.GetItems(query, user, parentIds)
var list = _libraryManager.GetItems(query, parentIds)
.Where(i =>
{
// Strip out secondary versions

View File

@ -283,7 +283,7 @@ namespace MediaBrowser.Api
private T GetParentWithImage<T>(BaseItem item, ImageType type)
where T : BaseItem
{
return item.Parents.OfType<T>().FirstOrDefault(i => i.HasImage(type));
return item.GetParents().OfType<T>().FirstOrDefault(i => i.HasImage(type));
}
}
}

View File

@ -70,10 +70,10 @@ namespace MediaBrowser.Api
_config.Configuration.EnableStandaloneMetadata = true;
_config.Configuration.EnableLibraryMetadataSubFolder = true;
_config.Configuration.EnableCustomPathSubFolders = true;
_config.Configuration.DisableXmlSavers = true;
_config.Configuration.DisableStartupScan = true;
_config.Configuration.EnableUserViews = true;
_config.Configuration.EnableDateLastRefresh = true;
_config.Configuration.EnableSharedCollectionViewImage = true;
_config.SaveConfiguration();
}

View File

@ -80,6 +80,7 @@ namespace MediaBrowser.Api.UserLibrary
var dtoOptions = GetDtoOptions(request);
dtoOptions.Fields = new List<ItemFields>();
dtoOptions.Fields.Add(ItemFields.PrimaryImageAspectRatio);
dtoOptions.Fields.Add(ItemFields.DisplayPreferencesId);
var user = _userManager.GetUserById(request.UserId);

View File

@ -30,7 +30,7 @@ namespace MediaBrowser.Controller.Entities.Audio
{
get
{
return Parents.OfType<MusicArtist>().FirstOrDefault();
return GetParents().OfType<MusicArtist>().FirstOrDefault();
}
}
@ -121,7 +121,7 @@ namespace MediaBrowser.Controller.Entities.Audio
id.AlbumArtists = AlbumArtists;
var artist = Parents.OfType<MusicArtist>().FirstOrDefault();
var artist = GetParents().OfType<MusicArtist>().FirstOrDefault();
if (artist != null)
{

View File

@ -214,11 +214,6 @@ namespace MediaBrowser.Controller.Entities
}
}
public virtual bool IsHiddenFromUser(User user)
{
return false;
}
[IgnoreDataMember]
public virtual bool IsOwnedItem
{
@ -519,15 +514,7 @@ namespace MediaBrowser.Controller.Entities
[IgnoreDataMember]
public Folder Parent
{
get
{
if (ParentId != Guid.Empty)
{
return LibraryManager.GetItemById(ParentId) as Folder;
}
return null;
}
get { return GetParent() as Folder; }
set
{
@ -542,16 +529,28 @@ namespace MediaBrowser.Controller.Entities
[IgnoreDataMember]
public IEnumerable<Folder> Parents
{
get
get { return GetParents().OfType<Folder>(); }
}
public BaseItem GetParent()
{
var parent = Parent;
if (ParentId != Guid.Empty)
{
return LibraryManager.GetItemById(ParentId);
}
return null;
}
public IEnumerable<BaseItem> GetParents()
{
var parent = GetParent();
while (parent != null)
{
yield return parent;
parent = parent.Parent;
}
parent = parent.GetParent();
}
}
@ -563,13 +562,13 @@ namespace MediaBrowser.Controller.Entities
public T FindParent<T>()
where T : Folder
{
return Parents.OfType<T>().FirstOrDefault();
return GetParents().OfType<T>().FirstOrDefault();
}
[IgnoreDataMember]
public virtual BaseItem DisplayParent
{
get { return Parent; }
get { return GetParent(); }
}
/// <summary>
@ -869,7 +868,7 @@ namespace MediaBrowser.Controller.Entities
[IgnoreDataMember]
protected virtual bool SupportsOwnedItems
{
get { return IsFolder || Parent != null; }
get { return IsFolder || GetParent() != null; }
}
[IgnoreDataMember]
@ -894,7 +893,7 @@ namespace MediaBrowser.Controller.Entities
var localTrailersChanged = false;
if (LocationType == LocationType.FileSystem && Parent != null)
if (LocationType == LocationType.FileSystem && GetParent() != null)
{
var hasThemeMedia = this as IHasThemeMedia;
if (hasThemeMedia != null)
@ -1056,7 +1055,7 @@ namespace MediaBrowser.Controller.Entities
if (string.IsNullOrWhiteSpace(lang))
{
lang = Parents
lang = GetParents()
.Select(i => i.PreferredMetadataLanguage)
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
}
@ -1086,7 +1085,7 @@ namespace MediaBrowser.Controller.Entities
if (string.IsNullOrWhiteSpace(lang))
{
lang = Parents
lang = GetParents()
.Select(i => i.PreferredMetadataCountryCode)
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
}
@ -1276,14 +1275,14 @@ namespace MediaBrowser.Controller.Entities
return false;
}
if (Parents.Any(i => !i.IsVisible(user)))
if (GetParents().Any(i => !i.IsVisible(user)))
{
return false;
}
if (checkFolders)
{
var topParent = Parents.LastOrDefault() ?? this;
var topParent = GetParents().LastOrDefault() ?? this;
if (string.IsNullOrWhiteSpace(topParent.Path))
{
@ -1937,7 +1936,7 @@ namespace MediaBrowser.Controller.Entities
public virtual IEnumerable<Guid> GetAncestorIds()
{
return Parents.Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
}
[IgnoreDataMember]

View File

@ -37,7 +37,7 @@ namespace MediaBrowser.Controller.Entities
if (string.IsNullOrEmpty(SeriesName))
{
info.SeriesName = Parents.Select(i => i.Name).FirstOrDefault();
info.SeriesName = GetParents().Select(i => i.Name).FirstOrDefault();
}
else
{

View File

@ -825,19 +825,7 @@ namespace MediaBrowser.Controller.Entities
return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager);
}
/// <summary>
/// Gets allowed children of an item
/// </summary>
/// <param name="user">The user.</param>
/// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
/// <returns>IEnumerable{BaseItem}.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public virtual IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
{
return GetChildren(user, includeLinkedChildren, false);
}
internal IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren, bool includeHidden)
{
if (user == null)
{
@ -849,7 +837,7 @@ namespace MediaBrowser.Controller.Entities
var result = new Dictionary<Guid, BaseItem>();
AddChildren(user, includeLinkedChildren, result, includeHidden, false, null);
AddChildren(user, includeLinkedChildren, result, false, null);
return result.Values;
}
@ -865,29 +853,25 @@ namespace MediaBrowser.Controller.Entities
/// <param name="user">The user.</param>
/// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
/// <param name="result">The result.</param>
/// <param name="includeHidden">if set to <c>true</c> [include hidden].</param>
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
/// <param name="filter">The filter.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool includeHidden, bool recursive, Func<BaseItem, bool> filter)
private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, Func<BaseItem, bool> filter)
{
foreach (var child in GetEligibleChildrenForRecursiveChildren(user))
{
if (child.IsVisible(user))
{
if (includeHidden || !child.IsHiddenFromUser(user))
{
if (filter == null || filter(child))
{
result[child.Id] = child;
}
}
if (recursive && child.IsFolder)
{
var folder = (Folder)child;
folder.AddChildren(user, includeLinkedChildren, result, includeHidden, true, filter);
folder.AddChildren(user, includeLinkedChildren, result, true, filter);
}
}
}
@ -928,7 +912,7 @@ namespace MediaBrowser.Controller.Entities
var result = new Dictionary<Guid, BaseItem>();
AddChildren(user, true, result, false, true, filter);
AddChildren(user, true, result, true, filter);
return result.Values;
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Entities
{
public interface IHiddenFromDisplay
{
/// <summary>
/// Determines whether the specified user is hidden.
/// </summary>
/// <param name="user">The user.</param>
/// <returns><c>true</c> if the specified user is hidden; otherwise, <c>false</c>.</returns>
bool IsHiddenFromUser(User user);
}
}

View File

@ -130,7 +130,7 @@ namespace MediaBrowser.Controller.Entities.Movies
// Must have a parent to have special features
// In other words, it must be part of the Parent/Child tree
if (LocationType == LocationType.FileSystem && Parent != null && !IsInMixedFolder)
if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
{
var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);

View File

@ -49,7 +49,7 @@ namespace MediaBrowser.Controller.Entities
{
get
{
return Parents.OfType<PhotoAlbum>().FirstOrDefault();
return GetParents().OfType<PhotoAlbum>().FirstOrDefault();
}
}

View File

@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.Entities.TV
{
get
{
return Season ?? Parent;
return Season ?? GetParent();
}
}

View File

@ -33,7 +33,7 @@ namespace MediaBrowser.Controller.Entities.TV
[IgnoreDataMember]
public override BaseItem DisplayParent
{
get { return Series ?? Parent; }
get { return Series ?? GetParent(); }
}
// Genre, Rating and Stuido will all be the same

View File

@ -73,7 +73,7 @@ namespace MediaBrowser.Controller.Entities
get
{
// Local trailers are not part of children
return Parent == null;
return GetParent() == null;
}
}

View File

@ -38,6 +38,10 @@ namespace MediaBrowser.Controller.Entities
{
list.Add(ParentId);
}
else
{
list.Add(Id);
}
return list;
}
@ -125,10 +129,14 @@ namespace MediaBrowser.Controller.Entities
{
var standaloneTypes = new List<string>
{
CollectionType.Playlists,
CollectionType.BoxSets
CollectionType.Playlists
};
if (!ConfigurationManager.Configuration.EnableSharedCollectionViewImage)
{
standaloneTypes.Add(CollectionType.BoxSets);
}
var collectionFolder = folder as ICollectionFolder;
if (collectionFolder == null)

View File

@ -1073,7 +1073,7 @@ namespace MediaBrowser.Controller.Entities
if (query.IsInBoxSet.HasValue)
{
var val = query.IsInBoxSet.Value;
if (item.Parents.OfType<BoxSet>().Any() != val)
if (item.GetParents().OfType<BoxSet>().Any() != val)
{
return false;
}
@ -1511,7 +1511,7 @@ namespace MediaBrowser.Controller.Entities
.Where(i => !UserView.IsExcludedFromGrouping(i));
}
return user.RootFolder
.GetChildren(user, true, true)
.GetChildren(user, true)
.OfType<Folder>()
.Where(i => user.IsFolderGrouped(i.Id) && !UserView.IsExcludedFromGrouping(i));
}

View File

@ -352,7 +352,7 @@ namespace MediaBrowser.Controller.Entities
// Must have a parent to have additional parts or alternate versions
// In other words, it must be part of the Parent/Child tree
// The additional parts won't have additional parts themselves
if (LocationType == LocationType.FileSystem && Parent != null)
if (LocationType == LocationType.FileSystem && GetParent() != null)
{
if (!IsStacked)
{

View File

@ -548,10 +548,9 @@ namespace MediaBrowser.Controller.Library
/// Gets the items.
/// </summary>
/// <param name="query">The query.</param>
/// <param name="user">The user.</param>
/// <param name="parentIds">The parent ids.</param>
/// <returns>List&lt;BaseItem&gt;.</returns>
IEnumerable<BaseItem> GetItems(InternalItemsQuery query, User user, IEnumerable<string> parentIds);
IEnumerable<BaseItem> GetItems(InternalItemsQuery query, IEnumerable<string> parentIds);
/// <summary>
/// Gets the items result.

View File

@ -155,7 +155,7 @@ namespace MediaBrowser.Controller.Library
// Not officially supported but in some cases we can handle it.
if (item == null)
{
item = parent.Parents.OfType<T>().FirstOrDefault();
item = parent.GetParents().OfType<T>().FirstOrDefault();
}
return item != null;

View File

@ -162,6 +162,7 @@
<Compile Include="Entities\IHasThemeMedia.cs" />
<Compile Include="Entities\IHasTrailers.cs" />
<Compile Include="Entities\IHasUserData.cs" />
<Compile Include="Entities\IHiddenFromDisplay.cs" />
<Compile Include="Entities\IItemByName.cs" />
<Compile Include="Entities\ILibraryItem.cs" />
<Compile Include="Entities\ImageSourceInfo.cs" />

View File

@ -959,7 +959,7 @@ namespace MediaBrowser.Dlna.Didl
}
}
item = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Primary));
item = item.GetParents().FirstOrDefault(i => i.HasImage(ImageType.Primary));
if (item != null)
{

View File

@ -225,7 +225,6 @@ namespace MediaBrowser.Model.Configuration
public int SharingExpirationDays { get; set; }
public bool DisableXmlSavers { get; set; }
public bool EnableWindowsShortcuts { get; set; }
public bool EnableVideoFrameByFrameAnalysis { get; set; }
@ -236,6 +235,7 @@ namespace MediaBrowser.Model.Configuration
public int MigrationVersion { get; set; }
public bool EnableImagePreDownloading { get; set; }
public bool EnableSharedCollectionViewImage { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ServerConfiguration" /> class.

View File

@ -15,6 +15,12 @@ namespace MediaBrowser.Model.Library
/// <value><c>true</c> if [include external content]; otherwise, <c>false</c>.</value>
public bool IncludeExternalContent { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [include hidden].
/// </summary>
/// <value><c>true</c> if [include hidden]; otherwise, <c>false</c>.</value>
public bool IncludeHidden { get; set; }
public UserViewQuery()
{
IncludeExternalContent = true;

View File

@ -1035,7 +1035,7 @@ namespace MediaBrowser.Providers.Manager
.ToList();
var musicArtists = albums
.Select(i => i.Parent)
.Select(i => i.GetParent())
.OfType<MusicArtist>()
.ToList();

View File

@ -59,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.Collections
return subItem;
}
var parent = subItem.Parent;
var parent = subItem.GetParent();
if (parent != null && parent.HasImage(ImageType.Primary))
{

View File

@ -3,7 +3,7 @@ using System.Linq;
namespace MediaBrowser.Server.Implementations.Collections
{
public class ManualCollectionsFolder : BasePluginFolder
public class ManualCollectionsFolder : BasePluginFolder, IHiddenFromDisplay
{
public ManualCollectionsFolder()
{
@ -19,7 +19,7 @@ namespace MediaBrowser.Server.Implementations.Collections
}
}
public override bool IsHiddenFromUser(User user)
public bool IsHiddenFromUser(User user)
{
return !user.Configuration.DisplayCollectionsView;
}
@ -31,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.Collections
public override string GetClientTypeName()
{
return typeof (CollectionFolder).Name;
return typeof(CollectionFolder).Name;
}
}
}

View File

@ -167,7 +167,7 @@ namespace MediaBrowser.Server.Implementations.Dto
{
Person = byName.Name
}, user, new string[] { });
}, new string[] { });
return items.ToList();
}
@ -812,7 +812,7 @@ namespace MediaBrowser.Server.Implementations.Dto
/// <returns>BaseItem.</returns>
private BaseItem GetParentBackdropItem(BaseItem item, BaseItem owner)
{
var parent = item.Parent ?? owner;
var parent = item.GetParent() ?? owner;
while (parent != null)
{
@ -821,7 +821,7 @@ namespace MediaBrowser.Server.Implementations.Dto
return parent;
}
parent = parent.Parent;
parent = parent.GetParent();
}
return null;
@ -836,7 +836,7 @@ namespace MediaBrowser.Server.Implementations.Dto
/// <returns>BaseItem.</returns>
private BaseItem GetParentImageItem(BaseItem item, ImageType type, BaseItem owner)
{
var parent = item.Parent ?? owner;
var parent = item.GetParent() ?? owner;
while (parent != null)
{
@ -845,7 +845,7 @@ namespace MediaBrowser.Server.Implementations.Dto
return parent;
}
parent = parent.Parent;
parent = parent.GetParent();
}
return null;
@ -1210,15 +1210,15 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.VoteCount = item.VoteCount;
}
if (item.IsFolder)
{
var folder = (Folder)item;
//if (item.IsFolder)
//{
// var folder = (Folder)item;
if (fields.Contains(ItemFields.IndexOptions))
{
dto.IndexOptions = folder.IndexByOptionStrings.ToArray();
}
}
// if (fields.Contains(ItemFields.IndexOptions))
// {
// dto.IndexOptions = folder.IndexByOptionStrings.ToArray();
// }
//}
var supportsPlaceHolders = item as ISupportsPlaceHolders;
if (supportsPlaceHolders != null)

View File

@ -74,7 +74,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
// Go up one level for indicators
if (baseItem != null)
{
var parent = baseItem.Parent;
var parent = baseItem.GetParent();
if (parent != null)
{

View File

@ -217,7 +217,7 @@ namespace MediaBrowser.Server.Implementations.IO
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
void LibraryManager_ItemRemoved(object sender, ItemChangeEventArgs e)
{
if (e.Item.Parent is AggregateFolder)
if (e.Item.GetParent() is AggregateFolder)
{
StopWatchingPath(e.Item.Path);
}
@ -230,7 +230,7 @@ namespace MediaBrowser.Server.Implementations.IO
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
void LibraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
{
if (e.Item.Parent is AggregateFolder)
if (e.Item.GetParent() is AggregateFolder)
{
StartWatchingPath(e.Item.Path);
}
@ -658,7 +658,7 @@ namespace MediaBrowser.Server.Implementations.IO
// If the item has been deleted find the first valid parent that still exists
while (!_fileSystem.DirectoryExists(item.Path) && !_fileSystem.FileExists(item.Path))
{
item = item.Parent;
item = item.GetParent();
if (item == null)
{

View File

@ -87,7 +87,7 @@ namespace MediaBrowser.Server.Implementations.Intros
{
IncludeItemTypes = new[] { typeof(Movie).Name }
}, user, new string[]{});
}, new string[]{});
var itemsWithTrailers = inputItems
.Where(i =>

View File

@ -27,6 +27,7 @@ using MediaBrowser.Server.Implementations.Library.Validators;
using MediaBrowser.Server.Implementations.Logging;
using MediaBrowser.Server.Implementations.ScheduledTasks;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
@ -36,6 +37,7 @@ using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Library;
using MoreLinq;
using SortOrder = MediaBrowser.Model.Entities.SortOrder;
@ -140,6 +142,7 @@ namespace MediaBrowser.Server.Implementations.Library
private readonly Func<ILibraryMonitor> _libraryMonitorFactory;
private readonly Func<IProviderManager> _providerManagerFactory;
private readonly Func<IUserViewManager> _userviewManager;
/// <summary>
/// The _library items cache
@ -167,7 +170,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// <param name="userManager">The user manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="userDataRepository">The user data repository.</param>
public LibraryManager(ILogger logger, ITaskManager taskManager, IUserManager userManager, IServerConfigurationManager configurationManager, IUserDataManager userDataRepository, Func<ILibraryMonitor> libraryMonitorFactory, IFileSystem fileSystem, Func<IProviderManager> providerManagerFactory)
public LibraryManager(ILogger logger, ITaskManager taskManager, IUserManager userManager, IServerConfigurationManager configurationManager, IUserDataManager userDataRepository, Func<ILibraryMonitor> libraryMonitorFactory, IFileSystem fileSystem, Func<IProviderManager> providerManagerFactory, Func<IUserViewManager> userviewManager)
{
_logger = logger;
_taskManager = taskManager;
@ -177,6 +180,7 @@ namespace MediaBrowser.Server.Implementations.Library
_libraryMonitorFactory = libraryMonitorFactory;
_fileSystem = fileSystem;
_providerManagerFactory = providerManagerFactory;
_userviewManager = userviewManager;
ByReferenceItems = new ConcurrentDictionary<Guid, BaseItem>();
_libraryItemsCache = new ConcurrentDictionary<Guid, BaseItem>();
@ -1307,7 +1311,7 @@ namespace MediaBrowser.Server.Implementations.Library
return ItemRepository.GetItemIdsList(query);
}
public IEnumerable<BaseItem> GetItems(InternalItemsQuery query, User user, IEnumerable<string> parentIds)
public IEnumerable<BaseItem> GetItems(InternalItemsQuery query, IEnumerable<string> parentIds)
{
var parents = parentIds.Select(i => GetItemById(new Guid(i))).ToList();
@ -1329,7 +1333,14 @@ namespace MediaBrowser.Server.Implementations.Library
{
if (query.AncestorIds.Length == 0 && !query.ParentId.HasValue && query.ChannelIds.Length == 0)
{
// TODO: Need to filter on user folders
//var userViews = _userviewManager().GetUserViews(new UserViewQuery
//{
// UserId = user.Id.ToString("N"),
// IncludeHidden = true
//}, CancellationToken.None).Result.ToList();
//query.AncestorIds = userViews.SelectMany(i => i.GetIdsForAncestorQuery()).Distinct().Select(i => i.ToString("N")).ToArray();
}
// TODO: handle blocking by tags
@ -1634,9 +1645,9 @@ namespace MediaBrowser.Server.Implementations.Library
public IEnumerable<Folder> GetCollectionFolders(BaseItem item)
{
while (!(item.Parent is AggregateFolder) && item.Parent != null)
while (!(item.GetParent() is AggregateFolder) && item.GetParent() != null)
{
item = item.Parent;
item = item.GetParent();
}
if (item == null)
@ -1673,7 +1684,7 @@ namespace MediaBrowser.Server.Implementations.Library
return type;
}
return item.Parents
return item.GetParents()
.Select(GetConfiguredContentType)
.LastOrDefault(i => !string.IsNullOrWhiteSpace(i));
}
@ -1710,9 +1721,9 @@ namespace MediaBrowser.Server.Implementations.Library
private string GetTopFolderContentType(BaseItem item)
{
while (!(item.Parent is AggregateFolder) && item.Parent != null)
while (!(item.GetParent() is AggregateFolder) && item.GetParent() != null)
{
item = item.Parent;
item = item.GetParent();
}
if (item == null)

View File

@ -86,7 +86,7 @@ namespace MediaBrowser.Server.Implementations.Library
Genres = genreList.ToArray()
}, user, new string[] { });
}, new string[] { });
var genresDictionary = genreList.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

View File

@ -41,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.Library
item.Id = libraryManager.GetNewItemId(item.Path, item.GetType());
item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 ||
item.Parents.Any(i => i.IsLocked);
item.GetParents().Any(i => i.IsLocked);
// Make sure DateCreated and DateModified have values
var fileInfo = directoryService.GetFile(item.Path);
@ -78,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.Library
EnsureName(item, args.FileInfo);
item.IsLocked = item.Path.IndexOf("[dontfetchmeta]", StringComparison.OrdinalIgnoreCase) != -1 ||
item.Parents.Any(i => i.IsLocked);
item.GetParents().Any(i => i.IsLocked);
// Make sure DateCreated and DateModified have values
EnsureDates(fileSystem, item, args, true);

View File

@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return ResolveVideos<Video>(parent, files, directoryService, false);
}
if (parent is Series || parent.Parents.OfType<Series>().Any())
if (parent is Series || parent.GetParents().OfType<Series>().Any())
{
return null;
}

View File

@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
// Not officially supported but in some cases we can handle it.
if (season == null)
{
season = parent.Parents.OfType<Season>().FirstOrDefault();
season = parent.GetParents().OfType<Season>().FirstOrDefault();
}
// If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something

View File

@ -164,7 +164,7 @@ namespace MediaBrowser.Server.Implementations.Library
IncludeItemTypes = includeItemTypes.ToArray(),
Limit = query.Limit,
}, user, new string[] { });
}, new string[] { });
// Add search hints based on item name
hints.AddRange(mediaItems.Where(IncludeInSearch).Select(item =>

View File

@ -49,6 +49,15 @@ namespace MediaBrowser.Server.Implementations.Library
.OfType<Folder>()
.ToList();
if (!query.IncludeHidden)
{
folders = folders.Where(i =>
{
var hidden = i as IHiddenFromDisplay;
return hidden == null || !hidden.IsHiddenFromUser(user);
}).ToList();
}
var plainFolderIds = user.Configuration.PlainFolderViews.Select(i => new Guid(i)).ToList();
var standaloneFolders = folders
@ -121,7 +130,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (parents.Count > 0)
{
list.Add(await GetUserView(parents, list, CollectionType.TvShows, string.Empty, user, enableUserViews, cancellationToken).ConfigureAwait(false));
list.Add(await GetUserView(parents, CollectionType.TvShows, string.Empty, user, enableUserViews, cancellationToken).ConfigureAwait(false));
}
parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.GetViewType(user)))
@ -129,7 +138,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (parents.Count > 0)
{
list.Add(await GetUserView(parents, list, CollectionType.Movies, string.Empty, user, enableUserViews, cancellationToken).ConfigureAwait(false));
list.Add(await GetUserView(parents, CollectionType.Movies, string.Empty, user, enableUserViews, cancellationToken).ConfigureAwait(false));
}
if (user.Configuration.DisplayFoldersView)
@ -194,7 +203,7 @@ namespace MediaBrowser.Server.Implementations.Library
return GetUserSubView(name, parentId, type, sortName, cancellationToken);
}
private async Task<UserView> GetUserView(List<ICollectionFolder> parents, List<Folder> currentViews, string viewType, string sortName, User user, bool enableUserViews, CancellationToken cancellationToken)
private async Task<UserView> GetUserView(List<ICollectionFolder> parents, string viewType, string sortName, User user, bool enableUserViews, CancellationToken cancellationToken)
{
if (parents.Count == 1 && parents.All(i => string.Equals((enableUserViews ? i.GetViewType(user) : i.CollectionType), viewType, StringComparison.OrdinalIgnoreCase)))
{
@ -305,7 +314,7 @@ namespace MediaBrowser.Server.Implementations.Library
ExcludeLocationTypes = new[] { LocationType.Virtual },
Limit = limit * 20
}, user, parentIds);
}, parentIds);
}
}
}

View File

@ -1170,7 +1170,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var list = new List<LiveTvChannel>();
var numComplete = 0;
var folder = await GetInternalLiveTvFolder(cancellationToken).ConfigureAwait(false);
var parentFolder = await GetInternalLiveTvFolder(cancellationToken).ConfigureAwait(false);
var parentFolderId = parentFolder.Id;
foreach (var channelInfo in allChannelsList)
{
@ -1178,7 +1179,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
try
{
var item = await GetChannel(channelInfo.Item2, channelInfo.Item1, folder.Id, cancellationToken).ConfigureAwait(false);
var item = await GetChannel(channelInfo.Item2, channelInfo.Item1, parentFolderId, cancellationToken).ConfigureAwait(false);
list.Add(item);
@ -1390,7 +1391,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
internalQuery.ChannelIds = new[] { query.ChannelId };
}
var queryResult = _libraryManager.GetItems(internalQuery, user, new string[] { });
var queryResult = _libraryManager.GetItems(internalQuery, new string[] { });
IEnumerable<ILiveTvRecording> recordings = queryResult.Cast<ILiveTvRecording>();
if (!string.IsNullOrEmpty(query.Id))
@ -1802,7 +1803,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
Limit = 1,
SortBy = new[] { "StartDate" }
}, user, new string[] { }).Cast<LiveTvProgram>();
}, new string[] { }).Cast<LiveTvProgram>();
var currentProgram = programs.FirstOrDefault();
@ -1826,7 +1827,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
Limit = 1,
SortBy = new[] { "StartDate" }
}, user, new string[] { }).Cast<LiveTvProgram>();
}, new string[] { }).Cast<LiveTvProgram>();
var currentProgram = programs.FirstOrDefault();

View File

@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _updateInheritedRatingCommand;
private const int LatestSchemaVersion = 29;
private const int LatestSchemaVersion = 32;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
@ -136,7 +136,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
"create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))",
"create index if not exists idx_AncestorIds on AncestorIds(ItemId,AncestorId)",
"create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)",
"create index if not exists idx_AncestorIds2 on AncestorIds(AncestorIdText)",
"create table if not exists ChildrenIds (ParentId GUID, ItemId GUID, PRIMARY KEY (ParentId, ItemId))",
"create index if not exists idx_ChildrenIds on ChildrenIds(ParentId,ItemId)",

View File

@ -47,7 +47,7 @@ namespace MediaBrowser.Server.Implementations.Playlists
return subItem;
}
var parent = subItem.Parent;
var parent = subItem.GetParent();
if (parent != null && parent.HasImage(ImageType.Primary))
{

View File

@ -1621,17 +1621,17 @@ namespace MediaBrowser.Server.Implementations.Session
if (backropItem == null)
{
backropItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Backdrop));
backropItem = item.GetParents().FirstOrDefault(i => i.HasImage(ImageType.Backdrop));
}
if (thumbItem == null)
{
thumbItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Thumb));
thumbItem = item.GetParents().FirstOrDefault(i => i.HasImage(ImageType.Thumb));
}
if (logoItem == null)
{
logoItem = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Logo));
logoItem = item.GetParents().FirstOrDefault(i => i.HasImage(ImageType.Logo));
}
if (thumbItem != null)

View File

@ -341,7 +341,7 @@ namespace MediaBrowser.Server.Implementations.Sync
if (primaryImage == null)
{
var parentWithImage = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Primary));
var parentWithImage = item.GetParents().FirstOrDefault(i => i.HasImage(ImageType.Primary));
if (parentWithImage != null)
{
@ -380,7 +380,7 @@ namespace MediaBrowser.Server.Implementations.Sync
if (primaryImage == null)
{
var parentWithImage = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Primary));
var parentWithImage = item.GetParents().FirstOrDefault(i => i.HasImage(ImageType.Primary));
if (parentWithImage != null)
{

View File

@ -41,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.TV
IncludeItemTypes = new[] { typeof(Series).Name },
SortOrder = SortOrder.Ascending
}, user, parentIds).Cast<Series>();
}, parentIds).Cast<Series>();
// Avoid implicitly captured closure
var episodes = GetNextUpEpisodes(request, user, items);
@ -63,7 +63,7 @@ namespace MediaBrowser.Server.Implementations.TV
IncludeItemTypes = new[] { typeof(Series).Name },
SortOrder = SortOrder.Ascending
}, user, parentsFolders.Select(i => i.Id.ToString("N"))).Cast<Series>();
}, parentsFolders.Select(i => i.Id.ToString("N"))).Cast<Series>();
// Avoid implicitly captured closure
var episodes = GetNextUpEpisodes(request, user, items);

View File

@ -419,7 +419,7 @@ namespace MediaBrowser.Server.Startup.Common
UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager);
RegisterSingleInstance(UserManager);
LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager);
LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager);
RegisterSingleInstance(LibraryManager);
var musicManager = new MusicManager(LibraryManager);