From 7b93b7a33c9c5d099759d6f9a9ca66c08029e94e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Mar 2016 01:04:38 -0400 Subject: [PATCH] finish removing ChannelFolderItem --- MediaBrowser.Controller/Channels/Channel.cs | 8 ++ .../Channels/ChannelAudioItem.cs | 6 ++ .../Channels/ChannelFolderItem.cs | 90 ------------------- .../Channels/ChannelVideoItem.cs | 7 ++ MediaBrowser.Controller/Entities/BaseItem.cs | 39 +++++++- MediaBrowser.Controller/Entities/Folder.cs | 32 ++++++- .../Entities/InternalItemsQuery.cs | 2 + .../LiveTv/LiveTvAudioRecording.cs | 7 ++ .../LiveTv/LiveTvChannel.cs | 7 ++ .../LiveTv/LiveTvProgram.cs | 7 ++ .../LiveTv/LiveTvVideoRecording.cs | 7 ++ .../LiveTv/RecordingGroup.cs | 10 ++- .../MediaBrowser.Controller.csproj | 1 - .../Channels/ChannelManager.cs | 20 ++++- .../Dto/DtoService.cs | 8 +- .../Library/UserViewManager.cs | 11 ++- .../Persistence/SqliteItemRepository.cs | 27 +++++- 17 files changed, 184 insertions(+), 105 deletions(-) delete mode 100644 MediaBrowser.Controller/Channels/ChannelFolderItem.cs diff --git a/MediaBrowser.Controller/Channels/Channel.cs b/MediaBrowser.Controller/Channels/Channel.cs index 839b7d68f..ff1bd7ff4 100644 --- a/MediaBrowser.Controller/Channels/Channel.cs +++ b/MediaBrowser.Controller/Channels/Channel.cs @@ -3,6 +3,7 @@ using MediaBrowser.Model.Channels; using MediaBrowser.Model.Querying; using System; using System.Linq; +using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; @@ -30,6 +31,13 @@ namespace MediaBrowser.Controller.Channels return base.IsVisible(user); } + [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.Channel; } + set { } + } + public override async Task> GetItems(InternalItemsQuery query) { try diff --git a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs b/MediaBrowser.Controller/Channels/ChannelAudioItem.cs index bcb2dc234..b4a9db8b3 100644 --- a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelAudioItem.cs @@ -37,6 +37,12 @@ namespace MediaBrowser.Controller.Channels } } + [IgnoreDataMember] + public override SourceType SourceType { + get { return SourceType.Channel; } + set { } + } + public override bool IsSaveLocalMetadataEnabled() { return false; diff --git a/MediaBrowser.Controller/Channels/ChannelFolderItem.cs b/MediaBrowser.Controller/Channels/ChannelFolderItem.cs deleted file mode 100644 index 174cd282a..000000000 --- a/MediaBrowser.Controller/Channels/ChannelFolderItem.cs +++ /dev/null @@ -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> 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(), CancellationToken.None); - } - catch - { - // Already logged at lower levels - return new QueryResult - { - - }; - } - } - - 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); - } - } -} diff --git a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs index c15b345b5..7b4bc6fbe 100644 --- a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs @@ -47,6 +47,13 @@ namespace MediaBrowser.Controller.Channels return UnratedItem.ChannelContent; } + [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.Channel; } + set { } + } + [IgnoreDataMember] public override bool SupportsLocalMetadata { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index d607facf1..04c887dca 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -170,7 +170,7 @@ namespace MediaBrowser.Controller.Entities public bool IsOffline { get; set; } [IgnoreDataMember] - public SourceType SourceType { get; set; } + public virtual SourceType SourceType { get; set; } /// /// Returns the folder containing the item. @@ -258,6 +258,11 @@ namespace MediaBrowser.Controller.Entities { get { + if (SourceType == SourceType.Channel) + { + return false; + } + var locationType = LocationType; return locationType != LocationType.Remote && locationType != LocationType.Virtual; @@ -304,6 +309,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool CanDelete() { + if (SourceType == SourceType.Channel) + { + return false; + } + var locationType = LocationType; return locationType != LocationType.Remote && locationType != LocationType.Virtual; @@ -463,6 +473,11 @@ namespace MediaBrowser.Controller.Entities 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"); basePath = System.IO.Path.Combine(basePath, "library"); @@ -1035,6 +1050,13 @@ namespace MediaBrowser.Controller.Entities protected virtual string CreateUserDataKey() { + if (SourceType == SourceType.Channel) + { + if (!string.IsNullOrWhiteSpace(ExternalId)) + { + return ExternalId; + } + } return Id.ToString(); } @@ -1113,6 +1135,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool IsSaveLocalMetadataEnabled() { + if (SourceType == SourceType.Channel) + { + return false; + } + return ConfigurationManager.Configuration.SaveLocalMeta; } @@ -1228,6 +1255,11 @@ namespace MediaBrowser.Controller.Entities public virtual UnratedItem GetBlockUnratedType() { + if (SourceType == SourceType.Channel) + { + return UnratedItem.ChannelContent; + } + return UnratedItem.Other; } @@ -1271,6 +1303,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool IsVisibleStandalone(User user) { + if (SourceType == SourceType.Channel) + { + return IsVisibleStandaloneInternal(user, false) && ChannelVideoItem.IsChannelVisible(this, user); + } + return IsVisibleStandaloneInternal(user, true); } diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 824a067ad..e6db695aa 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -15,6 +15,7 @@ using System.Threading; using System.Threading.Tasks; using CommonIO; using MediaBrowser.Common.IO; +using MediaBrowser.Model.Channels; namespace MediaBrowser.Controller.Entities { @@ -794,8 +795,35 @@ namespace MediaBrowser.Controller.Entities return item; } - public virtual Task> GetItems(InternalItemsQuery query) + public virtual async Task> 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(), CancellationToken.None); + } + catch + { + // Already logged at lower levels + return new QueryResult + { + + }; + } + } + var user = query.User; Func filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); @@ -817,7 +845,7 @@ namespace MediaBrowser.Controller.Entities var result = PostFilterAndSort(items, query); - return Task.FromResult(result); + return result; } protected QueryResult PostFilterAndSort(IEnumerable items, InternalItemsQuery query) diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 8b623d64e..56f1e8a66 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -115,6 +115,7 @@ namespace MediaBrowser.Controller.Entities public LocationType[] ExcludeLocationTypes { get; set; } public string[] PresetViews { get; set; } + public SourceType[] SourceTypes { get; set; } public InternalItemsQuery() { @@ -141,6 +142,7 @@ namespace MediaBrowser.Controller.Entities ExcludeTags = new string[] { }; ExcludeLocationTypes = new LocationType[] { }; PresetViews = new string[] { }; + SourceTypes = new SourceType[] { }; } public InternalItemsQuery(User user) diff --git a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs index 6f72ae1fb..04e19c92a 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs @@ -39,6 +39,13 @@ namespace MediaBrowser.Controller.LiveTv [IgnoreDataMember] public bool IsPremiere { get; set; } + [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.LiveTV; } + set { } + } + /// /// Gets the user data key. /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs index 8c4ee92cd..bc0b40b30 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs @@ -40,6 +40,13 @@ namespace MediaBrowser.Controller.LiveTv } } + [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.LiveTV; } + set { } + } + /// /// Gets or sets the number. /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs index fcd065e79..c01df7464 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs @@ -46,6 +46,13 @@ namespace MediaBrowser.Controller.LiveTv [IgnoreDataMember] public string ServiceName { get; set; } + [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.LiveTV; } + set { } + } + /// /// The start date of the program, in UTC. /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs index ce0c69dee..f298e89b7 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs @@ -39,6 +39,13 @@ namespace MediaBrowser.Controller.LiveTv [IgnoreDataMember] public bool IsPremiere { get; set; } + [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.LiveTV; } + set { } + } + /// /// Gets the user data key. /// diff --git a/MediaBrowser.Controller/LiveTv/RecordingGroup.cs b/MediaBrowser.Controller/LiveTv/RecordingGroup.cs index 2d58ef67f..5c86de08b 100644 --- a/MediaBrowser.Controller/LiveTv/RecordingGroup.cs +++ b/MediaBrowser.Controller/LiveTv/RecordingGroup.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using System.Runtime.Serialization; +using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Users; @@ -24,5 +25,12 @@ namespace MediaBrowser.Controller.LiveTv return false; } } + + [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.LiveTV; } + set { } + } } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 7078b04cf..5dbb0ac69 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -75,7 +75,6 @@ - diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index d219e270b..b4c6ae724 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -26,6 +26,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Entities.Audio; namespace MediaBrowser.Server.Implementations.Channels { @@ -1243,7 +1244,18 @@ namespace MediaBrowser.Server.Implementations.Channels if (info.Type == ChannelItemType.Folder) { - item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + if (info.FolderType == ChannelFolderType.MusicAlbum) + { + item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + } + else if (info.FolderType == ChannelFolderType.PhotoAlbum) + { + item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + } + else + { + item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + } } else if (info.MediaType == ChannelMediaType.Audio) { @@ -1314,6 +1326,12 @@ namespace MediaBrowser.Server.Implementations.Channels item.SetImagePath(ImageType.Primary, info.ImageUrl); } + if (item.SourceType != SourceType.Channel) + { + item.SourceType = SourceType.Channel; + forceUpdate = true; + } + if (isNew) { await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 61da810aa..581b03f08 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1534,9 +1534,13 @@ namespace MediaBrowser.Server.Implementations.Dto 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; + } } } diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index a375dde31..b612e0e37 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -80,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Library list.Add(folder); continue; } - + if (collectionFolder != null && UserView.IsEligibleForGrouping(folder) && user.IsFolderGrouped(folder.Id)) { groupedFolders.Add(collectionFolder); @@ -272,7 +272,11 @@ namespace MediaBrowser.Server.Implementations.Library .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) { @@ -282,7 +286,8 @@ namespace MediaBrowser.Server.Implementations.Library IsFolder = includeItemTypes.Length == 0 ? false : (bool?)null, ExcludeItemTypes = excludeItemTypes, ExcludeLocationTypes = new[] { LocationType.Virtual }, - Limit = limit * 20 + Limit = limit * 20, + SourceTypes = new[] { SourceType.Library } }, parentIds); } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 56daff78a..51ac1351e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -223,6 +223,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "UnratedType", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "TopParentId", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "IsItemByName", "BIT"); + _connection.AddColumn(Logger, "TypedBaseItems", "SourceType", "Text"); PrepareStatements(); @@ -353,7 +354,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "DateLastSaved", "LockedFields", "Studios", - "Tags" + "Tags", + "SourceType" }; private readonly string[] _mediaStreamSaveColumns = @@ -453,7 +455,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsFolder", "UnratedType", "TopParentId", - "IsItemByName" + "IsItemByName", + "SourceType" }; _saveItemCommand = _connection.CreateCommand(); _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 = item.SourceType.ToString(); + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1109,6 +1114,11 @@ namespace MediaBrowser.Server.Implementations.Persistence 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; } @@ -1871,6 +1881,17 @@ namespace MediaBrowser.Server.Implementations.Persistence 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.Value) @@ -2152,8 +2173,6 @@ namespace MediaBrowser.Server.Implementations.Persistence 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["Program"] = new[] { typeof(LiveTvProgram).FullName }; dict["TvChannel"] = new[] { typeof(LiveTvChannel).FullName };