update DisplayParent

This commit is contained in:
Luke Pulverenti 2016-04-09 00:16:53 -04:00
parent a95cbac076
commit 2ec515027f
11 changed files with 67 additions and 350 deletions

View File

@ -1,101 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
namespace MediaBrowser.Controller.Channels
{
public class ChannelAudioItem : Audio
{
public ChannelMediaContentType ContentType { get; set; }
public List<ChannelMediaInfo> ChannelMediaSources { get; set; }
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.ChannelContent;
}
protected override string CreateUserDataKey()
{
return ExternalId;
}
[IgnoreDataMember]
public override bool SupportsLocalMetadata
{
get
{
return false;
}
}
public override bool IsSaveLocalMetadataEnabled()
{
return false;
}
public ChannelAudioItem()
{
ChannelMediaSources = new List<ChannelMediaInfo>();
}
[IgnoreDataMember]
public override LocationType LocationType
{
get
{
if (string.IsNullOrEmpty(Path))
{
return LocationType.Remote;
}
return base.LocationType;
}
}
protected override string GetInternalMetadataPath(string basePath)
{
return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
}
public override IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
{
var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None)
.Result.ToList();
if (sources.Count > 0)
{
return sources;
}
var list = base.GetMediaSources(enablePathSubstitution).ToList();
foreach (var mediaSource in list)
{
if (string.IsNullOrWhiteSpace(mediaSource.Path))
{
mediaSource.Type = MediaSourceType.Placeholder;
}
}
return list;
}
public override bool CanDelete()
{
return false;
}
public override bool IsVisibleStandalone(User user)
{
return IsVisibleStandaloneInternal(user, false) && ChannelVideoItem.IsChannelVisible(this, user);
}
}
}

View File

@ -1,89 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Users;
using System;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Configuration;
namespace MediaBrowser.Controller.Channels
{
public class ChannelFolderItem : Folder
{
public ChannelFolderType ChannelFolderType { get; set; }
protected override bool GetBlockUnratedValue(UserPolicy config)
{
// Don't block.
return false;
}
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.ChannelContent;
}
[IgnoreDataMember]
public override bool SupportsLocalMetadata
{
get
{
return false;
}
}
public override bool IsSaveLocalMetadataEnabled()
{
return false;
}
protected override string CreateUserDataKey()
{
return ExternalId;
}
protected override async Task<QueryResult<BaseItem>> GetItemsInternal(InternalItemsQuery query)
{
try
{
// Don't blow up here because it could cause parent screens with other content to fail
return await ChannelManager.GetChannelItemsInternal(new ChannelItemQuery
{
ChannelId = ChannelId,
FolderId = Id.ToString("N"),
Limit = query.Limit,
StartIndex = query.StartIndex,
UserId = query.User.Id.ToString("N"),
SortBy = query.SortBy,
SortOrder = query.SortOrder
}, new Progress<double>(), CancellationToken.None);
}
catch
{
// Already logged at lower levels
return new QueryResult<BaseItem>
{
};
}
}
protected override string GetInternalMetadataPath(string basePath)
{
return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
}
public override bool CanDelete()
{
return false;
}
public override bool IsVisibleStandalone(User user)
{
return IsVisibleStandaloneInternal(user, false) && ChannelVideoItem.IsChannelVisible(this, user);
}
}
}

View File

@ -1,126 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
namespace MediaBrowser.Controller.Channels
{
public class ChannelVideoItem : Video
{
public ChannelMediaContentType ContentType { get; set; }
public List<ChannelMediaInfo> ChannelMediaSources { get; set; }
protected override string CreateUserDataKey()
{
if (ContentType == ChannelMediaContentType.MovieExtra)
{
var key = this.GetProviderId(MetadataProviders.Imdb) ?? this.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrWhiteSpace(key))
{
key = key + "-" + ExtraType.ToString().ToLower();
// Make sure different trailers have their own data.
if (RunTimeTicks.HasValue)
{
key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
}
return key;
}
}
return ExternalId;
}
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.ChannelContent;
}
[IgnoreDataMember]
public override bool SupportsLocalMetadata
{
get
{
return false;
}
}
public override bool IsSaveLocalMetadataEnabled()
{
return false;
}
public ChannelVideoItem()
{
ChannelMediaSources = new List<ChannelMediaInfo>();
}
[IgnoreDataMember]
public override LocationType LocationType
{
get
{
if (string.IsNullOrEmpty(Path))
{
return LocationType.Remote;
}
return base.LocationType;
}
}
public override IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
{
var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None)
.Result.ToList();
if (sources.Count > 0)
{
return sources;
}
var list = base.GetMediaSources(enablePathSubstitution).ToList();
foreach (var mediaSource in list)
{
if (string.IsNullOrWhiteSpace(mediaSource.Path))
{
mediaSource.Type = MediaSourceType.Placeholder;
}
}
return list;
}
protected override string GetInternalMetadataPath(string basePath)
{
return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
}
public override bool CanDelete()
{
return false;
}
public override bool IsVisibleStandalone(User user)
{
return IsVisibleStandaloneInternal(user, false) && IsChannelVisible(this, user);
}
internal static bool IsChannelVisible(BaseItem item, User user)
{
var channel = ChannelManager.GetChannel(item.ChannelId);
return channel.IsVisible(user);
}
}
}

View File

