finish removing ChannelFolderItem

This commit is contained in:
Luke Pulverenti 2016-03-19 01:04:38 -04:00
parent cbac67b5ae
commit 7b93b7a33c
17 changed files with 184 additions and 105 deletions

View File

@ -3,6 +3,7 @@ using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using System; using System;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -30,6 +31,13 @@ namespace MediaBrowser.Controller.Channels
return base.IsVisible(user); return base.IsVisible(user);
} }
[IgnoreDataMember]
public override SourceType SourceType
{
get { return SourceType.Channel; }
set { }
}
public override async Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query) public override async Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query)
{ {
try try

View File

@ -37,6 +37,12 @@ namespace MediaBrowser.Controller.Channels
} }
} }
[IgnoreDataMember]
public override SourceType SourceType {
get { return SourceType.Channel; }
set { }
}
public override bool IsSaveLocalMetadataEnabled() public override bool IsSaveLocalMetadataEnabled()
{ {
return false; return false;

View File

@ -1,90 +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;
using MediaBrowser.Model.Entities;
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;
}
public override async Task<QueryResult<BaseItem>> GetItems(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

@ -47,6 +47,13 @@ namespace MediaBrowser.Controller.Channels
return UnratedItem.ChannelContent; return UnratedItem.ChannelContent;
} }
[IgnoreDataMember]
public override SourceType SourceType
{
get { return SourceType.Channel; }
set { }
}
[IgnoreDataMember] [IgnoreDataMember]
public override bool SupportsLocalMetadata public override bool SupportsLocalMetadata
{ {

View File

@ -170,7 +170,7 @@ namespace MediaBrowser.Controller.Entities
public bool IsOffline { get; set; } public bool IsOffline { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public SourceType SourceType { get; set; } public virtual SourceType SourceType { get; set; }
/// <summary> /// <summary>
/// Returns the folder containing the item. /// Returns the folder containing the item.
@ -258,6 +258,11 @@ namespace MediaBrowser.Controller.Entities
{ {
get get
{ {
if (SourceType == SourceType.Channel)
{
return false;
}
var locationType = LocationType; var locationType = LocationType;
return locationType != LocationType.Remote && locationType != LocationType.Virtual; return locationType != LocationType.Remote && locationType != LocationType.Virtual;
@ -304,6 +309,11 @@ namespace MediaBrowser.Controller.Entities
public virtual bool CanDelete() public virtual bool CanDelete()
{ {
if (SourceType == SourceType.Channel)
{
return false;
}
var locationType = LocationType; var locationType = LocationType;
return locationType != LocationType.Remote && return locationType != LocationType.Remote &&
locationType != LocationType.Virtual; locationType != LocationType.Virtual;
@ -463,6 +473,11 @@ namespace MediaBrowser.Controller.Entities
protected virtual string GetInternalMetadataPath(string basePath) protected virtual string GetInternalMetadataPath(string basePath)
{ {
if (SourceType == SourceType.Channel)
{
return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
}
var idString = Id.ToString("N"); var idString = Id.ToString("N");
basePath = System.IO.Path.Combine(basePath, "library"); basePath = System.IO.Path.Combine(basePath, "library");
@ -1035,6 +1050,13 @@ namespace MediaBrowser.Controller.Entities
protected virtual string CreateUserDataKey() protected virtual string CreateUserDataKey()
{ {
if (SourceType == SourceType.Channel)
{
if (!string.IsNullOrWhiteSpace(ExternalId))
{
return ExternalId;
}
}
return Id.ToString(); return Id.ToString();
} }
@ -1113,6 +1135,11 @@ namespace MediaBrowser.Controller.Entities
public virtual bool IsSaveLocalMetadataEnabled() public virtual bool IsSaveLocalMetadataEnabled()
{ {
if (SourceType == SourceType.Channel)
{
return false;
}
return ConfigurationManager.Configuration.SaveLocalMeta; return ConfigurationManager.Configuration.SaveLocalMeta;
} }
@ -1228,6 +1255,11 @@ namespace MediaBrowser.Controller.Entities
public virtual UnratedItem GetBlockUnratedType() public virtual UnratedItem GetBlockUnratedType()
{ {
if (SourceType == SourceType.Channel)
{
return UnratedItem.ChannelContent;
}
return UnratedItem.Other; return UnratedItem.Other;
} }
@ -1271,6 +1303,11 @@ namespace MediaBrowser.Controller.Entities
public virtual bool IsVisibleStandalone(User user) public virtual bool IsVisibleStandalone(User user)
{ {
if (SourceType == SourceType.Channel)
{
return IsVisibleStandaloneInternal(user, false) && ChannelVideoItem.IsChannelVisible(this, user);
}
return IsVisibleStandaloneInternal(user, true); return IsVisibleStandaloneInternal(user, true);
} }

View File

@ -15,6 +15,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommonIO; using CommonIO;
using MediaBrowser.Common.IO; using MediaBrowser.Common.IO;
using MediaBrowser.Model.Channels;
namespace MediaBrowser.Controller.Entities namespace MediaBrowser.Controller.Entities
{ {
@ -794,8 +795,35 @@ namespace MediaBrowser.Controller.Entities
return item; return item;
} }
public virtual Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query) public virtual async Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query)
{ {
if (SourceType == SourceType.Channel)
{
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>
{
};
}
}
var user = query.User; var user = query.User;
Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
@ -817,7 +845,7 @@ namespace MediaBrowser.Controller.Entities
var result = PostFilterAndSort(items, query); var result = PostFilterAndSort(items, query);
return Task.FromResult(result); return result;
} }
protected QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items, InternalItemsQuery query) protected QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items, InternalItemsQuery query)

View File

@ -115,6 +115,7 @@ namespace MediaBrowser.Controller.Entities
public LocationType[] ExcludeLocationTypes { get; set; } public LocationType[] ExcludeLocationTypes { get; set; }
public string[] PresetViews { get; set; } public string[] PresetViews { get; set; }
public SourceType[] SourceTypes { get; set; }
public InternalItemsQuery() public InternalItemsQuery()
{ {
@ -141,6 +142,7 @@ namespace MediaBrowser.Controller.Entities
ExcludeTags = new string[] { }; ExcludeTags = new string[] { };
ExcludeLocationTypes = new LocationType[] { }; ExcludeLocationTypes = new LocationType[] { };
PresetViews = new string[] { }; PresetViews = new string[] { };
SourceTypes = new SourceType[] { };
} }
public InternalItemsQuery(User user) public InternalItemsQuery(User user)

View File

@ -39,6 +39,13 @@ namespace MediaBrowser.Controller.LiveTv
[IgnoreDataMember] [IgnoreDataMember]
public bool IsPremiere { get; set; } public bool IsPremiere { get; set; }
[IgnoreDataMember]
public override SourceType SourceType
{
get { return SourceType.LiveTV; }
set { }
}
/// <summary> /// <summary>
/// Gets the user data key. /// Gets the user data key.
/// </summary> /// </summary>

View File

@ -40,6 +40,13 @@ namespace MediaBrowser.Controller.LiveTv
} }
} }
[IgnoreDataMember]
public override SourceType SourceType
{
get { return SourceType.LiveTV; }
set { }
}
/// <summary> /// <summary>
/// Gets or sets the number. /// Gets or sets the number.
/// </summary> /// </summary>

View File

@ -46,6 +46,13 @@ namespace MediaBrowser.Controller.LiveTv
[IgnoreDataMember] [IgnoreDataMember]
public string ServiceName { get; set; } public string ServiceName { get; set; }
[IgnoreDataMember]
public override SourceType SourceType
{
get { return SourceType.LiveTV; }
set { }
}
/// <summary> /// <summary>
/// The start date of the program, in UTC. /// The start date of the program, in UTC.
/// </summary> /// </summary>

View File

@ -39,6 +39,13 @@ namespace MediaBrowser.Controller.LiveTv
[IgnoreDataMember] [IgnoreDataMember]
public bool IsPremiere { get; set; } public bool IsPremiere { get; set; }
[IgnoreDataMember]
public override SourceType SourceType
{
get { return SourceType.LiveTV; }
set { }
}
/// <summary> /// <summary>
/// Gets the user data key. /// Gets the user data key.
/// </summary> /// </summary>

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities; using System.Runtime.Serialization;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Users; using MediaBrowser.Model.Users;
@ -24,5 +25,12 @@ namespace MediaBrowser.Controller.LiveTv
return false; return false;
} }
} }
[IgnoreDataMember]
public override SourceType SourceType
{
get { return SourceType.LiveTV; }
set { }
}
} }
} }

