diff options
32 files changed, 289 insertions, 320 deletions
diff --git a/MediaBrowser.Controller/Channels/Channel.cs b/MediaBrowser.Controller/Channels/Channel.cs index 839b7d68f..43f7b6637 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<QueryResult<BaseItem>> GetItems(InternalItemsQuery query) { try @@ -75,5 +83,12 @@ namespace MediaBrowser.Controller.Channels { return false; } + + internal static bool IsChannelVisible(BaseItem channelItem, User user) + { + var channel = ChannelManager.GetChannel(channelItem.ChannelId); + + return channel.IsVisible(user); + } } } diff --git a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs b/MediaBrowser.Controller/Channels/ChannelAudioItem.cs deleted file mode 100644 index 17dcf138b..000000000 --- a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs +++ /dev/null @@ -1,102 +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 MediaBrowser.Model.Users; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Threading; - -namespace MediaBrowser.Controller.Channels -{ - public class ChannelAudioItem : Audio, IChannelMediaItem - { - 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); - } - } -} diff --git a/MediaBrowser.Controller/Channels/ChannelFolderItem.cs b/MediaBrowser.Controller/Channels/ChannelFolderItem.cs deleted file mode 100644 index f662020bb..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, IChannelItem - { - 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); - } - } -} diff --git a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs index 79ad4b36b..c42363dcf 100644 --- a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs @@ -13,7 +13,7 @@ using System.Threading; namespace MediaBrowser.Controller.Channels { - public class ChannelVideoItem : Video, IChannelMediaItem, IHasLookupInfo<ChannelItemLookupInfo> + public class ChannelVideoItem : Video, IHasLookupInfo<ChannelItemLookupInfo> { public ChannelMediaContentType ContentType { get; set; } @@ -48,6 +48,13 @@ namespace MediaBrowser.Controller.Channels } [IgnoreDataMember] + public override SourceType SourceType + { + get { return SourceType.Channel; } + set { } + } + + [IgnoreDataMember] public override bool SupportsLocalMetadata { get @@ -129,14 +136,7 @@ namespace MediaBrowser.Controller.Channels public override bool IsVisibleStandalone(User user) { - return IsVisibleStandaloneInternal(user, false) && IsChannelVisible(this, user); - } - - internal static bool IsChannelVisible(IChannelItem item, User user) - { - var channel = ChannelManager.GetChannel(item.ChannelId); - - return channel.IsVisible(user); + return IsVisibleStandaloneInternal(user, false) && Channel.IsChannelVisible(this, user); } } } diff --git a/MediaBrowser.Controller/Channels/IChannelItem.cs b/MediaBrowser.Controller/Channels/IChannelItem.cs deleted file mode 100644 index 9b5f0359b..000000000 --- a/MediaBrowser.Controller/Channels/IChannelItem.cs +++ /dev/null @@ -1,11 +0,0 @@ -using MediaBrowser.Controller.Entities; - -namespace MediaBrowser.Controller.Channels -{ - public interface IChannelItem : IHasImages, IHasTags - { - string ChannelId { get; set; } - - string ExternalId { get; set; } - } -} diff --git a/MediaBrowser.Controller/Channels/IChannelManager.cs b/MediaBrowser.Controller/Channels/IChannelManager.cs index fec550df8..e3d2d0440 100644 --- a/MediaBrowser.Controller/Channels/IChannelManager.cs +++ b/MediaBrowser.Controller/Channels/IChannelManager.cs @@ -116,7 +116,7 @@ namespace MediaBrowser.Controller.Channels /// <param name="includeCachedVersions">if set to <c>true</c> [include cached versions].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task{IEnumerable{MediaSourceInfo}}.</returns> - Task<IEnumerable<MediaSourceInfo>> GetStaticMediaSources(IChannelMediaItem item, bool includeCachedVersions, CancellationToken cancellationToken); + Task<IEnumerable<MediaSourceInfo>> GetStaticMediaSources(BaseItem item, bool includeCachedVersions, CancellationToken cancellationToken); /// <summary> /// Gets the channel folder. @@ -141,6 +141,6 @@ namespace MediaBrowser.Controller.Channels /// <param name="progress">The progress.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> - Task DownloadChannelItem(IChannelMediaItem item, string destinationPath, IProgress<double> progress, CancellationToken cancellationToken); + Task DownloadChannelItem(BaseItem item, string destinationPath, IProgress<double> progress, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/Channels/IChannelMediaItem.cs b/MediaBrowser.Controller/Channels/IChannelMediaItem.cs deleted file mode 100644 index 60a29da90..000000000 --- a/MediaBrowser.Controller/Channels/IChannelMediaItem.cs +++ /dev/null @@ -1,18 +0,0 @@ -using MediaBrowser.Model.Channels; -using MediaBrowser.Model.Entities; -using System.Collections.Generic; - -namespace MediaBrowser.Controller.Channels -{ - public interface IChannelMediaItem : IChannelItem - { - long? RunTimeTicks { get; set; } - string MediaType { get; } - - ChannelMediaContentType ContentType { get; set; } - - ExtraType? ExtraType { get; set; } - - List<ChannelMediaInfo> ChannelMediaSources { get; set; } - } -}
\ No newline at end of file diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index dc37dccea..4c66a6562 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -8,6 +8,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using System.Threading; +using MediaBrowser.Controller.Channels; namespace MediaBrowser.Controller.Entities.Audio { @@ -24,6 +26,8 @@ namespace MediaBrowser.Controller.Entities.Audio IThemeMedia, IArchivable { + public List<ChannelMediaInfo> ChannelMediaSources { get; set; } + public long? Size { get; set; } public string Container { get; set; } public int? TotalBitrate { get; set; } @@ -198,7 +202,11 @@ namespace MediaBrowser.Controller.Entities.Audio public override UnratedItem GetBlockUnratedType() { - return UnratedItem.Music; + if (SourceType == SourceType.Library) + { + return UnratedItem.Music; + } + return base.GetBlockUnratedType(); } public SongInfo GetLookupInfo() @@ -214,6 +222,32 @@ namespace MediaBrowser.Controller.Entities.Audio public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution) { + if (SourceType == SourceType.Channel) + { + var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None) + .Result.ToList(); + + if (sources.Count > 0) + { + return sources; + } + + var list = new List<MediaSourceInfo> + { + GetVersionInfo(this, enablePathSubstitution) + }; + + foreach (var mediaSource in list) + { + if (string.IsNullOrWhiteSpace(mediaSource.Path)) + { + mediaSource.Type = MediaSourceType.Placeholder; + } + } + + return list; + } + var result = new List<MediaSourceInfo> { GetVersionInfo(this, enablePathSubstitution) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 4106c7197..366aceb83 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -169,6 +169,9 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public bool IsOffline { get; set; } + [IgnoreDataMember] + public virtual SourceType SourceType { get; set; } + /// <summary> /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself @@ -255,6 +258,11 @@ namespace MediaBrowser.Controller.Entities { get { + if (SourceType == SourceType.Channel) + { + return false; + } + var locationType = LocationType; return locationType != LocationType.Remote && locationType != LocationType.Virtual; @@ -301,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; @@ -460,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"); @@ -1032,6 +1050,13 @@ namespace MediaBrowser.Controller.Entities protected virtual string CreateUserDataKey() { + if (SourceType == SourceType.Channel) + { + if (!string.IsNullOrWhiteSpace(ExternalId)) + { + return ExternalId; + } + } return Id.ToString(); } @@ -1110,6 +1135,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool IsSaveLocalMetadataEnabled() { + if (SourceType == SourceType.Channel) + { + return false; + } + return ConfigurationManager.Configuration.SaveLocalMeta; } @@ -1225,6 +1255,11 @@ namespace MediaBrowser.Controller.Entities public virtual UnratedItem GetBlockUnratedType() { + if (SourceType == SourceType.Channel) + { + return UnratedItem.ChannelContent; + } + return UnratedItem.Other; } @@ -1268,6 +1303,11 @@ namespace MediaBrowser.Controller.Entities public virtual bool IsVisibleStandalone(User user) { + if (SourceType == SourceType.Channel) + { + return IsVisibleStandaloneInternal(user, false) && Channel.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<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; 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); - return Task.FromResult(result); + return result; } protected QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> 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/Entities/SourceType.cs b/MediaBrowser.Controller/Entities/SourceType.cs new file mode 100644 index 000000000..9c307b4e6 --- /dev/null +++ b/MediaBrowser.Controller/Entities/SourceType.cs @@ -0,0 +1,10 @@ + +namespace MediaBrowser.Controller.Entities +{ + public enum SourceType + { + Library = 0, + Channel = 1, + LiveTV = 2 + } +} 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 { } + } + /// <summary> /// Gets the user data key. /// </summary> 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 { } + } + /// <summary> /// Gets or sets the number. /// </summary> 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 { } + } + /// <summary> /// The start date of the program, in UTC. /// </summary> 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 { } + } + /// <summary> /// Gets the user data key. /// </summary> 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 f74d82caa..7cc66ef73 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -75,7 +75,6 @@ </Compile> <Compile Include="Activity\IActivityManager.cs" /> <Compile Include="Activity\IActivityRepository.cs" /> - <Compile Include="Channels\ChannelFolderItem.cs" /> <Compile Include="Channels\ChannelItemInfo.cs" /> <Compile Include="Channels\ChannelItemResult.cs" /> <Compile Include="Channels\ChannelItemType.cs" /> @@ -84,11 +83,8 @@ <Compile Include="Channels\ChannelSearchInfo.cs" /> <Compile Include="Channels\IChannel.cs" /> <Compile Include="Channels\IChannelManager.cs" /> - <Compile Include="Channels\IChannelItem.cs" /> - <Compile Include="Channels\ChannelAudioItem.cs" /> <Compile Include="Channels\ChannelVideoItem.cs" /> <Compile Include="Channels\Channel.cs" /> - <Compile Include="Channels\IChannelMediaItem.cs" /> <Compile Include="Channels\IHasCacheKey.cs" /> <Compile Include="Channels\IIndexableChannel.cs" /> <Compile Include="Channels\InternalAllChannelMediaQuery.cs" /> @@ -180,6 +176,7 @@ <Compile Include="Entities\Photo.cs" /> <Compile Include="Entities\PhotoAlbum.cs" /> <Compile Include="Entities\Share.cs" /> + <Compile Include="Entities\SourceType.cs" /> <Compile Include="Entities\UserView.cs" /> <Compile Include="Entities\UserViewBuilder.cs" /> <Compile Include="FileOrganization\IFileOrganizationService.cs" /> diff --git a/MediaBrowser.Providers/Channels/AudioChannelItemMetadataService.cs b/MediaBrowser.Providers/Channels/AudioChannelItemMetadataService.cs deleted file mode 100644 index 9a1a993d9..000000000 --- a/MediaBrowser.Providers/Channels/AudioChannelItemMetadataService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; -using CommonIO; -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Channels; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Logging; -using MediaBrowser.Providers.Manager; - -namespace MediaBrowser.Providers.Channels -{ - public class AudioChannelItemMetadataService : MetadataService<ChannelAudioItem, ItemLookupInfo> - { - public AudioChannelItemMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem, userDataManager, libraryManager) - { - } - - protected override void MergeData(MetadataResult<ChannelAudioItem> source, MetadataResult<ChannelAudioItem> target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings) - { - ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings); - } - } -} diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index eca254848..f9d4d7bd4 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -90,7 +90,6 @@ <Compile Include="Chapters\ChapterManager.cs" /> <Compile Include="Folders\DefaultImageProvider.cs" /> <Compile Include="Folders\FolderMetadataService.cs" /> - <Compile Include="Channels\AudioChannelItemMetadataService.cs" /> <Compile Include="Folders\UserViewMetadataService.cs" /> <Compile Include="GameGenres\GameGenreMetadataService.cs" /> <Compile Include="Channels\VideoChannelItemMetadataService.cs" /> diff --git a/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs b/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs index e86ae4b04..c29df6191 100644 --- a/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs @@ -42,7 +42,7 @@ namespace MediaBrowser.Providers.Movies public bool Supports(IHasImages item) { - var channelItem = item as IChannelMediaItem; + var channelItem = item as ChannelVideoItem; if (channelItem != null) { diff --git a/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs b/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs index eaebd426f..d63a1594e 100644 --- a/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs @@ -81,7 +81,7 @@ namespace MediaBrowser.Providers.Omdb return false; } - var channelItem = item as IChannelMediaItem; + var channelItem = item as ChannelVideoItem; if (channelItem != null) { diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelDynamicMediaSourceProvider.cs b/MediaBrowser.Server.Implementations/Channels/ChannelDynamicMediaSourceProvider.cs index dac3a80f2..3239b20b2 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelDynamicMediaSourceProvider.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelDynamicMediaSourceProvider.cs @@ -20,11 +20,11 @@ namespace MediaBrowser.Server.Implementations.Channels public Task<IEnumerable<MediaSourceInfo>> GetMediaSources(IHasMediaSources item, CancellationToken cancellationToken) { - var channelItem = item as IChannelMediaItem; + var baseItem = (BaseItem) item; - if (channelItem != null) + if (baseItem.SourceType == SourceType.Channel) { - return _channelManager.GetDynamicMediaSources(channelItem, cancellationToken); + return _channelManager.GetDynamicMediaSources(baseItem, cancellationToken); } return Task.FromResult<IEnumerable<MediaSourceInfo>>(new List<MediaSourceInfo>()); diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index c7865b6aa..775f7224c 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 { @@ -248,9 +249,19 @@ namespace MediaBrowser.Server.Implementations.Channels return item; } - public async Task<IEnumerable<MediaSourceInfo>> GetStaticMediaSources(IChannelMediaItem item, bool includeCachedVersions, CancellationToken cancellationToken) + public async Task<IEnumerable<MediaSourceInfo>> GetStaticMediaSources(BaseItem item, bool includeCachedVersions, CancellationToken cancellationToken) { - IEnumerable<ChannelMediaInfo> results = item.ChannelMediaSources; + IEnumerable<ChannelMediaInfo> results = new List<ChannelMediaInfo>(); + var video = item as ChannelVideoItem; + if (video != null) + { + results = video.ChannelMediaSources; + } + var audio = item as Audio; + if (audio != null) + { + results = audio.ChannelMediaSources ?? new List<ChannelMediaInfo>(); + } var sources = SortMediaInfoResults(results) .Select(i => GetMediaSource(item, i)) @@ -265,7 +276,7 @@ namespace MediaBrowser.Server.Implementations.Channels return sources; } - public async Task<IEnumerable<MediaSourceInfo>> GetDynamicMediaSources(IChannelMediaItem item, CancellationToken cancellationToken) + public async Task<IEnumerable<MediaSourceInfo>> GetDynamicMediaSources(BaseItem item, CancellationToken cancellationToken) { var channel = GetChannel(item.ChannelId); var channelPlugin = GetChannelProvider(channel); @@ -319,7 +330,7 @@ namespace MediaBrowser.Server.Implementations.Channels return list; } - private IEnumerable<MediaSourceInfo> GetCachedChannelItemMediaSources(IChannelMediaItem item) + private IEnumerable<MediaSourceInfo> GetCachedChannelItemMediaSources(BaseItem item) { var filenamePrefix = item.Id.ToString("N"); var parentPath = Path.Combine(ChannelDownloadPath, item.ChannelId); @@ -368,7 +379,7 @@ namespace MediaBrowser.Server.Implementations.Channels return new List<MediaSourceInfo>(); } - private MediaSourceInfo GetMediaSource(IChannelMediaItem item, ChannelMediaInfo info) + private MediaSourceInfo GetMediaSource(BaseItem item, ChannelMediaInfo info) { var source = info.ToMediaSource(); @@ -1079,7 +1090,7 @@ namespace MediaBrowser.Server.Implementations.Channels if (!string.IsNullOrWhiteSpace(folderId)) { - var categoryItem = (IChannelItem)_libraryManager.GetItemById(new Guid(folderId)); + var categoryItem = _libraryManager.GetItemById(new Guid(folderId)); query.FolderId = categoryItem.ExternalId; } @@ -1195,7 +1206,7 @@ namespace MediaBrowser.Server.Implementations.Channels } private T GetItemById<T>(string idString, string channelName, string channnelDataVersion, out bool isNew) - where T : BaseItem, IChannelItem, new() + where T : BaseItem, new() { var id = GetIdToHash(idString, channelName).GetMBId(typeof(T)); @@ -1233,11 +1244,22 @@ namespace MediaBrowser.Server.Implementations.Channels 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) { - item = GetItemById<ChannelAudioItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + item = GetItemById<Audio>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); } else { @@ -1263,9 +1285,7 @@ namespace MediaBrowser.Server.Implementations.Channels item.Tags = info.Tags; } - var channelItem = (IChannelItem)item; - - channelItem.ChannelId = internalChannelId.ToString("N"); + item.ChannelId = internalChannelId.ToString("N"); if (item.ParentId != internalChannelId) { @@ -1273,22 +1293,30 @@ namespace MediaBrowser.Server.Implementations.Channels } item.ParentId = internalChannelId; - if (!string.Equals(channelItem.ExternalId, info.Id, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(item.ExternalId, info.Id, StringComparison.OrdinalIgnoreCase)) { forceUpdate = true; } - channelItem.ExternalId = info.Id; - - var channelMediaItem = item as IChannelMediaItem; + item.ExternalId = info.Id; - if (channelMediaItem != null) + var channelAudioItem = item as Audio; + if (channelAudioItem != null) { - channelMediaItem.ContentType = info.ContentType; - channelMediaItem.ExtraType = info.ExtraType; - channelMediaItem.ChannelMediaSources = info.MediaSources; + channelAudioItem.ExtraType = info.ExtraType; + channelAudioItem.ChannelMediaSources = info.MediaSources; var mediaSource = info.MediaSources.FirstOrDefault(); + item.Path = mediaSource == null ? null : mediaSource.Path; + } + + var channelVideoItem = item as ChannelVideoItem; + if (channelVideoItem != null) + { + channelVideoItem.ContentType = info.ContentType; + channelVideoItem.ExtraType = info.ExtraType; + channelVideoItem.ChannelMediaSources = info.MediaSources; + var mediaSource = info.MediaSources.FirstOrDefault(); item.Path = mediaSource == null ? null : mediaSource.Path; } @@ -1297,6 +1325,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); @@ -1441,7 +1475,7 @@ namespace MediaBrowser.Server.Implementations.Channels return await _libraryManager.GetNamedView(name, "channels", "zz_" + name, cancellationToken).ConfigureAwait(false); } - public async Task DownloadChannelItem(IChannelMediaItem item, string destination, + public async Task DownloadChannelItem(BaseItem item, string destination, IProgress<double> progress, CancellationToken cancellationToken) { var sources = await GetDynamicMediaSources(item, cancellationToken) @@ -1457,7 +1491,7 @@ namespace MediaBrowser.Server.Implementations.Channels } private async Task TryDownloadChannelItem(MediaSourceInfo source, - IChannelMediaItem item, + BaseItem item, string destination, IProgress<double> progress, CancellationToken cancellationToken) diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index fb202b798..581b03f08 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -480,7 +480,7 @@ namespace MediaBrowser.Server.Implementations.Dto var folder = (Folder)item; - if (!(folder is IChannelItem) && !(folder is Channel)) + if (item.SourceType == SourceType.Library) { dto.ChildCount = GetChildCount(folder, user); @@ -1250,6 +1250,7 @@ namespace MediaBrowser.Server.Implementations.Dto if (audio != null) { dto.Album = audio.Album; + dto.ExtraType = audio.ExtraType; var albumParent = audio.AlbumEntity; @@ -1352,6 +1353,8 @@ namespace MediaBrowser.Server.Implementations.Dto { dto.Chapters = GetChapterInfoDtos(item); } + + dto.ExtraType = video.ExtraType; } if (fields.Contains(ItemFields.MediaStreams)) @@ -1531,16 +1534,13 @@ namespace MediaBrowser.Server.Implementations.Dto dto.ChannelId = item.ChannelId; - var channelItem = item as IChannelItem; - if (channelItem != null) - { - dto.ChannelName = _channelManagerFactory().GetChannel(channelItem.ChannelId).Name; - } - - var channelMediaItem = item as IChannelMediaItem; - if (channelMediaItem != null) + if (item.SourceType == SourceType.Channel && !string.IsNullOrWhiteSpace(item.ChannelId)) { - dto.ExtraType = channelMediaItem.ExtraType; + var channel = _libraryManager.GetItemById(item.ChannelId); + if (channel != null) + { + dto.ChannelName = channel.Name; + } } } diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs index 28883e9a2..dfaedbc9d 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs @@ -342,7 +342,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints void _libraryManager_ItemRemoved(object sender, ItemChangeEventArgs e) { - if (e.Item is LiveTvProgram || e.Item is IChannelItem) + if (e.Item.SourceType != SourceType.Library) { return; } @@ -356,7 +356,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e) { - if (e.Item is LiveTvProgram || e.Item is IChannelItem) + if (e.Item.SourceType != SourceType.Library) { return; } diff --git a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 703096a2b..237c7157b 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -282,7 +282,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints return false; } - return !(item is IChannelItem) && !(item is ILiveTvItem); + return item.SourceType == SourceType.Library; } /// <summary> diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs index a9e4aaa0b..da1d25f2c 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs @@ -346,7 +346,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications return false; } - return !(item is IChannelItem) && !(item is ILiveTvItem); + return item.SourceType == SourceType.Library; } private async void LibraryUpdateTimerCallback(object state) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 3c56af9e6..184737ece 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -347,11 +347,7 @@ namespace MediaBrowser.Server.Implementations.Library private void RegisterItem(Guid id, BaseItem item) { - if (item is LiveTvProgram) - { - return; - } - if (item is IChannelItem) + if (item.SourceType != SourceType.Library) { return; } 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 }; diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 8ebc8d91e..e22f86b11 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -536,7 +536,7 @@ namespace MediaBrowser.Server.Implementations.Sync } } - if (item is LiveTvChannel || item is IChannelItem) + if (item.SourceType != SourceType.Library) { return false; } |