@ -306,7 +306,7 @@ namespace MediaBrowser.Controller.Entities
}
}
private List<Tuple<StringBuilder,bool>> GetSortChunks(string s1)
private List<Tuple<StringBuilder, bool>> GetSortChunks(string s1)
{
var list = new List<Tuple<StringBuilder, bool>>();
@ -668,9 +668,30 @@ namespace MediaBrowser.Controller.Entities
}
[IgnoreDataMember]
public virtual BaseItem DisplayParent
public virtual Guid? DisplayParentId
{
get { return GetParent(); }
get
{
if (ParentId == Guid.Empty)
{
return null;
}
return ParentId;
}
}
[IgnoreDataMember]
public BaseItem DisplayParent
{
get
{
var id = DisplayParentId;
if (!id.HasValue)
{
return null;
}
return LibraryManager.GetItemById(id.Value);
}
}
/// <summary>
@ -1454,7 +1475,7 @@ namespace MediaBrowser.Controller.Entities
public virtual string GetClientTypeName()
{
if (IsFolder && SourceType == SourceType.Channel)
if (IsFolder && SourceType == SourceType.Channel && !(this is Channel))
{
return "ChannelFolderItem";
}

View File

@ -1,6 +1,7 @@
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Controller.Entities
{
@ -18,11 +19,20 @@ namespace MediaBrowser.Controller.Entities
/// <value>The local trailer ids.</value>
List<Guid> LocalTrailerIds { get; set; }
List<Guid> RemoteTrailerIds { get; set; }
}
public static class HasTrailerExtensions
{
/// <summary>
/// Gets the trailer ids.
/// </summary>
/// <returns>List&lt;Guid&gt;.</returns>
List<Guid> GetTrailerIds();
public static List<Guid> GetTrailerIds(this IHasTrailers item)
{
var list = item.LocalTrailerIds.ToList();
list.AddRange(item.RemoteTrailerIds);
return list;
}
}
}

View File

@ -78,17 +78,6 @@ namespace MediaBrowser.Controller.Entities.Movies
set { TmdbCollectionName = value; }
}
/// <summary>
/// Gets the trailer ids.
/// </summary>
/// <returns>List&lt;Guid&gt;.</returns>
public List<Guid> GetTrailerIds()
{
var list = LocalTrailerIds.ToList();
list.AddRange(RemoteTrailerIds);
return list;
}
/// <summary>
/// Gets the user data key.
/// </summary>

View File

@ -90,11 +90,11 @@ namespace MediaBrowser.Controller.Entities.TV
}
[IgnoreDataMember]
public override BaseItem DisplayParent
public override Guid? DisplayParentId
{
get
{
return Season ?? GetParent();
return SeasonId;
}
}

View File

@ -33,9 +33,13 @@ namespace MediaBrowser.Controller.Entities.TV
}
[IgnoreDataMember]
public override BaseItem DisplayParent
public override Guid? DisplayParentId
{
get { return Series ?? GetParent(); }
get
{
var series = Series;
return series == null ? ParentId : series.Id;
}
}
// Genre, Rating and Stuido will all be the same

View File

@ -75,15 +75,12 @@
</Compile>
<Compile Include="Activity\IActivityManager.cs" />
<Compile Include="Activity\IActivityRepository.cs" />
<Compile Include="Channels\ChannelAudioItem.cs" />
<Compile Include="Channels\ChannelFolderItem.cs" />
<Compile Include="Channels\ChannelItemInfo.cs" />
<Compile Include="Channels\ChannelItemResult.cs" />
<Compile Include="Channels\ChannelItemType.cs" />
<Compile Include="Channels\ChannelMediaInfo.cs" />
<Compile Include="Channels\ChannelParentalRating.cs" />
<Compile Include="Channels\ChannelSearchInfo.cs" />
<Compile Include="Channels\ChannelVideoItem.cs" />
<Compile Include="Channels\IChannel.cs" />
<Compile Include="Channels\IChannelManager.cs" />
<Compile Include="Channels\Channel.cs" />

View File

@ -93,10 +93,10 @@ namespace MediaBrowser.Dlna.Didl
}
else
{
var parent = item.DisplayParent;
if (parent != null)
var parent = item.DisplayParentId;
if (parent.HasValue)
{
element.SetAttribute("parentID", GetClientId(parent, null));
element.SetAttribute("parentID", GetClientId(parent.Value, null));
}
}
@ -499,14 +499,21 @@ namespace MediaBrowser.Dlna.Didl
{
container.SetAttribute("id", clientId);
var parent = context ?? folder.DisplayParent;
if (parent == null)
if (context != null)
{
container.SetAttribute("parentID", "0");
container.SetAttribute("parentID", GetClientId(context, null));
}
else
{
container.SetAttribute("parentID", GetClientId(parent, null));
var parent = folder.DisplayParentId;
if (!parent.HasValue)
{
container.SetAttribute("parentID", "0");
}
else
{
container.SetAttribute("parentID", GetClientId(parent.Value, null));
}
}
}
@ -1059,7 +1066,12 @@ namespace MediaBrowser.Dlna.Didl
public static string GetClientId(BaseItem item, StubType? stubType)
{
var id = item.Id.ToString("N");
return GetClientId(item.Id, stubType);
}
public static string GetClientId(Guid idValue, StubType? stubType)
{
var id = idValue.ToString("N");
if (stubType.HasValue)
{

View File

@ -1149,10 +1149,10 @@ namespace MediaBrowser.Server.Implementations.Dto
if (fields.Contains(ItemFields.ParentId))
{
var displayParent = item.DisplayParent;
if (displayParent != null)
var displayParentId = item.DisplayParentId;
if (displayParentId.HasValue)
{
dto.ParentId = GetDtoId(displayParent);
dto.ParentId = displayParentId.Value.ToString("N");
}
}