View File

@ -75,7 +75,6 @@
</Compile> </Compile>
<Compile Include="Activity\IActivityManager.cs" /> <Compile Include="Activity\IActivityManager.cs" />
<Compile Include="Activity\IActivityRepository.cs" /> <Compile Include="Activity\IActivityRepository.cs" />
<Compile Include="Channels\ChannelFolderItem.cs" />
<Compile Include="Channels\ChannelItemInfo.cs" /> <Compile Include="Channels\ChannelItemInfo.cs" />
<Compile Include="Channels\ChannelItemResult.cs" /> <Compile Include="Channels\ChannelItemResult.cs" />
<Compile Include="Channels\ChannelItemType.cs" /> <Compile Include="Channels\ChannelItemType.cs" />

View File

@ -26,6 +26,7 @@ using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommonIO; using CommonIO;
using MediaBrowser.Controller.Entities.Audio;
namespace MediaBrowser.Server.Implementations.Channels namespace MediaBrowser.Server.Implementations.Channels
{ {
@ -1243,7 +1244,18 @@ namespace MediaBrowser.Server.Implementations.Channels
if (info.Type == ChannelItemType.Folder) if (info.Type == ChannelItemType.Folder)
{ {
item = GetItemById<ChannelFolderItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); if (info.FolderType == ChannelFolderType.MusicAlbum)
{
item = GetItemById<MusicAlbum>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew);
}
else if (info.FolderType == ChannelFolderType.PhotoAlbum)
{
item = GetItemById<PhotoAlbum>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew);
}
else
{
item = GetItemById<Folder>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew);
}
} }
else if (info.MediaType == ChannelMediaType.Audio) else if (info.MediaType == ChannelMediaType.Audio)
{ {
@ -1314,6 +1326,12 @@ namespace MediaBrowser.Server.Implementations.Channels
item.SetImagePath(ImageType.Primary, info.ImageUrl); item.SetImagePath(ImageType.Primary, info.ImageUrl);
} }
if (item.SourceType != SourceType.Channel)
{
item.SourceType = SourceType.Channel;
forceUpdate = true;
}
if (isNew) if (isNew)
{ {
await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);

View File

@ -1534,9 +1534,13 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.ChannelId = item.ChannelId; dto.ChannelId = item.ChannelId;
if (item.SourceType == SourceType.Channel) if (item.SourceType == SourceType.Channel && !string.IsNullOrWhiteSpace(item.ChannelId))
{ {
dto.ChannelName = _channelManagerFactory().GetChannel(item.ChannelId).Name; var channel = _libraryManager.GetItemById(item.ChannelId);
if (channel != null)
{
dto.ChannelName = channel.Name;
}
} }
} }

View File

@ -80,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Library
list.Add(folder); list.Add(folder);
continue; continue;
} }
if (collectionFolder != null && UserView.IsEligibleForGrouping(folder) && user.IsFolderGrouped(folder.Id)) if (collectionFolder != null && UserView.IsEligibleForGrouping(folder) && user.IsFolderGrouped(folder.Id))
{ {
groupedFolders.Add(collectionFolder); groupedFolders.Add(collectionFolder);
@ -272,7 +272,11 @@ namespace MediaBrowser.Server.Implementations.Library
.ToArray(); .ToArray();
} }
var excludeItemTypes = includeItemTypes.Length == 0 ? new[] { "ChannelItem", "LiveTvItem", typeof(Person).Name, typeof(Studio).Name, typeof(Year).Name, typeof(GameGenre).Name, typeof(MusicGenre).Name, typeof(Genre).Name } : new string[] { }; var excludeItemTypes = includeItemTypes.Length == 0 ? new[]
{
typeof(Person).Name, typeof(Studio).Name, typeof(Year).Name, typeof(GameGenre).Name, typeof(MusicGenre).Name, typeof(Genre).Name
} : new string[] { };
return _libraryManager.GetItems(new InternalItemsQuery(user) return _libraryManager.GetItems(new InternalItemsQuery(user)
{ {
@ -282,7 +286,8 @@ namespace MediaBrowser.Server.Implementations.Library
IsFolder = includeItemTypes.Length == 0 ? false : (bool?)null, IsFolder = includeItemTypes.Length == 0 ? false : (bool?)null,
ExcludeItemTypes = excludeItemTypes, ExcludeItemTypes = excludeItemTypes,
ExcludeLocationTypes = new[] { LocationType.Virtual }, ExcludeLocationTypes = new[] { LocationType.Virtual },
Limit = limit * 20 Limit = limit * 20,
SourceTypes = new[] { SourceType.Library }
}, parentIds); }, parentIds);
} }

View File

@ -223,6 +223,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection.AddColumn(Logger, "TypedBaseItems", "UnratedType", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "UnratedType", "Text");
_connection.AddColumn(Logger, "TypedBaseItems", "TopParentId", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "TopParentId", "Text");
_connection.AddColumn(Logger, "TypedBaseItems", "IsItemByName", "BIT"); _connection.AddColumn(Logger, "TypedBaseItems", "IsItemByName", "BIT");
_connection.AddColumn(Logger, "TypedBaseItems", "SourceType", "Text");
PrepareStatements(); PrepareStatements();
@ -353,7 +354,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"DateLastSaved", "DateLastSaved",
"LockedFields", "LockedFields",
"Studios", "Studios",
"Tags" "Tags",
"SourceType"
}; };
private readonly string[] _mediaStreamSaveColumns = private readonly string[] _mediaStreamSaveColumns =
@ -453,7 +455,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"IsFolder", "IsFolder",
"UnratedType", "UnratedType",
"TopParentId", "TopParentId",
"IsItemByName" "IsItemByName",
"SourceType"
}; };
_saveItemCommand = _connection.CreateCommand(); _saveItemCommand = _connection.CreateCommand();
_saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
@ -747,6 +750,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
} }
_saveItemCommand.GetParameter(index++).Value = isByName; _saveItemCommand.GetParameter(index++).Value = isByName;
_saveItemCommand.GetParameter(index++).Value = item.SourceType.ToString();
_saveItemCommand.Transaction = transaction; _saveItemCommand.Transaction = transaction;
_saveItemCommand.ExecuteNonQuery(); _saveItemCommand.ExecuteNonQuery();
@ -1109,6 +1114,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
item.Tags = reader.GetString(48).Split('|').Where(i => !string.IsNullOrWhiteSpace(i)).ToList(); item.Tags = reader.GetString(48).Split('|').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();
} }
if (!reader.IsDBNull(49))
{
item.SourceType = (SourceType)Enum.Parse(typeof(SourceType), reader.GetString(49), true);
}
return item; return item;
} }
@ -1871,6 +1881,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.Parameters.Add(cmd, "@MaxStartDate", DbType.Date).Value = query.MaxStartDate.Value; cmd.Parameters.Add(cmd, "@MaxStartDate", DbType.Date).Value = query.MaxStartDate.Value;
} }
if (query.SourceTypes.Length == 1)
{
whereClauses.Add("SourceType=@SourceType");
cmd.Parameters.Add(cmd, "@SourceType", DbType.String).Value = query.SourceTypes[0];
}
else if (query.SourceTypes.Length > 1)
{
var inClause = string.Join(",", query.SourceTypes.Select(i => "'" + i + "'").ToArray());
whereClauses.Add(string.Format("SourceType in ({0})", inClause));
}
if (query.IsAiring.HasValue) if (query.IsAiring.HasValue)
{ {
if (query.IsAiring.Value) if (query.IsAiring.Value)
@ -2152,8 +2173,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
dict[t.Name] = new[] { t.FullName }; dict[t.Name] = new[] { t.FullName };
} }
dict["ChannelItem"] = new[] { typeof(ChannelVideoItem).FullName, typeof(ChannelAudioItem).FullName, typeof(ChannelFolderItem).FullName };
dict["LiveTvItem"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName, typeof(LiveTvChannel).FullName, typeof(LiveTvProgram).FullName };
dict["Recording"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName }; dict["Recording"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName };
dict["Program"] = new[] { typeof(LiveTvProgram).FullName }; dict["Program"] = new[] { typeof(LiveTvProgram).FullName };
dict["TvChannel"] = new[] { typeof(LiveTvChannel).FullName }; dict["TvChannel"] = new[] { typeof(LiveTvChannel).FullName };